You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

748 lines
22KB

  1. /* SpiralPlugin
  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 "PoshSamplerPluginGUI.h"
  19. #include <FL/fl_draw.h>
  20. #include <FL/fl_draw.H>
  21. #include <FL/fl_file_chooser.h>
  22. using namespace std;
  23. ////////////////////////////////////////////
  24. Fl_WaveDisplay::Fl_WaveDisplay(int x,int y,int w,int h, char *Name) :
  25. Fl_Widget(x,y,w,h,Name),
  26. m_Sample(NULL),
  27. m_StartPos(1),
  28. m_EndPos(10),
  29. m_ViewStart(0),
  30. m_ViewEnd(INT_MAX),
  31. m_PlayPos(0),
  32. m_PlayStart(0),
  33. m_LoopStart(0),
  34. m_LoopEnd(INT_MAX),
  35. m_PosMarker(true)
  36. {
  37. }
  38. Fl_WaveDisplay::~Fl_WaveDisplay()
  39. {
  40. }
  41. void Fl_WaveDisplay::SetSample(const float* s, long len)
  42. {
  43. if (m_Sample) delete m_Sample;
  44. m_Sample = new Sample(s,len);
  45. }
  46. void Fl_WaveDisplay::draw()
  47. {
  48. int ho=h()/2;
  49. fl_color (m_BGColour);
  50. fl_rectf(x(), y(), w(), h());
  51. if (!m_Sample || m_Sample->GetLength()==0) return;
  52. if (m_ViewStart<0) m_ViewStart=0;
  53. if (m_ViewEnd>m_Sample->GetLength()-1) m_ViewEnd=m_Sample->GetLength()-1;
  54. if (m_PlayStart<0) m_PlayStart=0;
  55. if (m_PlayStart>m_Sample->GetLength()-1) m_PlayStart=m_Sample->GetLength()-1;
  56. if (m_LoopStart<0) m_LoopStart=0;
  57. if (m_LoopStart>m_Sample->GetLength()-1) m_LoopStart=m_Sample->GetLength()-1;
  58. if (m_LoopEnd<0) m_LoopEnd=0;
  59. if (m_LoopEnd>m_Sample->GetLength()-1) m_LoopEnd=m_Sample->GetLength()-1;
  60. float Value=0,NextValue=0;
  61. int pos=0;
  62. int Jump=(m_ViewEnd-m_ViewStart)/w();
  63. if (Jump==0) Jump=1;
  64. for(int n=m_ViewStart; n<m_ViewEnd-Jump; n+=Jump)
  65. {
  66. fl_font(fl_font(),10);
  67. if (m_PlayPos>=n && m_PlayPos<n+Jump)
  68. {
  69. fl_color (m_IndColour);
  70. fl_line(x()+pos, y(),
  71. x()+pos, y()+h());
  72. }
  73. if (m_PlayStart>=n && m_PlayStart<n+Jump)
  74. {
  75. fl_color (m_MrkColour);
  76. fl_draw("S",x()+pos+2,y()+h());
  77. fl_line(x()+pos, y(),
  78. x()+pos, y()+h());
  79. }
  80. if (m_LoopStart>=n && m_LoopStart<n+Jump)
  81. {
  82. fl_color (m_MrkColour);
  83. fl_draw("LS",x()+pos+2,y()+h());
  84. fl_line(x()+pos, y(),
  85. x()+pos, y()+h());
  86. }
  87. if (m_LoopEnd>=n && m_LoopEnd<n+Jump)
  88. {
  89. fl_color (m_MrkColour);
  90. fl_draw("LE",x()+pos+2,y()+h());
  91. fl_line(x()+pos, y(),
  92. x()+pos, y()+h());
  93. }
  94. if (n>m_StartPos && n<m_EndPos) fl_color (m_SelColour);
  95. else fl_color (m_FGColour);
  96. Value = NextValue;
  97. // get max
  98. float max=(*m_Sample)[n];
  99. float min=(*m_Sample)[n];
  100. for (int m=n; m<n+Jump; m++)
  101. {
  102. if (max<(*m_Sample)[m]) max=(*m_Sample)[m];
  103. if (min>(*m_Sample)[m]) min=(*m_Sample)[m];
  104. }
  105. min*=ho; max*=ho;
  106. fl_line(x()+pos-1, y()+ho-(int)min,
  107. x()+pos-1, y()+ho-(int)max);
  108. pos++;
  109. }
  110. }
  111. int Fl_WaveDisplay::handle(int event)
  112. {
  113. int xx=Fl::event_x();
  114. int yy=Fl::event_y();
  115. static int DragX,DragY;
  116. static int Mousebutton=0;
  117. static int Holding=0;
  118. static int GrabDist=10;
  119. if (!m_Sample || m_Sample->GetLength()==0) return 1;
  120. if (event==FL_PUSH)
  121. {
  122. GrabDist=(int)((m_ViewEnd-m_ViewStart)*0.03f);
  123. Mousebutton=Fl::event_button();
  124. DragX=xx;
  125. DragY=yy;
  126. if (Mousebutton==1)
  127. {
  128. int MousePos=(xx-x())*((m_ViewEnd-m_ViewStart)/w())+m_ViewStart;
  129. Holding=0;
  130. if (abs(MousePos-m_StartPos)<GrabDist) Holding=1;
  131. else if (abs(MousePos-m_EndPos)<GrabDist) Holding=2;
  132. else if (abs(MousePos-m_PlayStart)<GrabDist) Holding=3;
  133. else if (abs(MousePos-m_LoopStart)<GrabDist) Holding=4;
  134. else if (abs(MousePos-m_LoopEnd)<GrabDist) Holding=5;
  135. else
  136. {
  137. m_StartPos=MousePos;
  138. m_EndPos=MousePos;
  139. }
  140. }
  141. }
  142. if (event==FL_DRAG)
  143. {
  144. if (Mousebutton==1)
  145. {
  146. int MousePos=(xx-x())*((m_ViewEnd-m_ViewStart)/w())+m_ViewStart;
  147. switch (Holding)
  148. {
  149. case 0:
  150. {
  151. if (MousePos>m_EndPos) m_EndPos=MousePos;
  152. else m_StartPos=MousePos;
  153. } break;
  154. case 1:
  155. {
  156. m_StartPos=MousePos;
  157. if (m_StartPos>m_EndPos) Holding=2; // swap
  158. } break;
  159. case 2:
  160. {
  161. m_EndPos=MousePos;
  162. if (m_StartPos>m_EndPos) Holding=1; // swap
  163. } break;
  164. case 3: m_PlayStart=MousePos; break;
  165. case 4: m_LoopStart=MousePos; break;
  166. case 5: m_LoopEnd=MousePos; break;
  167. }
  168. }
  169. if (Mousebutton==2)
  170. {
  171. int Dist=(DragX-xx)*((m_ViewEnd-m_ViewStart)/w());
  172. if (m_ViewStart>0 && m_ViewEnd<m_Sample->GetLength()-1)
  173. {
  174. m_ViewStart+=Dist;
  175. m_ViewEnd+=Dist;
  176. }
  177. else // stop it sticking when at end/beginning
  178. {
  179. if ((Dist>0 && m_ViewStart<=0) ||
  180. (Dist<0 && m_ViewEnd>=m_Sample->GetLength()-1))
  181. {
  182. m_ViewStart+=Dist;
  183. m_ViewEnd+=Dist;
  184. }
  185. }
  186. DragX=xx;
  187. DragY=yy;
  188. }
  189. if (Mousebutton==3)
  190. {
  191. // only draw wave at 1 pixel = 1 sample
  192. if ((m_ViewEnd-m_ViewStart)/w()==1)
  193. {
  194. int MousePos=(xx-x())*((m_ViewEnd-m_ViewStart)/w())+m_ViewStart;
  195. float Value=-(yy-y())/((float)h()/2.0f)+1.0f;
  196. m_Sample->Set(MousePos,Value);
  197. redraw();
  198. }
  199. }
  200. do_callback();
  201. redraw();
  202. }
  203. if (m_EndPos>=m_Sample->GetLength()) m_EndPos=m_Sample->GetLength()-1;
  204. return 1;
  205. }
  206. void Fl_WaveDisplay::ZoomIn()
  207. {
  208. int Zoom=(int)((m_ViewEnd-m_ViewStart)*0.03f);
  209. if ((m_ViewEnd-m_ViewStart)/w()>1)
  210. {
  211. m_ViewStart+=Zoom;
  212. m_ViewEnd-=Zoom;
  213. }
  214. redraw();
  215. }
  216. void Fl_WaveDisplay::ZoomOut()
  217. {
  218. int Zoom=(int)((m_ViewEnd-m_ViewStart)*0.03f);
  219. m_ViewStart-=Zoom;
  220. m_ViewEnd+=Zoom;
  221. redraw();
  222. }
  223. ////////////////////////////////////////////
  224. PoshSamplerPluginGUI::PoshSamplerPluginGUI(int w, int h,PoshSamplerPlugin *o,ChannelHandler *ch,const HostInfo *Info) :
  225. SpiralPluginGUI(w,h,o,ch),
  226. m_UpdateMe(false)
  227. {
  228. int n=0;
  229. m_Load = new Fl_Button(5, 20, 70, 20, "Load");
  230. m_Load->labelsize(10);
  231. m_Load->box (FL_PLASTIC_UP_BOX);
  232. m_Load->color (Info->GUI_COLOUR);
  233. m_Load->selection_color (Info->GUI_COLOUR);
  234. m_Load->callback((Fl_Callback*)cb_Load);
  235. add(m_Load);
  236. m_Save = new Fl_Button(5, 40, 70, 20, "Save");
  237. m_Save->labelsize(10);
  238. m_Save->box (FL_PLASTIC_UP_BOX);
  239. m_Save->color (Info->GUI_COLOUR);
  240. m_Save->selection_color (Info->GUI_COLOUR);
  241. m_Save->callback((Fl_Callback*)cb_Save);
  242. add(m_Save);
  243. m_Record = new Fl_Button(5, 60, 70, 20, "Record");
  244. m_Record->type (FL_TOGGLE_BUTTON);
  245. m_Record->box (FL_PLASTIC_UP_BOX);
  246. m_Record->color (FL_RED);
  247. m_Record->selection_color (FL_RED);
  248. m_Record->labelsize (10);
  249. //m_Record->labelcolor (FL_RED);
  250. m_Record->callback((Fl_Callback*)cb_Record);
  251. add(m_Record);
  252. m_Loop = new Fl_Button(80, 20, 70, 20, "Loop");
  253. m_Loop->type (FL_TOGGLE_BUTTON);
  254. m_Loop->labelsize(10);
  255. m_Loop->box (FL_PLASTIC_UP_BOX);
  256. m_Loop->color (Info->GUI_COLOUR);
  257. m_Loop->selection_color (Info->GUI_COLOUR);
  258. m_Loop->callback((Fl_Callback*)cb_Loop);
  259. add(m_Loop);
  260. m_PingPong = new Fl_Button(80, 40, 70, 20, "PingPong");
  261. m_PingPong->labelsize(10);
  262. m_PingPong->type (FL_TOGGLE_BUTTON);
  263. m_PingPong->labelsize(10);
  264. m_PingPong->box (FL_PLASTIC_UP_BOX);
  265. m_PingPong->color (Info->GUI_COLOUR);
  266. m_PingPong->selection_color (Info->GUI_COLOUR);
  267. m_PingPong->callback((Fl_Callback*)cb_PingPong);
  268. add(m_PingPong);
  269. m_PosMarker = new Fl_Button(80, 60, 70, 20, "PosMarker");
  270. m_PosMarker->labelsize(10);
  271. m_PosMarker->type (FL_TOGGLE_BUTTON);
  272. m_PosMarker->labelsize(10);
  273. m_PosMarker->box (FL_PLASTIC_UP_BOX);
  274. m_PosMarker->color (Info->GUI_COLOUR);
  275. m_PosMarker->selection_color (Info->GUI_COLOUR);
  276. m_PosMarker->value(1);
  277. m_PosMarker->callback((Fl_Callback*)cb_PosMarker);
  278. add(m_PosMarker);
  279. m_Volume = new Fl_Knob(160, 20, 50, 50, "Volume");
  280. m_Volume->color(Info->GUI_COLOUR);
  281. m_Volume->type(Fl_Knob::LINELIN);
  282. m_Volume->labelsize(10);
  283. m_Volume->maximum(2);
  284. m_Volume->step(0.001);
  285. m_Volume->value(1);
  286. m_Volume->callback((Fl_Callback*)cb_Volume);
  287. add(m_Volume);
  288. m_Pitch = new Fl_Knob(220, 20, 50, 50, "Pitch");
  289. m_Pitch->color(Info->GUI_COLOUR);
  290. m_Pitch->type(Fl_Knob::LINELIN);
  291. m_Pitch->labelsize(10);
  292. m_Pitch->maximum(10);
  293. m_Pitch->step(0.001);
  294. m_Pitch->value(1);
  295. m_Pitch->callback((Fl_Callback*)cb_Pitch);
  296. add(m_Pitch);
  297. m_Octave = new Fl_Knob(280, 20, 50, 50, "Octave");
  298. m_Octave->color(Info->GUI_COLOUR);
  299. m_Octave->type(Fl_Knob::LINELIN);
  300. m_Octave->labelsize(10);
  301. m_Octave->maximum(12);
  302. m_Octave->step(1);
  303. m_Octave->value(6);
  304. m_Octave->callback((Fl_Callback*)cb_Octave);
  305. add(m_Octave);
  306. m_SampleNum = new Fl_Counter (w-60, 15, 45, 20, "Sample");
  307. m_SampleNum->labelsize(10);
  308. m_SampleNum->type(FL_SIMPLE_COUNTER);
  309. m_SampleNum->box (FL_PLASTIC_UP_BOX);
  310. m_SampleNum->color (Info->GUI_COLOUR);
  311. m_SampleNum->selection_color (Info->GUI_COLOUR);
  312. m_SampleNum->step(1);
  313. m_SampleNum->value(n);
  314. m_SampleNum->callback((Fl_Callback*)cb_SampleNum);
  315. add(m_SampleNum);
  316. m_Note = new Fl_Counter (w-60, 50, 45, 20, "Trig Note");
  317. m_Note->labelsize(10);
  318. m_Note->type(FL_SIMPLE_COUNTER);
  319. m_Note->box (FL_PLASTIC_UP_BOX);
  320. m_Note->color (Info->GUI_COLOUR);
  321. m_Note->selection_color (Info->GUI_COLOUR);
  322. m_Note->step(1);
  323. m_Note->value(n);
  324. m_Note->callback((Fl_Callback*)cb_Note);
  325. add(m_Note);
  326. m_Display = new Fl_WaveDisplay(5,85,w-10,100,"");
  327. m_Display->SetColours (Info->SCOPE_BG_COLOUR, Info->SCOPE_FG_COLOUR,
  328. Info->SCOPE_SEL_COLOUR, Info->SCOPE_IND_COLOUR, Info->SCOPE_MRK_COLOUR);
  329. m_Display->callback((Fl_Callback*)cb_WaveDisplay);
  330. int bx=5,by=190,bw=w/9-2,bh=20,bs=w/9-2;
  331. n=0;
  332. m_Cut = new Fl_Button(bx+(n++*bs),by,bw,bh,"Cut");
  333. m_Cut->labelsize(10);
  334. m_Cut->box (FL_PLASTIC_UP_BOX);
  335. m_Cut->color (Info->GUI_COLOUR);
  336. m_Cut->selection_color (Info->GUI_COLOUR);
  337. m_Cut->callback((Fl_Callback*)cb_Cut);
  338. m_Copy = new Fl_Button(bx+(n++*bs),by,bw,bh,"Copy");
  339. m_Copy->labelsize(10);
  340. m_Copy->box (FL_PLASTIC_UP_BOX);
  341. m_Copy->color (Info->GUI_COLOUR);
  342. m_Copy->selection_color (Info->GUI_COLOUR);
  343. m_Copy->callback((Fl_Callback*)cb_Copy);
  344. m_Paste = new Fl_Button(bx+(n++*bs),by,bw,bh,"Paste");
  345. m_Paste->labelsize(10);
  346. m_Paste->box (FL_PLASTIC_UP_BOX);
  347. m_Paste->color (Info->GUI_COLOUR);
  348. m_Paste->selection_color (Info->GUI_COLOUR);
  349. m_Paste->callback((Fl_Callback*)cb_Paste);
  350. m_Mix = new Fl_Button(bx+(n++*bs),by,bw,bh,"Mix");
  351. m_Mix->labelsize(10);
  352. m_Mix->box (FL_PLASTIC_UP_BOX);
  353. m_Mix->color (Info->GUI_COLOUR);
  354. m_Mix->selection_color (Info->GUI_COLOUR);
  355. m_Mix->callback((Fl_Callback*)cb_Mix);
  356. m_Crop = new Fl_Button(bx+(n++*bs),by,bw,bh,"Crop");
  357. m_Crop->labelsize(10);
  358. m_Crop->box (FL_PLASTIC_UP_BOX);
  359. m_Crop->color (Info->GUI_COLOUR);
  360. m_Crop->selection_color (Info->GUI_COLOUR);
  361. m_Crop->callback((Fl_Callback*)cb_Crop);
  362. m_Reverse = new Fl_Button(bx+(n++*bs),by,bw,bh,"Reverse");
  363. m_Reverse->labelsize(10);
  364. m_Reverse->box (FL_PLASTIC_UP_BOX);
  365. m_Reverse->color (Info->GUI_COLOUR);
  366. m_Reverse->selection_color (Info->GUI_COLOUR);
  367. m_Reverse->callback((Fl_Callback*)cb_Reverse);
  368. m_Amp = new Fl_Button(bx+(n++*bs),by,bw,bh,"Amp");
  369. m_Amp->labelsize(10);
  370. m_Amp->box (FL_PLASTIC_UP_BOX);
  371. m_Amp->color (Info->GUI_COLOUR);
  372. m_Amp->selection_color (Info->GUI_COLOUR);
  373. m_Amp->callback((Fl_Callback*)cb_Amp);
  374. m_ZoomIn = new Fl_Button(bx+(n++*bs),by,bw,bh,"Zoom +");
  375. m_ZoomIn->labelsize(10);
  376. m_ZoomIn->box (FL_PLASTIC_UP_BOX);
  377. m_ZoomIn->color (Info->GUI_COLOUR);
  378. m_ZoomIn->selection_color (Info->GUI_COLOUR);
  379. //m_ZoomIn->callback((Fl_Callback*)cb_ZoomIn);
  380. m_ZoomOut = new Fl_Button(bx+(n++*bs),by,bw,bh,"Zoom -");
  381. m_ZoomOut->labelsize(10);
  382. m_ZoomOut->box (FL_PLASTIC_UP_BOX);
  383. m_ZoomOut->color (Info->GUI_COLOUR);
  384. m_ZoomOut->selection_color (Info->GUI_COLOUR);
  385. //m_ZoomOut->callback((Fl_Callback*)cb_ZoomOut);
  386. end();
  387. redraw();
  388. }
  389. void PoshSamplerPluginGUI::UpdateSampleDisplay(int num)
  390. {
  391. m_GUICH->SetCommand(PoshSamplerPlugin::GETSAMPLE);
  392. m_GUICH->Wait();
  393. m_GUICH->RequestChannelAndWait("SampleSize");
  394. long SampleSize=m_GUICH->GetLong("SampleSize");
  395. if (SampleSize)
  396. {
  397. char *TempBuf = new char[SampleSize];
  398. m_GUICH->BulkTransfer("SampleBuffer",(void*)TempBuf,SampleSize);
  399. m_Display->SetSample((float*)TempBuf,SampleSize/sizeof(float));
  400. delete[] TempBuf;
  401. }
  402. }
  403. void PoshSamplerPluginGUI::Update()
  404. {
  405. SetPlayPos(m_GUICH->GetLong("PlayPos"));
  406. if (m_ZoomIn->value()) m_Display->ZoomIn();
  407. if (m_ZoomOut->value()) m_Display->ZoomOut();
  408. if (m_UpdateMe)
  409. {
  410. UpdateSampleDisplay((int)m_SampleNum->value());
  411. m_Display->redraw();
  412. m_UpdateMe=false;
  413. }
  414. //redraw();
  415. }
  416. void PoshSamplerPluginGUI::UpdateValues(SpiralPlugin *o)
  417. {
  418. PoshSamplerPlugin *Plugin = (PoshSamplerPlugin*)o;
  419. m_Volume->value(Plugin->GetVolume((int)m_SampleNum->value()));
  420. m_Pitch->value(Plugin->GetPitch((int)m_SampleNum->value()));
  421. m_Note->value(Plugin->GetNote((int)m_SampleNum->value()));
  422. m_Loop->value(Plugin->GetLoop((int)m_SampleNum->value()));
  423. m_UpdateMe=true;
  424. m_Display->SetPlayStart(Plugin->GetPlayStart((int)m_SampleNum->value()));
  425. m_Display->SetLoopStart(Plugin->GetLoopStart((int)m_SampleNum->value()));
  426. m_Display->SetLoopEnd(Plugin->GetLoopEnd((int)m_SampleNum->value()));
  427. m_Display->redraw();
  428. }
  429. inline void PoshSamplerPluginGUI::cb_Load_i(Fl_Button* o, void* v)
  430. {
  431. char *fn=fl_file_chooser("Load a sample", "{*.wav,*.WAV}", NULL);
  432. if (fn && fn!='\0')
  433. {
  434. strcpy(m_TextBuf,fn);
  435. m_GUICH->SetData("Name",m_TextBuf);
  436. m_GUICH->Set("Num",(int)m_SampleNum->value());
  437. m_GUICH->SetCommand(PoshSamplerPlugin::LOAD);
  438. m_GUICH->Wait(); // wait for the sample to load
  439. UpdateSampleDisplay((int)m_SampleNum->value());
  440. m_Display->redraw();
  441. redraw();
  442. }
  443. }
  444. void PoshSamplerPluginGUI::cb_Load(Fl_Button* o, void* v)
  445. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_Load_i(o,v);}
  446. inline void PoshSamplerPluginGUI::cb_Save_i(Fl_Button* o, void* v)
  447. {
  448. char *fn=fl_file_chooser("Save sample", "{*.wav,*.WAV}", NULL);
  449. if (fn && fn!='\0')
  450. {
  451. strcpy(m_TextBuf,fn);
  452. m_GUICH->Set("Name",m_TextBuf);
  453. m_GUICH->Set("Num",(int)m_SampleNum->value());
  454. m_GUICH->SetCommand(PoshSamplerPlugin::SAVE);
  455. }
  456. }
  457. void PoshSamplerPluginGUI::cb_Save(Fl_Button* o, void* v)
  458. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_Save_i(o,v);}
  459. inline void PoshSamplerPluginGUI::cb_Volume_i(Fl_Knob* o, void* v)
  460. {
  461. m_GUICH->Set("Value",(float)o->value());
  462. m_GUICH->Set("Num",(int)m_SampleNum->value());
  463. m_GUICH->SetCommand(PoshSamplerPlugin::SETVOL);
  464. }
  465. void PoshSamplerPluginGUI::cb_Volume(Fl_Knob* o, void* v)
  466. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_Volume_i(o,v);}
  467. inline void PoshSamplerPluginGUI::cb_Pitch_i(Fl_Knob* o, void* v)
  468. {
  469. m_GUICH->Set("Value",(float)o->value());
  470. m_GUICH->Set("Num",(int)m_SampleNum->value());
  471. m_GUICH->SetCommand(PoshSamplerPlugin::SETPITCH);
  472. }
  473. void PoshSamplerPluginGUI::cb_Pitch(Fl_Knob* o, void* v)
  474. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_Pitch_i(o,v);}
  475. inline void PoshSamplerPluginGUI::cb_Octave_i(Fl_Knob* o, void* v)
  476. {
  477. m_GUICH->Set("Int",(int)o->value());
  478. m_GUICH->Set("Num",(int)m_SampleNum->value());
  479. m_GUICH->SetCommand(PoshSamplerPlugin::SETOCT);
  480. }
  481. void PoshSamplerPluginGUI::cb_Octave(Fl_Knob* o, void* v)
  482. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_Octave_i(o,v);}
  483. inline void PoshSamplerPluginGUI::cb_Loop_i(Fl_Button* o, void* v)
  484. {
  485. m_GUICH->Set("Bool",(bool)o->value());
  486. m_GUICH->Set("Num",(int)m_SampleNum->value());
  487. m_GUICH->SetCommand(PoshSamplerPlugin::SETLOOP);
  488. }
  489. void PoshSamplerPluginGUI::cb_Loop(Fl_Button* o, void* v)
  490. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_Loop_i(o,v);}
  491. inline void PoshSamplerPluginGUI::cb_PingPong_i(Fl_Button* o, void* v)
  492. {
  493. m_GUICH->Set("Bool",(bool)o->value());
  494. m_GUICH->Set("Num",(int)m_SampleNum->value());
  495. m_GUICH->SetCommand(PoshSamplerPlugin::SETPING);
  496. }
  497. void PoshSamplerPluginGUI::cb_PingPong(Fl_Button* o, void* v)
  498. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_PingPong_i(o,v);}
  499. inline void PoshSamplerPluginGUI::cb_Record_i(Fl_Button* o, void* v)
  500. {
  501. m_GUICH->Set("Bool",(bool)o->value());
  502. m_GUICH->SetCommand(PoshSamplerPlugin::SETREC);
  503. redraw();
  504. }
  505. void PoshSamplerPluginGUI::cb_Record(Fl_Button* o, void* v)
  506. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_Record_i(o,v);}
  507. inline void PoshSamplerPluginGUI::cb_PosMarker_i(Fl_Button* o, void* v)
  508. { m_Display->SetPosMarker(o->value()); }
  509. void PoshSamplerPluginGUI::cb_PosMarker(Fl_Button* o, void* v)
  510. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_PosMarker_i(o,v);}
  511. inline void PoshSamplerPluginGUI::cb_Note_i(Fl_Counter* o, void* v)
  512. {
  513. m_GUICH->Set("Int",(int)o->value());
  514. m_GUICH->Set("Num",(int)m_SampleNum->value());
  515. m_GUICH->SetCommand(PoshSamplerPlugin::SETNOTE);
  516. }
  517. void PoshSamplerPluginGUI::cb_Note(Fl_Counter* o, void* v)
  518. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_Note_i(o,v);}
  519. inline void PoshSamplerPluginGUI::cb_SampleNum_i(Fl_Counter* o, void* v)
  520. {
  521. if (m_SampleNum->value()<0) m_SampleNum->value(0);
  522. if (m_SampleNum->value()>7) m_SampleNum->value(7);
  523. m_GUICH->Set("Num",(int)m_SampleNum->value());
  524. m_GUICH->SetCommand(PoshSamplerPlugin::SETCURRENT);
  525. m_GUICH->Wait();
  526. UpdateSampleDisplay((int)m_SampleNum->value());
  527. }
  528. void PoshSamplerPluginGUI::cb_SampleNum(Fl_Counter* o, void* v)
  529. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_SampleNum_i(o,v);}
  530. inline void PoshSamplerPluginGUI::cb_Cut_i(Fl_Button* o, void* v)
  531. {
  532. m_GUICH->Set("Start",(long)m_Display->GetRangeStart());
  533. m_GUICH->Set("End",(long)m_Display->GetRangeEnd());
  534. m_GUICH->Set("Num",(int)m_SampleNum->value());
  535. m_GUICH->SetCommand(PoshSamplerPlugin::CUT);
  536. m_GUICH->Wait();
  537. UpdateSampleDisplay((int)m_SampleNum->value());
  538. m_Display->redraw();
  539. }
  540. void PoshSamplerPluginGUI::cb_Cut(Fl_Button* o, void* v)
  541. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_Cut_i(o,v);}
  542. inline void PoshSamplerPluginGUI::cb_Copy_i(Fl_Button* o, void* v)
  543. {
  544. m_GUICH->Set("Start",(long)m_Display->GetRangeStart());
  545. m_GUICH->Set("End",(long)m_Display->GetRangeEnd());
  546. m_GUICH->Set("Num",(int)m_SampleNum->value());
  547. m_GUICH->SetCommand(PoshSamplerPlugin::COPY);
  548. }
  549. void PoshSamplerPluginGUI::cb_Copy(Fl_Button* o, void* v)
  550. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_Copy_i(o,v);}
  551. inline void PoshSamplerPluginGUI::cb_Paste_i(Fl_Button* o, void* v)
  552. {
  553. m_GUICH->Set("Start",(long)m_Display->GetRangeStart());
  554. m_GUICH->Set("End",(long)m_Display->GetRangeEnd());
  555. m_GUICH->Set("Num",(int)m_SampleNum->value());
  556. m_GUICH->SetCommand(PoshSamplerPlugin::PASTE);
  557. m_GUICH->Wait();
  558. UpdateSampleDisplay((int)m_SampleNum->value());
  559. m_Display->redraw();
  560. }
  561. void PoshSamplerPluginGUI::cb_Paste(Fl_Button* o, void* v)
  562. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_Paste_i(o,v);}
  563. inline void PoshSamplerPluginGUI::cb_Mix_i(Fl_Button* o, void* v)
  564. {
  565. m_GUICH->Set("Start",(long)m_Display->GetRangeStart());
  566. m_GUICH->Set("End",(long)m_Display->GetRangeEnd());
  567. m_GUICH->Set("Num",(int)m_SampleNum->value());
  568. m_GUICH->SetCommand(PoshSamplerPlugin::MIX);
  569. m_GUICH->Wait();
  570. UpdateSampleDisplay((int)m_SampleNum->value());
  571. m_Display->redraw();
  572. }
  573. void PoshSamplerPluginGUI::cb_Mix(Fl_Button* o, void* v)
  574. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_Mix_i(o,v);}
  575. inline void PoshSamplerPluginGUI::cb_Crop_i(Fl_Button* o, void* v)
  576. {
  577. m_GUICH->Set("Start",(long)m_Display->GetRangeStart());
  578. m_GUICH->Set("End",(long)m_Display->GetRangeEnd());
  579. m_GUICH->Set("Num",(int)m_SampleNum->value());
  580. m_GUICH->SetCommand(PoshSamplerPlugin::CROP);
  581. m_GUICH->Wait();
  582. UpdateSampleDisplay((int)m_SampleNum->value());
  583. m_Display->redraw();
  584. }
  585. void PoshSamplerPluginGUI::cb_Crop(Fl_Button* o, void* v)
  586. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_Crop_i(o,v);}
  587. inline void PoshSamplerPluginGUI::cb_Reverse_i(Fl_Button* o, void* v)
  588. {
  589. m_GUICH->Set("Start",(long)m_Display->GetRangeStart());
  590. m_GUICH->Set("End",(long)m_Display->GetRangeEnd());
  591. m_GUICH->Set("Num",(int)m_SampleNum->value());
  592. m_GUICH->SetCommand(PoshSamplerPlugin::REV);
  593. m_GUICH->Wait();
  594. UpdateSampleDisplay((int)m_SampleNum->value());
  595. m_Display->redraw();
  596. }
  597. void PoshSamplerPluginGUI::cb_Reverse(Fl_Button* o, void* v)
  598. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_Reverse_i(o,v);}
  599. inline void PoshSamplerPluginGUI::cb_Amp_i(Fl_Button* o, void* v)
  600. {
  601. m_GUICH->Set("Start",(long)m_Display->GetRangeStart());
  602. m_GUICH->Set("End",(long)m_Display->GetRangeEnd());
  603. m_GUICH->Set("Num",(int)m_SampleNum->value());
  604. m_GUICH->SetCommand(PoshSamplerPlugin::AMP);
  605. m_GUICH->Wait();
  606. UpdateSampleDisplay((int)m_SampleNum->value());
  607. m_Display->redraw();
  608. }
  609. void PoshSamplerPluginGUI::cb_Amp(Fl_Button* o, void* v)
  610. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_Amp_i(o,v);}
  611. inline void PoshSamplerPluginGUI::cb_WaveDisplay_i(Fl_WaveDisplay* o, void* v)
  612. {
  613. m_GUICH->Set("Start",(long)o->GetPlayStart());
  614. m_GUICH->Set("End",(long)o->GetLoopEnd());
  615. m_GUICH->Set("LoopStart",(long)o->GetLoopStart());
  616. m_GUICH->Set("Num",(int)m_SampleNum->value());
  617. m_GUICH->SetCommand(PoshSamplerPlugin::SETPLAYPOINTS);
  618. }
  619. void PoshSamplerPluginGUI::cb_WaveDisplay(Fl_WaveDisplay* o, void* v)
  620. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_WaveDisplay_i(o,v);}
  621. inline void PoshSamplerPluginGUI::cb_ZoomIn_i(Fl_Button* o, void* v)
  622. {
  623. m_Display->ZoomIn();
  624. }
  625. void PoshSamplerPluginGUI::cb_ZoomIn(Fl_Button* o, void* v)
  626. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_ZoomIn_i(o,v);}
  627. inline void PoshSamplerPluginGUI::cb_ZoomOut_i(Fl_Button* o, void* v)
  628. {
  629. m_Display->ZoomOut();
  630. }
  631. void PoshSamplerPluginGUI::cb_ZoomOut(Fl_Button* o, void* v)
  632. { ((PoshSamplerPluginGUI*)(o->parent()))->cb_ZoomOut_i(o,v);}
  633. const string PoshSamplerPluginGUI::GetHelpText(const string &loc){
  634. return string("")
  635. + "A sampler that allows simple sample editing (cut copy paste etc),\n"
  636. + "dirty time stretching (by modulating the start pos + retriggering +\n"
  637. + "modulating pitch) and loop start/end points with ping pong loop mode.\n"
  638. + "Also implementations of controls, such as continuous pitch changing,\n"
  639. + "so you can add portmento to samples, trigger velocity sets sample\n"
  640. + "volume.\n\n"
  641. + "Can records input data too.\n\n"
  642. + "Controls:\n"
  643. + "lmb: Select region\n"
  644. + "mmb: Move view\n"
  645. + "rmb: Draws samples at full zoom.\n\n"
  646. + "Left mouse also drags loop points. The Loop end marker defaults to the\n"
  647. + "end of the sample.\n\n"
  648. + "Note: The loading and saving of samples is not yet realtime safe";
  649. }