Overte C++ Documentation
Deck.h
1 //
2 // Created by Bradley Austin Davis 2015/11/04
3 // Copyright 2015 High Fidelity, Inc.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 //
8 
9 #pragma once
10 #ifndef hifi_Recording_Deck_h
11 #define hifi_Recording_Deck_h
12 
13 #include <utility>
14 #include <list>
15 #include <mutex>
16 
17 #include <QtCore/QObject>
18 #include <QtCore/QTimer>
19 #include <QtCore/QList>
20 
21 #include <DependencyManager.h>
22 
23 #include "Forward.h"
24 #include "Frame.h"
25 
26 
27 namespace recording {
28 
29 class Deck : public QObject, public ::Dependency {
30  Q_OBJECT
31 public:
32  using ClipList = std::list<ClipPointer>;
33  using Pointer = std::shared_ptr<Deck>;
34 
35  Deck(QObject* parent = nullptr);
36 
37  // Place a clip on the deck for recording or playback
38  void queueClip(ClipPointer clip, float timeOffset = 0.0f);
39  void removeClip(const ClipConstPointer& clip);
40  void removeClip(const QString& clipName);
41  void removeAllClips();
42  ClipList getClips(const QString& clipName) const;
43 
44  void play();
45  bool isPlaying();
46 
47  void pause();
48  bool isPaused() const;
49 
50  void stop();
51 
52  float length() const;
53 
54  void loop(bool enable = true);
55  bool isLooping() const;
56 
57  float position() const;
58  void seek(float position);
59 
60  float getVolume() const { return _volume; }
61  void setVolume(float volume);
62 
63 signals:
64  void playbackStateChanged();
65  void looped();
66 
67 private:
68  using Mutex = std::recursive_mutex;
69  using Locker = std::unique_lock<Mutex>;
70 
71  ClipPointer getNextClip();
72  void processFrames();
73 
74  mutable Mutex _mutex;
75  QTimer _timer;
76  ClipList _clips;
77  quint64 _startEpoch { 0 };
78  Frame::Time _position { 0 };
79  bool _pause { true };
80  bool _loop { false };
81  float _length { 0 };
82  float _volume { 1.0f };
83 };
84 
85 }
86 
87 #endif