1 /*  SpiralLoops
2  *  Copyleft (C) 2000 David Griffiths <dave@pawfal.org>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 #include <iostream>
19 #include "../SpiralLoopsInfo.h"
20 
21 #include "Widgets/Fl_Loop.h"
22 #include "LoopGUI.h"
23 #include "../Loop.h"
24 #include <FL/Fl_File_Chooser.H>
25 
26 static const int EFFECT_ADDITION = 130;
27 
28 /////////////////////////////////////////////////////////////////////////////
29 
LoopGUI(Loop * o,Delay * pDelay,Reverb * pReverb)30 LoopGUI::LoopGUI(Loop *o, Delay *pDelay, Reverb* pReverb) :
31 GUILoopGroup(NULL)
32 {
33 	m_loop=o;
34 	m_LastAngle=0;
35 	m_DelayPtr=pDelay;
36 	m_ReverbPtr=pReverb;
37 
38 	if (!m_loop || !m_DelayPtr || !m_ReverbPtr)
39 		cerr<<"WARNING: Loop not correctly set up"<<endl;
40 }
41 
~LoopGUI()42 LoopGUI::~LoopGUI()
43 {
44 	delete GUILoopGroup;
45 }
46 
CreateGUI(char * name)47 void LoopGUI::CreateGUI(char *name)
48 {
49 	{
50 	  GUILoopGroup = new Fl_Loop(0,0,300, 300, name);
51       GUILoopGroup->box(FL_NO_BOX);
52 	  GUILoopGroup->color(SpiralLoopsInfo::GUIBG2_COLOUR);
53 	  GUILoopGroup->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
54 	  GUILoopGroup->user_data((void*)(this));
55 	  GUILoopGroup->SetData(m_loop->GetLoopPtr());
56 	  GUILoopGroup->SetLength(m_loop->GetLoopLength());
57 	  GUILoopGroup->SetPos(m_loop->GetPosPtr());
58 	  GUILoopGroup->callback((Fl_Callback*)cb_Loop);
59 	  GUILoopGroup->SetupCopyBufFuncs((Fl_Loop::cb_CopyBuf1*)cb_Cut,
60 	                                  (Fl_Loop::cb_CopyBuf1*)cb_Copy,
61 	                                  (Fl_Loop::cb_CopyBuf2*)cb_Paste,
62 									  (Fl_Loop::cb_CopyBuf2*)cb_PasteMix,
63 									  (Fl_Loop::cb_CopyBuf1*)cb_ZeroRange,
64 					    			  (Fl_Loop::cb_CopyBuf1*)cb_ReverseRange,
65 					    			  (Fl_Loop::cb_CopyBuf1*)cb_Halve,
66 					    			  (Fl_Loop::cb_CopyBuf1*)cb_Hold,
67 					    			  (Fl_Loop::cb_CopyBuf1*)cb_SelectAll,
68 									  (Fl_Loop::cb_CopyBuf1*)cb_NewTrigger,
69 									  (Fl_Loop::cb_CopyBuf1*)cb_Move);
70 
71 	  GUILoopGroup->SetMainWin(m_loop->GetParent()->GetPluginWindow());
72 
73 	  Volume = new Fl_Slider(60, 100, 20, 70, "Volume");
74 	  Volume->type(4);
75 	  Volume->color(SpiralLoopsInfo::GUIBG2_COLOUR);
76 	  Volume->selection_color(SpiralLoopsInfo::GUI_COLOUR);
77       Volume->labelsize(10);
78 	  Volume->maximum(1.0f);
79       Volume->step(0.001);
80       Volume->value(0);
81       Volume->callback((Fl_Callback*)cb_Volume);
82 
83 	  Cutoff = new Fl_Slider(220, 100, 20, 70, "Cutoff");
84 	  Cutoff->type(4);
85 	  Cutoff->color(SpiralLoopsInfo::GUIBG2_COLOUR);
86 	  Cutoff->selection_color(SpiralLoopsInfo::GUI_COLOUR);
87       Cutoff->labelsize(10);
88 	  Cutoff->maximum(100);
89       Cutoff->step(0.1);
90       Cutoff->value(0);
91       Cutoff->callback((Fl_Callback*)cb_Cutoff);
92 
93 	  Resonance = new Fl_Knob(160, 140, 45, 45, "Emphasis");
94       Resonance->color(SpiralLoopsInfo::GUI_COLOUR);
95 	  Resonance->type(Fl_Knob::DOTLIN);
96       Resonance->labelsize(10);
97       Resonance->maximum(10);
98       Resonance->step(0.1);
99       Resonance->value(0);
100 	  Resonance->callback((Fl_Callback*)cb_Resonance);
101 
102  	  Balance = new Fl_Knob(95, 140, 45, 45, "Balance");
103       Balance->color(SpiralLoopsInfo::GUI_COLOUR);
104 	  Balance->type(Fl_Knob::DOTLIN);
105       Balance->labelsize(10);
106       Balance->maximum(2);
107       Balance->step(0.001);
108       Balance->value(1.0);
109 	  Balance->callback((Fl_Callback*)cb_Balance);
110 
111  	  Speed = new Fl_Knob(95, 60, 45, 45, "Speed");
112       Speed->color(SpiralLoopsInfo::GUI_COLOUR);
113 	  Speed->type(Fl_Knob::DOTLIN);
114       Speed->labelsize(10);
115       Speed->maximum(3);
116       Speed->step(0.0001);
117       Speed->value(1);
118 	  Speed->callback((Fl_Callback*)cb_Speed);
119 
120 	  Length = new Fl_Knob(160, 60, 45, 45, "Length");
121       Length->color(SpiralLoopsInfo::GUI_COLOUR);
122 	  Length->type(Fl_Knob::DOTLIN);
123       Length->labelsize(10);
124       Length->maximum(1);
125       Length->step(0.0001);
126       Length->value(1);
127 	  Length->callback((Fl_Callback*)cb_Length);
128 
129 	  Record = new Fl_Button(85, 200, 40, 14, "Record");
130       Record->type(1);
131 	  Record->color(SpiralLoopsInfo::GUIBG2_COLOUR);
132       Record->down_box(FL_DOWN_BOX);
133       Record->labelsize(10);
134       Record->callback((Fl_Callback*)cb_Record);
135 
136 	  Load = new Fl_Button(175, 200, 40, 14, "Load");
137 	  Load->color(SpiralLoopsInfo::GUIBG2_COLOUR);
138       Load->type(0);
139       Load->down_box(FL_DOWN_BOX);
140       Load->labelsize(10);
141       Load->callback((Fl_Callback*)cb_Load);
142 
143 	  Effects = new Fl_Button(130, 200, 40, 14, "Effects");
144 	  Effects->color(SpiralLoopsInfo::GUIBG2_COLOUR);
145       Effects->type(1);
146       Effects->down_box(FL_DOWN_BOX);
147       Effects->labelsize(10);
148       Effects->callback((Fl_Callback*)cb_Effects);
149 
150 	  Double = new Fl_Button(85, 218, 40, 14, "Double");
151 	  Double->color(SpiralLoopsInfo::GUIBG2_COLOUR);
152       Double->type(0);
153       Double->down_box(FL_DOWN_BOX);
154       Double->labelsize(10);
155       Double->callback((Fl_Callback*)cb_Double);
156 
157 	  Match = new Fl_Button(130, 218, 40, 14, "Match");
158 	  Match->color(SpiralLoopsInfo::GUIBG2_COLOUR);
159       Match->type(0);
160       Match->down_box(FL_DOWN_BOX);
161       Match->labelsize(10);
162       Match->callback((Fl_Callback*)cb_Match);
163 
164 	  Save = new Fl_Button(175, 218, 40, 14, "Save");
165 	  Save->color(SpiralLoopsInfo::GUIBG2_COLOUR);
166       Save->type(0);
167       Save->down_box(FL_DOWN_BOX);
168       Save->labelsize(10);
169       Save->callback((Fl_Callback*)cb_Save);
170 
171 	  Play = new Fl_LED_Button(255, 275, 40, 25, "Play");
172 	  Play->color(SpiralLoopsInfo::GUIBG2_COLOUR);
173       Play->type(1);
174 	  Play->value(1);
175       Play->down_box(FL_DOWN_BOX);
176       Play->labelsize(10);
177       Play->callback((Fl_Callback*)cb_Play);
178 
179 	  SpeedOutput  = new Fl_Value_Output(93, 120, 50, 15);
180 	  SpeedOutput->labelsize(10);
181 	  SpeedOutput->textsize(10);
182 
183 	  LengthOutput = new Fl_Value_Output(157, 120, 50, 15);
184 	  LengthOutput->labelsize(10);
185 	  LengthOutput->textsize(10);
186 
187 	  MagicOutput = new Fl_Value_Output(125, 235, 50, 15);
188 	  MagicOutput->labelsize(10);
189 	  MagicOutput->textsize(10);
190 
191 	  Master = new Fl_LED_Button(2, 5, 40, 25, "Master");
192 	  Master->type(1);
193 	  Master->color(SpiralLoopsInfo::GUIBG2_COLOUR);
194       Master->down_box(FL_DOWN_BOX);
195       Master->labelsize(10);
196       Master->callback((Fl_Callback*)cb_Master);
197 
198 	  Update = new Fl_LED_Button(2, 275, 40, 25, "Update");
199 	  Update->type(1);
200 	  Update->value(0);
201 	  Update->selection_color(3);
202       Update->down_box(FL_DOWN_BOX);
203       Update->labelsize(10);
204       Update->callback((Fl_Callback*)cb_Update);
205 
206 	  WaveSize = new Fl_Knob(262, 5, 30, 30, "WaveSize");
207       WaveSize->color(SpiralLoopsInfo::GUI_COLOUR);
208 	  WaveSize->type(Fl_Knob::DOTLIN);
209       WaveSize->labelsize(8);
210       WaveSize->maximum(10.0);
211       WaveSize->step(0.01);
212       WaveSize->value(0.0);
213 	  WaveSize->callback((Fl_Callback*)cb_WaveSize);
214 
215 	  DelayWin = new DelayGUI(m_DelayPtr);
216 	  DelayWin->CreateGUI(0,300,"Delay");
217 
218 	  ReverbWin = new ReverbGUI(m_ReverbPtr);
219 	  ReverbWin->CreateGUI(0,365,"Reverb");
220 
221       GUILoopGroup->show();
222 	  GUILoopGroup->end();
223   }
224 }
225 
SetMasterStatus(bool m)226 void LoopGUI::SetMasterStatus(bool m)
227 {
228 	m_loop->SetMasterStatus(m);
229 	MagicOutput->value(m_loop->GetMagic());
230 	Master->value(m);
231 	GUILoopGroup->redraw();
232 }
233 
CheckTriggers(float CurrentAngle,vector<int> & LoopTriggers)234 void LoopGUI::CheckTriggers(float CurrentAngle, vector<int> &LoopTriggers)
235 {
236 	for (vector<Fl_Trigger*>::iterator i=m_TriggerVec.begin();
237 		 i!=m_TriggerVec.end(); i++)
238 	{
239 		// Todo: Better detection needed
240 
241 		if (CurrentAngle>(*i)->GetAngle() &&
242 		    m_LastAngle<(*i)->GetAngle())
243 		{
244 			if ((*i)->Completed() && (*i)->GetPass()!=0)
245 			{
246 				m_loop->SetPlaying(false);
247 				Play->value(false);
248 			}
249 
250 			LoopTriggers.push_back((*i)->GetLoop());
251 			(*i)->IncCount();
252 			(*i)->redraw();
253 		}
254 	}
255 
256 	m_LastAngle=CurrentAngle;
257 }
258 
SetSnapAngle(int Angle)259 void LoopGUI::SetSnapAngle(int Angle)
260 {
261 	m_SnapAngle = Angle;
262 
263 	for (vector<Fl_Trigger*>::iterator i=m_TriggerVec.begin();
264 		 i!=m_TriggerVec.end(); i++)
265 	{
266 		(*i)->SetSnapAngle(Angle);
267 	}
268 
269 	GUILoopGroup->SetSnapAngle(Angle);
270 	GUILoopGroup->redraw();
271 }
272 
273 
SetSnap(bool s)274 void LoopGUI::SetSnap(bool s)
275 {
276 	for (vector<Fl_Trigger*>::iterator i=m_TriggerVec.begin();
277 		 i!=m_TriggerVec.end(); i++)
278 	{
279 		(*i)->SetSnap(s);
280 	}
281 
282 	GUILoopGroup->SetSnap(s);
283 }
284 
UpdateValues()285 void LoopGUI::UpdateValues()
286 {
287       Volume->value(1.0f-m_loop->GetVolume());
288       Cutoff->value(100.0f-sqrt(m_loop->GetCutoff()-10.0f));
289       Resonance->value(m_loop->GetResonance()-1.0f);
290       Balance->value(m_loop->GetBalance());
291       Speed->value(m_loop->GetSpeed());
292       Length->value(m_loop->GetLoopLength()/(float)m_loop->GetTotalLength());
293       Effects->value(m_loop->GetEffects());
294 	  Play->value(m_loop->IsPlaying());
295       Master->value(m_loop->IsMaster());
296 
297 	  DelayWin->UpdateValues();
298 	  ReverbWin->UpdateValues();
299 }
300 
UpdateDataPtr()301 void LoopGUI::UpdateDataPtr()
302 {
303 	GUILoopGroup->SetData(m_loop->GetLoopPtr());
304 }
305 
306 
307 //// Callbacks ////
308 
cb_Loop_i(Fl_Loop * o,void * v)309 inline void LoopGUI::cb_Loop_i(Fl_Loop* o, void* v)
310 {
311 	o->hide();
312 	m_loop->DelMe();
313 }
cb_Loop(Fl_Loop * o,void * v)314 void LoopGUI::cb_Loop(Fl_Loop* o, void* v)
315 { ((LoopGUI*)(o->user_data()))->cb_Loop_i(o,v); }
316 
cb_Volume_i(Fl_Slider * o,void * v)317 inline void LoopGUI::cb_Volume_i(Fl_Slider* o, void* v)
318 {
319 	m_loop->SetVolume(1.0f-o->value());
320 }
cb_Volume(Fl_Slider * o,void * v)321 void LoopGUI::cb_Volume(Fl_Slider* o, void* v)
322 { ((LoopGUI*)(o->parent()->user_data()))->cb_Volume_i(o,v); }
323 
cb_Cutoff_i(Fl_Slider * o,void * v)324 inline void LoopGUI::cb_Cutoff_i(Fl_Slider* o, void* v)
325 {
326 	m_loop->FilterBypass(o->value()==0);
327 	float value=100.0f-o->value();
328 	m_loop->SetCutoff(value*value+10.0f);
329 }
cb_Cutoff(Fl_Slider * o,void * v)330 void LoopGUI::cb_Cutoff(Fl_Slider* o, void* v)
331 { ((LoopGUI*)(o->parent()->user_data()))->cb_Cutoff_i(o,v); }
332 
cb_Balance_i(Fl_Knob * o,void * v)333 inline void LoopGUI::cb_Balance_i(Fl_Knob* o, void* v)
334 {
335 	/*float rvalue=1+o->value()-1.0f;
336 	float lvalue=2-o->value();
337 
338 	m_loop->SetLeftVol(lvalue/2.0f);
339 	m_loop->SetRightVol(rvalue/2.0f);*/
340 
341 	m_loop->SetBalance(o->value());
342 
343 }
cb_Balance(Fl_Knob * o,void * v)344 void LoopGUI::cb_Balance(Fl_Knob* o, void* v)
345 { ((LoopGUI*)(o->parent()->user_data()))->cb_Balance_i(o,v); }
346 
cb_Length_i(Fl_Knob * o,void * v)347 inline void LoopGUI::cb_Length_i(Fl_Knob* o, void* v)
348 {
349 	m_loop->SetLength(o->value()*m_loop->GetTotalLength());
350 	GUILoopGroup->SetLength(m_loop->GetLoopLength());
351 
352 	LengthOutput->value((float)m_loop->GetLoopLength()/(float)SpiralLoopsInfo::SAMPLERATE);
353 	MagicOutput->value(m_loop->GetMagic());
354 	GUILoopGroup->redraw();
355 }
cb_Length(Fl_Knob * o,void * v)356 void LoopGUI::cb_Length(Fl_Knob* o, void* v)
357 { ((LoopGUI*)(o->parent()->user_data()))->cb_Length_i(o,v); }
358 
cb_Speed_i(Fl_Knob * o,void * v)359 inline void LoopGUI::cb_Speed_i(Fl_Knob* o, void* v)
360 {
361 	m_loop->SetSpeed(o->value());
362 	SpeedOutput->value(o->value());
363 	MagicOutput->value(m_loop->GetMagic());
364 }
cb_Speed(Fl_Knob * o,void * v)365 void LoopGUI::cb_Speed(Fl_Knob* o, void* v)
366 { ((LoopGUI*)(o->parent()->user_data()))->cb_Speed_i(o,v); }
367 
cb_Resonance_i(Fl_Knob * o,void * v)368 inline void LoopGUI::cb_Resonance_i(Fl_Knob* o, void* v)
369 {
370 	m_loop->SetResonance(o->value()+1.0f);
371 }
cb_Resonance(Fl_Knob * o,void * v)372 void LoopGUI::cb_Resonance(Fl_Knob* o, void* v)
373 { ((LoopGUI*)(o->parent()->user_data()))->cb_Resonance_i(o,v); }
374 
cb_Record_i(Fl_Button * o,void * v)375 inline void LoopGUI::cb_Record_i(Fl_Button* o, void* v)
376 {
377 	m_loop->Record(o->value());
378 	GUILoopGroup->SetData(m_loop->GetLoopPtr());
379 	GUILoopGroup->SetLength(m_loop->GetLoopLength());
380 	GUILoopGroup->redraw();
381 }
cb_Record(Fl_Button * o,void * v)382 void LoopGUI::cb_Record(Fl_Button* o, void* v)
383 { ((LoopGUI*)(o->parent()->user_data()))->cb_Record_i(o,v); }
384 
cb_Load_i(Fl_Button * o,void * v)385 inline void LoopGUI::cb_Load_i(Fl_Button* o, void* v)
386 {
387 	//GUILoopGroup->UnsetIdle();
388 	char *fn=fl_file_chooser("Pick a Wav file to load", "*.wav", NULL);
389 
390 	if (fn && fn!="")
391 	{
392 		m_loop->LoadWav(fn);
393 	}
394 
395   GUILoopGroup->SetData(m_loop->GetLoopPtr());
396   GUILoopGroup->SetLength(m_loop->GetLoopLength());
397 
398   LengthOutput->value(m_loop->GetLoopLength()/(float)SpiralLoopsInfo::SAMPLERATE);
399   MagicOutput->value(m_loop->GetMagic());
400   //GUILoopGroup->SetIdle();
401   GUILoopGroup->redraw();
402 }
cb_Load(Fl_Button * o,void * v)403 void LoopGUI::cb_Load(Fl_Button* o, void* v)
404 { ((LoopGUI*)(o->parent()->user_data()))->cb_Load_i(o,v); }
405 
cb_Play_i(Fl_LED_Button * o,void * v)406 inline void LoopGUI::cb_Play_i(Fl_LED_Button* o, void* v)
407 {
408 	m_loop->SetPlaying(o->value());
409 }
cb_Play(Fl_LED_Button * o,void * v)410 void LoopGUI::cb_Play(Fl_LED_Button* o, void* v)
411 { ((LoopGUI*)(o->parent()->user_data()))->cb_Play_i(o,v); }
412 
cb_Master_i(Fl_LED_Button * o,void * v)413 inline void LoopGUI::cb_Master_i(Fl_LED_Button* o, void* v)
414 {
415 	m_loop->SetMaster();
416 	MagicOutput->value(m_loop->GetMagic());
417 	GUILoopGroup->redraw();
418 }
cb_Master(Fl_LED_Button * o,void * v)419 void LoopGUI::cb_Master(Fl_LED_Button* o, void* v)
420 { ((LoopGUI*)(o->parent()->user_data()))->cb_Master_i(o,v); }
421 
cb_Effects_i(Fl_Button * o,void * v)422 inline void LoopGUI::cb_Effects_i(Fl_Button* o, void* v)
423 {
424 	if (o->value())
425 	{
426 		GUILoopGroup->resize(GUILoopGroup->x(),GUILoopGroup->y(),
427 				GUILoopGroup->w(),GUILoopGroup->h()+EFFECT_ADDITION);
428 	}
429 	else
430 	{
431 		GUILoopGroup->resize(GUILoopGroup->x(),GUILoopGroup->y(),
432 				GUILoopGroup->w(),GUILoopGroup->h()-EFFECT_ADDITION);
433 	}
434 
435 	m_loop->SetEffects(o->value());
436 }
cb_Effects(Fl_Button * o,void * v)437 void LoopGUI::cb_Effects(Fl_Button* o, void* v)
438 { ((LoopGUI*)(o->parent()->user_data()))->cb_Effects_i(o,v); }
439 
cb_Update_i(Fl_LED_Button * o,void * v)440 inline void LoopGUI::cb_Update_i(Fl_LED_Button* o, void* v)
441 {
442 	GUILoopGroup->SetUpdate(o->value());
443 }
cb_Update(Fl_LED_Button * o,void * v)444 void LoopGUI::cb_Update(Fl_LED_Button* o, void* v)
445 { ((LoopGUI*)(o->parent()->user_data()))->cb_Update_i(o,v); }
446 
cb_Double_i(Fl_Button * o,void * v)447 inline void LoopGUI::cb_Double_i(Fl_Button* o, void* v)
448 {
449 	m_loop->Double();
450 
451 	GUILoopGroup->SetData(m_loop->GetLoopPtr());
452 	GUILoopGroup->SetLength(m_loop->GetLoopLength());
453 	GUILoopGroup->redraw();
454 
455 }
cb_Double(Fl_Button * o,void * v)456 void LoopGUI::cb_Double(Fl_Button* o, void* v)
457 { ((LoopGUI*)(o->parent()->user_data()))->cb_Double_i(o,v); }
458 
cb_Match_i(Fl_Button * o,void * v)459 inline void LoopGUI::cb_Match_i(Fl_Button* o, void* v)
460 {
461 	// simplest way to check if there is a master loop or not
462 	if (m_loop->GetMasterLength()==0) return;
463 
464 	m_loop->MatchLength(m_loop->GetMasterLength());
465 	m_loop->SetSpeed(m_loop->GetMasterSpeed());
466 
467 	GUILoopGroup->SetData(m_loop->GetLoopPtr());
468 	GUILoopGroup->SetLength(m_loop->GetLoopLength());
469 	GUILoopGroup->redraw();
470 }
cb_Match(Fl_Button * o,void * v)471 void LoopGUI::cb_Match(Fl_Button* o, void* v)
472 { ((LoopGUI*)(o->parent()->user_data()))->cb_Match_i(o,v); }
473 
cb_Save_i(Fl_Button * o,void * v)474 inline void LoopGUI::cb_Save_i(Fl_Button* o, void* v)
475 {
476 	char *fn=fl_file_chooser("Save loop as Wav file", "*.wav", NULL);
477 
478 	if (fn && fn!="")
479 	{
480 		m_loop->SaveWav(fn);
481 	}
482 }
cb_Save(Fl_Button * o,void * v)483 void LoopGUI::cb_Save(Fl_Button* o, void* v)
484 { ((LoopGUI*)(o->parent()->user_data()))->cb_Save_i(o,v); }
485 
cb_WaveSize_i(Fl_Knob * o,void * v)486 inline void LoopGUI::cb_WaveSize_i(Fl_Knob* o, void* v)
487 {
488 	GUILoopGroup->SetWaveSize(1+o->value());
489 	GUILoopGroup->redraw();
490 }
cb_WaveSize(Fl_Knob * o,void * v)491 void LoopGUI::cb_WaveSize(Fl_Knob* o, void* v)
492 { ((LoopGUI*)(o->parent()->user_data()))->cb_WaveSize_i(o,v); }
493 
494 
495 ////////////////////////////////////////////////////////////////
496 
497 
cb_Cut_i(Fl_Loop * o,int Start,int End)498 inline void LoopGUI::cb_Cut_i(Fl_Loop *o, int Start, int End)
499 {
500 	m_loop->Cut(Start,End);
501 	GUILoopGroup->SetData(m_loop->GetLoopPtr());
502 	GUILoopGroup->SetLength(m_loop->GetLoopLength());
503 	GUILoopGroup->redraw();
504 }
cb_Cut(Fl_Loop * o,int Start,int End)505 void LoopGUI::cb_Cut(Fl_Loop *o, int Start, int End)
506 { ((LoopGUI*)(o->user_data()))->cb_Cut_i(o,Start,End); }
507 
cb_Copy_i(Fl_Loop * o,int Start,int End)508 void LoopGUI::cb_Copy_i(Fl_Loop *o, int Start, int End)
509 {
510 	m_loop->Copy(Start,End);
511 	GUILoopGroup->SetData(m_loop->GetLoopPtr());
512 	GUILoopGroup->SetLength(m_loop->GetLoopLength());
513 	GUILoopGroup->redraw();
514 }
cb_Copy(Fl_Loop * o,int Start,int End)515 void LoopGUI::cb_Copy(Fl_Loop *o, int Start, int End)
516 { ((LoopGUI*)(o->user_data()))->cb_Copy_i(o,Start,End); }
517 
cb_Paste_i(Fl_Loop * o,int Start)518 inline void LoopGUI::cb_Paste_i(Fl_Loop *o, int Start)
519 {
520 	m_loop->Paste(Start);
521 	GUILoopGroup->SetData(m_loop->GetLoopPtr());
522 	GUILoopGroup->SetLength(m_loop->GetLoopLength());
523 	GUILoopGroup->redraw();
524 }
cb_Paste(Fl_Loop * o,int Start)525 void LoopGUI::cb_Paste(Fl_Loop *o, int Start)
526 { ((LoopGUI*)(o->user_data()))->cb_Paste_i(o,Start); }
527 
cb_PasteMix_i(Fl_Loop * o,int Start)528 inline void LoopGUI::cb_PasteMix_i(Fl_Loop *o, int Start)
529 {
530 	m_loop->PasteMix(Start);
531 	GUILoopGroup->SetData(m_loop->GetLoopPtr());
532 	GUILoopGroup->SetLength(m_loop->GetLoopLength());
533 	GUILoopGroup->redraw();
534 }
cb_PasteMix(Fl_Loop * o,int Start)535 void LoopGUI::cb_PasteMix(Fl_Loop *o, int Start)
536 { ((LoopGUI*)(o->user_data()))->cb_PasteMix_i(o,Start); }
537 
538 
cb_ZeroRange_i(Fl_Loop * o,int Start,int End)539 inline void LoopGUI::cb_ZeroRange_i(Fl_Loop *o, int Start, int End)
540 {
541 	m_loop->ZeroRange(Start,End);
542 	GUILoopGroup->SetData(m_loop->GetLoopPtr());
543 	GUILoopGroup->SetLength(m_loop->GetLoopLength());
544 	GUILoopGroup->redraw();
545 }
cb_ZeroRange(Fl_Loop * o,int Start,int End)546 void LoopGUI::cb_ZeroRange(Fl_Loop *o, int Start, int End)
547 { ((LoopGUI*)(o->user_data()))->cb_ZeroRange_i(o,Start,End); }
548 
cb_ReverseRange_i(Fl_Loop * o,int Start,int End)549 inline void LoopGUI::cb_ReverseRange_i(Fl_Loop *o, int Start, int End)
550 {
551 	m_loop->ReverseRange(Start,End);
552 	GUILoopGroup->SetData(m_loop->GetLoopPtr());
553 	GUILoopGroup->SetLength(m_loop->GetLoopLength());
554 	GUILoopGroup->redraw();
555 }
cb_ReverseRange(Fl_Loop * o,int Start,int End)556 void LoopGUI::cb_ReverseRange(Fl_Loop *o, int Start, int End)
557 { ((LoopGUI*)(o->user_data()))->cb_ReverseRange_i(o,Start,End); }
558 
cb_Halve_i(Fl_Loop * o,int Start,int End)559 inline void LoopGUI::cb_Halve_i(Fl_Loop *o, int Start, int End)
560 {
561 	m_loop->Halve();
562 	GUILoopGroup->SetData(m_loop->GetLoopPtr());
563 	GUILoopGroup->SetLength(m_loop->GetLoopLength());
564 	GUILoopGroup->redraw();
565 }
cb_Halve(Fl_Loop * o,int Start,int End)566 void LoopGUI::cb_Halve(Fl_Loop *o, int Start, int End)
567 { ((LoopGUI*)(o->user_data()))->cb_Halve_i(o,Start,End); }
568 
cb_Hold_i(Fl_Loop * o,int Start,int End)569 inline void LoopGUI::cb_Hold_i(Fl_Loop *o, int Start, int End)
570 {
571 	m_loop->Hold();
572 	GUILoopGroup->SetData(m_loop->GetLoopPtr());
573 	GUILoopGroup->SetLength(m_loop->GetLoopLength());
574 	GUILoopGroup->redraw();
575 }
cb_Hold(Fl_Loop * o,int Start,int End)576 void LoopGUI::cb_Hold(Fl_Loop *o, int Start, int End)
577 { ((LoopGUI*)(o->user_data()))->cb_Hold_i(o,Start,End); }
578 
cb_SelectAll_i(Fl_Loop * o,int Start,int End)579 inline void LoopGUI::cb_SelectAll_i(Fl_Loop *o, int Start, int End)
580 {
581 	m_loop->SelectAll();
582 	GUILoopGroup->SetData(m_loop->GetLoopPtr());
583 	GUILoopGroup->SetLength(m_loop->GetLoopLength());
584 	GUILoopGroup->redraw();
585 }
cb_SelectAll(Fl_Loop * o,int Start,int End)586 void LoopGUI::cb_SelectAll(Fl_Loop *o, int Start, int End)
587 { ((LoopGUI*)(o->user_data()))->cb_SelectAll_i(o,Start,End); }
588 
cb_NewTrigger_i(Fl_Loop * o,int Start,int End)589 inline void LoopGUI::cb_NewTrigger_i(Fl_Loop *o, int Start, int End)
590 {
591 	Fl_Trigger *NewTrigger = new Fl_Trigger(0, 0, 20, 20);
592 	NewTrigger->SetCentreX(150);
593 	NewTrigger->SetCentreY(150);
594 	NewTrigger->SetCentreRadius(125);
595 
596 	GUILoopGroup->add(NewTrigger);
597 	m_TriggerVec.push_back(NewTrigger);
598 	GUILoopGroup->redraw();
599 }
cb_NewTrigger(Fl_Loop * o,int Start,int End)600 void LoopGUI::cb_NewTrigger(Fl_Loop *o, int Start, int End)
601 { ((LoopGUI*)(o->user_data()))->cb_NewTrigger_i(o,Start,End); }
602 
cb_Move_i(Fl_Loop * o,int Start,int End)603 inline void LoopGUI::cb_Move_i(Fl_Loop *o, int Start, int End)
604 {
605 	m_loop->Move(Start);
606 	GUILoopGroup->SetData(m_loop->GetLoopPtr());
607 	GUILoopGroup->SetLength(m_loop->GetLoopLength());
608 	GUILoopGroup->redraw();
609 }
cb_Move(Fl_Loop * o,int Start,int End)610 void LoopGUI::cb_Move(Fl_Loop *o, int Start, int End)
611 { ((LoopGUI*)(o->user_data()))->cb_Move_i(o,Start,End); }
612 
613 /////////////////////////////////////////////////////
614 
615 istream &operator>>(istream &s, LoopGUI &o)
616 {
617 	int x,y,w,h;
618 	s>>x>>y>>w>>h;
619 	o.GUILoopGroup->resize(x,y,w,h);
620 
621 	int Num;
622 	s>>Num;
623 
624 	for (int n=0; n<Num; n++)
625 	{
626 		Fl_Trigger *NewTrigger = new Fl_Trigger(0, 0, 20, 20);
627 		s>>*NewTrigger;
628 		o.GUILoopGroup->add(NewTrigger);
629 		o.m_TriggerVec.push_back(NewTrigger);
630 	}
631 
632 	return s;
633 }
634 
635 ostream &operator<<(ostream &s, LoopGUI &o)
636 {
637 	s<<o.GUILoopGroup->GetX()<<" "<<o.GUILoopGroup->GetY()<<" "<<
638 	   o.GUILoopGroup->GetW()<<" "<<o.GUILoopGroup->GetH()<<" ";
639 
640 	s<<o.m_TriggerVec.size()<<" ";
641 
642 	for (vector<Fl_Trigger*>::iterator i=o.m_TriggerVec.begin();
643 		 i!=o.m_TriggerVec.end(); i++)
644 	{
645 		s<<**i;
646 	}
647 
648 	return s;
649 }
650