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.

696 lines
20KB

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