f@0
|
1 #pragma once
|
f@0
|
2
|
f@0
|
3 #include "cinder/Cinder.h"
|
f@0
|
4 #include "cinder/audio/Node.h"
|
f@0
|
5 #include "cinder/audio/dsp/RingBuffer.h"
|
f@0
|
6 #include "boost/optional.hpp"
|
f@0
|
7 #include "Messages.h"
|
f@0
|
8 #include "RingBufferPack.h"
|
f@0
|
9
|
f@0
|
10 #include <memory>
|
f@0
|
11
|
f@0
|
12 #include "PGranular.h"
|
f@0
|
13 #include "EnvASR.h"
|
f@0
|
14
|
f@0
|
15 typedef std::shared_ptr<class PGranularNode> PGranularNodeRef;
|
f@0
|
16 typedef ci::audio::dsp::RingBufferT<CursorTriggerMsg> CursorTriggerMsgRingBuffer;
|
f@0
|
17
|
f@0
|
18
|
f@0
|
19 struct RandomGenerator;
|
f@0
|
20
|
f@0
|
21 /*
|
f@0
|
22 A node in the Cinder audio graph that holds a PGranular
|
f@0
|
23 */
|
f@0
|
24 class PGranularNode : public ci::audio::Node
|
f@0
|
25 {
|
f@0
|
26 public:
|
f@0
|
27 static const size_t kMaxVoices = 6;
|
f@0
|
28 static const int kNoMidiNote = -50;
|
f@0
|
29
|
f@0
|
30 explicit PGranularNode( ci::audio::Buffer *grainBuffer, CursorTriggerMsgRingBuffer &triggerRingBuffer );
|
f@0
|
31 ~PGranularNode();
|
f@0
|
32
|
f@0
|
33 // set selection size in samples
|
f@0
|
34 void setSelectionSize( size_t size )
|
f@0
|
35 {
|
f@0
|
36 mSelectionSize.set( size );
|
f@0
|
37 }
|
f@0
|
38
|
f@0
|
39 void setSelectionStart( size_t start )
|
f@0
|
40 {
|
f@0
|
41 mSelectionStart.set( start );
|
f@0
|
42 }
|
f@0
|
43
|
f@0
|
44 void setGrainsDurationCoeff( double coeff )
|
f@0
|
45 {
|
f@0
|
46 mGrainDurationCoeff.set( coeff );
|
f@0
|
47 }
|
f@0
|
48
|
f@0
|
49 // used for trigger callback in PGRanular
|
f@0
|
50 void operator()( char msgType, int ID );
|
f@0
|
51
|
f@0
|
52 ci::audio::dsp::RingBufferT<NoteMsg>& getNoteRingBuffer() { return mNoteMsgRingBufferPack.getBuffer(); }
|
f@0
|
53
|
f@0
|
54 protected:
|
f@0
|
55
|
f@0
|
56 void initialize() override;
|
f@0
|
57
|
f@0
|
58 void process( ci::audio::Buffer *buffer ) override;
|
f@0
|
59
|
f@0
|
60 private:
|
f@0
|
61
|
f@0
|
62 template< typename T>
|
f@0
|
63 class LazyAtomic
|
f@0
|
64 {
|
f@0
|
65 public:
|
f@0
|
66 LazyAtomic( T val ) :
|
f@0
|
67 mAtomic( val ),
|
f@0
|
68 mPreviousVal( val )
|
f@0
|
69 {}
|
f@0
|
70
|
f@0
|
71 void set( T val )
|
f@0
|
72 {
|
f@0
|
73 mAtomic = val;
|
f@0
|
74 }
|
f@0
|
75
|
f@0
|
76 boost::optional<T> get()
|
f@0
|
77 {
|
f@0
|
78 const T val = mAtomic;
|
f@0
|
79 if ( val != mPreviousVal ){
|
f@0
|
80 mPreviousVal = val;
|
f@0
|
81 return val;
|
f@0
|
82 }
|
f@0
|
83 else{
|
f@0
|
84 return boost::none;
|
f@0
|
85 }
|
f@0
|
86 }
|
f@0
|
87
|
f@0
|
88 private:
|
f@0
|
89 std::atomic<T> mAtomic;
|
f@0
|
90 T mPreviousVal;
|
f@0
|
91 };
|
f@0
|
92
|
f@0
|
93 void handleNoteMsg( const NoteMsg &msg );
|
f@0
|
94
|
f@0
|
95 // pointer to PGranular object
|
f@0
|
96 std::unique_ptr < collidoscope::PGranular<float, RandomGenerator, PGranularNode > > mPGranularLoop;
|
f@0
|
97 std::array<std::unique_ptr < collidoscope::PGranular<float, RandomGenerator, PGranularNode > >, kMaxVoices> mPGranularNotes;
|
f@0
|
98 std::array<int, kMaxVoices> mMidiNotes;
|
f@0
|
99
|
f@0
|
100 // pointer to the random generator struct passed over to PGranular
|
f@0
|
101 std::unique_ptr< RandomGenerator > mRandomOffset;
|
f@0
|
102
|
f@0
|
103 /* buffer containing the recorder audio, to pass to PGranular in initialize() */
|
f@0
|
104 ci::audio::Buffer *mGrainBuffer;
|
f@0
|
105
|
f@0
|
106 ci::audio::BufferRef mTempBuffer;
|
f@0
|
107
|
f@0
|
108 CursorTriggerMsgRingBuffer &mTriggerRingBuffer;
|
f@0
|
109 RingBufferPack<NoteMsg> mNoteMsgRingBufferPack;
|
f@0
|
110
|
f@0
|
111 LazyAtomic<size_t> mSelectionSize;
|
f@0
|
112
|
f@0
|
113 LazyAtomic<size_t> mSelectionStart;
|
f@0
|
114
|
f@0
|
115 LazyAtomic<double> mGrainDurationCoeff;
|
f@0
|
116
|
f@0
|
117
|
f@0
|
118 };
|
f@0
|
119
|