1 
2 #ifndef OPENAV_AVTK_TEST_UI_HXX
3 #define OPENAV_AVTK_TEST_UI_HXX
4 
5 #include "avtk.hxx"
6 #include "step.hxx"
7 #include "../shared.hxx"
8 
9 #define OSCPKT_OSTREAM_OUTPUT
10 #include "oscpkt/oscpkt.hh"
11 #include "oscpkt/udp.hh"
12 using namespace oscpkt;
13 
14 // for write_function and controller
15 #include "lv2/lv2plug.in/ns/extensions/ui/ui.h"
16 
17 
18 namespace Avtk
19 {
20 class Pad;
21 class Step;
22 class Fader;
23 class Widget;
24 class Volume;
25 class MixStrip;
26 };
27 
28 #define UI_ATOM_BUF_SIZE 128*128
29 // Sequencer view controls
30 #define SEQ_ROWS 16
31 #define SEQ_STEPS 32
32 
33 class Fabla2UI : public Avtk::UI
34 {
35 public:
36 	/// Set a NativeWindow for embedding: ignore for standalone
37 	Fabla2UI(PuglNativeWindow parent = 0);
38 
39 	/// init function, called by LV2 UI wrapper after setting map, forge etc
init()40 	void init()
41 	{
42 		setBank( 0 );
43 		currentLayer = 1; // invalidate, so request updates
44 		requestSampleState( 0, 0, 0 );
45 		blankSampleState();
46 	}
47 
48 	void handleMaschine();
49 	void updateMaschine(int pad, int r, int g, int b, int a);
50 
51 
52 	void blankSampleState();
53 
54 	/// widget value callback
55 	void widgetValueCB( Avtk::Widget* widget);
56 	/// step-sequencer step button callback
57 	void seqStepValueCB( Avtk::Widget* w);
58 
59 	/// handle() fucntion for keybindings
60 	int handle( const PuglEvent* event );
61 
62 	/// A revision so the UI can drop update messages when not needed
63 	int redrawRev;
64 	int redrawRevDone;
65 
66 	// left: always visible widgets
67 	Avtk::Widget* bankBtns[4];
68 
69 	Avtk::Button* panicButton;
70 
71 	Avtk::List*  uiViewGroup;
72 	Avtk::ListItem* liveView;
73 	Avtk::ListItem* padsView;
74 	Avtk::ListItem* fileView;
75 	Avtk::ListItem* seqView;
76 
77 	Avtk::Widget* followPadBtn;
78 	Avtk::Widget* recordOverPad;
79 
80 	Avtk::Dial* masterPitch; // not shown
81 
82 	// Right
83 	Avtk::Volume*  masterDB;
84 	Avtk::Fader*  masterVolume;
85 	Avtk::Fader*  masterAuxFader1;
86 	Avtk::Fader*  masterAuxFader2;
87 	Avtk::Fader*  masterAuxFader3;
88 	Avtk::Fader*  masterAuxFader4;
89 
90 	// sample info
91 	Avtk::Text* sampleName;
92 
93 	// delete layer dialog
94 	Avtk::Dialog* deleteLayer;
95 
96 	// sample edit view
97 	Avtk::Number* muteGroup;
98 	Avtk::Number* offGroup;
99 	Avtk::Number* triggerMode;
100 	Avtk::Number* switchType;
101 	Avtk::List* layers;
102 	Avtk::Widget* adsr;
103 
104 	Avtk::Widget* filt1;
105 	Avtk::Number* filterType;
106 	Avtk::Widget* filterFrequency;
107 	Avtk::Widget* filterResonance;
108 
109 	Avtk::Widget* filt2;
110 	Avtk::Widget* bitcrusDist;
111 	Avtk::Widget* eq;
112 	Avtk::Widget* comp;
113 	Avtk::Widget* gainPitch;
114 	Avtk::Dial* sampleGain;
115 	Avtk::Dial* samplePan;
116 	Avtk::Dial* samplePitch;
117 	Avtk::Dial* sampleTime;
118 	Avtk::Dial* sampleStartPoint;
119 	Avtk::Dial* sampleEndPoint;
120 
121 	Avtk::Dial* velocityStartPoint;
122 	Avtk::Dial* velocityEndPoint;
123 
124 	Avtk::Dial* send1;
125 	Avtk::Dial* send2;
126 	Avtk::Dial* send3;
127 	Avtk::Dial* send4;
128 
129 	Avtk::Dial* adsrA;
130 	Avtk::Dial* adsrD;
131 	Avtk::Dial* adsrS;
132 	Avtk::Dial* adsrR;
133 
134 	Avtk::Button* padPlay;
135 	Avtk::Button* padMute;
136 	Avtk::Fader* padVolume;
137 
138 	Avtk::Widget* padSends;
139 	Avtk::Widget* padMaster;
140 
141 	// Sample / File loading screen
142 	Avtk::Box*    sampleViewHeader;
143 	Avtk::Scroll* sampleDirScroll;
144 	Avtk::List*   listSampleDirs;
145 	Avtk::Scroll* sampleFileScroll;
146 	Avtk::List*   listSampleFiles;
147 	Avtk::Button* fileViewHome;
148 	Avtk::Button* fileViewUp;
149 
150 	// Live view
151 	Avtk::Group* liveGroup;
152 	Avtk::Widget* padsHeaderBox;
153 
154 	// Sequencer view
155 	Avtk::Group*  seqGroup;
156 	Avtk::Step*   seqSteps[SEQ_ROWS*SEQ_STEPS];
157 	Avtk::Dial*   transport_bpm;
158 	Avtk::Button* transport_play;
159 
160 	// pad - tracks
161 	Avtk::MixStrip* mixStrip [16];
162 	Avtk::Fader*    padFaders[16];
163 	Avtk::Dial*     auxDials [16*4];
164 
165 	// AuxBus tracks
166 	Avtk::MixStrip* auxbus[4];
167 	Avtk::Fader*    auxFaders[4];
168 
169 
170 	// shared between views!
171 	/// holds all waveform related widgets: sample name, sample duration etc
172 	Avtk::Group*    waveformGroup;
173 	Avtk::Waveform* waveform;
174 
175 	Avtk::Group*    sampleBrowseGroup;
176 	Avtk::Group*    sampleControlGroup;
177 
178 	void padEvent( int bank, int pad, int layer, bool noteOn, int velocity );
179 
180 	Avtk::Group* padsGroup;
181 	Avtk::Pad* pads[16];
182 
183 	// bank/pad/layer currently shown in UI
184 	int currentBank;
185 	int currentPad;
186 	int currentLayer;
187 
188 	// LV2 ports
189 	LV2UI_Controller controller;
190 	LV2UI_Write_Function write_function;
191 
192 	// LV2 Atom
193 	URIs uris;
194 	LV2_URID_Map* map;
195 	LV2_Atom_Forge forge;
196 
197 private:
198 	// OSC interface for Maschine interfaces
199 	UdpSocket sock;
200 	std::string maschine_addr;
201 
202 	/// default directories / file loading
203 	std::string defaultDir;
204 	std::string currentDir;
205 	std::string currentFilesDir;
206 
207 	/// holds the stripped start of the filename, as presented in List. To build
208 	/// the loadable /path/filename, we do << currentDir << strippedFilenameStart;
209 	std::string strippedFilenameStart;
210 
211 	/// followPad allows the UI to update to the last played PAD.
212 	bool followPad;
213 
214 	/// shows the sample browser window instead of the pads
215 	void showPadsView();
216 	void showLiveView();
217 	void showFileView();
218 	void showSeqView();
219 
220 	/// updates the UI to a specifc bank
221 	void setBank( int bank );
222 	/// write a value to an AuxBus
223 	void writeAuxBus( int uri, int bus, float value );
224 	/// writes event/value identified by eventURI using currentBank / currentPad
225 	void writeAtom( int eventURI, float value );
226 	/// writes "live view" atoms for a specific pad
227 	void writeAtomForPad( int eventURI, int pad, float value );
228 	/// writes a pad play/stop event
229 	void writePadPlayStop( bool noteOn, int bank, int pad, int layer );
230 	/// request the state of a sample from the DSP, to show in the UI
231 	void requestSampleState( int bank, int pad, int layer );
232 	/// list sample dirs
233 	void loadNewDir( std::string newDir );
234 };
235 
236 
237 #endif // OPENAV_AVTK_TEST_UI_HXX
238