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.

610 lines
19KB

  1. /*
  2. ==============================================================================
  3. This file was auto-generated!
  4. It contains the basic framework code for a JUCE plugin editor.
  5. ==============================================================================
  6. */
  7. #include "PluginProcessor.h"
  8. #include "PluginEditor.h"
  9. //==============================================================================
  10. PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor (PaulstretchpluginAudioProcessor& p)
  11. : AudioProcessorEditor (&p),
  12. m_wavecomponent(p.m_afm),
  13. processor (p)
  14. {
  15. addAndMakeVisible(&m_import_button);
  16. m_import_button.setButtonText("Import file...");
  17. attachCallback(m_import_button, [this]() { chooseFile(); });
  18. addAndMakeVisible(&m_info_label);
  19. addAndMakeVisible(&m_wavecomponent);
  20. const auto& pars = processor.getParameters();
  21. for (int i=0;i<pars.size();++i)
  22. {
  23. AudioProcessorParameterWithID* parid = dynamic_cast<AudioProcessorParameterWithID*>(pars[i]);
  24. jassert(parid);
  25. if (parid)
  26. {
  27. bool notifyonlyonrelease = false;
  28. if (parid->paramID.startsWith("fftsize"))
  29. notifyonlyonrelease = true;
  30. m_parcomps.push_back(std::make_shared<ParameterComponent>(pars[i],notifyonlyonrelease));
  31. addAndMakeVisible(m_parcomps.back().get());
  32. }
  33. }
  34. //addAndMakeVisible(&m_specvis);
  35. setSize (1000, 30+(pars.size()/2)*25+200);
  36. m_wavecomponent.TimeSelectionChangedCallback = [this](Range<double> range, int which)
  37. {
  38. *processor.getFloatParameter(5) = range.getStart();
  39. *processor.getFloatParameter(6) = range.getEnd();
  40. };
  41. m_wavecomponent.CursorPosCallback = [this]()
  42. {
  43. return processor.getStretchSource()->getInfilePositionPercent();
  44. };
  45. m_wavecomponent.ShowFileCacheRange = true;
  46. m_spec_order_ed.setSource(processor.getStretchSource());
  47. addAndMakeVisible(&m_spec_order_ed);
  48. startTimer(1, 100);
  49. startTimer(2, 1000);
  50. startTimer(3, 200);
  51. m_wavecomponent.startTimer(100);
  52. }
  53. PaulstretchpluginAudioProcessorEditor::~PaulstretchpluginAudioProcessorEditor()
  54. {
  55. }
  56. void PaulstretchpluginAudioProcessorEditor::paint (Graphics& g)
  57. {
  58. g.fillAll(Colours::darkgrey);
  59. }
  60. void PaulstretchpluginAudioProcessorEditor::resized()
  61. {
  62. m_import_button.setBounds(1, 1, 60, 24);
  63. m_import_button.changeWidthToFitText();
  64. m_info_label.setBounds(m_import_button.getRight() + 1, m_import_button.getY(), getWidth()-m_import_button.getRight()-1, 24);
  65. for (int i = 0; i < m_parcomps.size(); ++i)
  66. {
  67. int gridx = i % 2;
  68. int gridy = i / 2;
  69. m_parcomps[i]->setBounds(1+gridx*(getWidth()/2), 30 + gridy * 25, getWidth()/2-2, 24);
  70. }
  71. int yoffs = m_parcomps.back()->getBottom() + 1;
  72. int remain_h = getHeight() - 1 - yoffs;
  73. m_spec_order_ed.setBounds(1, yoffs, getWidth() - 2, remain_h / 5 * 1);
  74. m_wavecomponent.setBounds(1, m_spec_order_ed.getBottom()+1, getWidth()-2, remain_h/5*4);
  75. //m_specvis.setBounds(1, yoffs, getWidth() - 2, getHeight() - 1 - yoffs);
  76. }
  77. void PaulstretchpluginAudioProcessorEditor::timerCallback(int id)
  78. {
  79. if (id == 1)
  80. {
  81. for (auto& e : m_parcomps)
  82. e->updateComponent();
  83. if (processor.isRecordingEnabled())
  84. {
  85. m_wavecomponent.setRecordingPosition(processor.getRecordingPositionPercent());
  86. } else
  87. m_wavecomponent.setRecordingPosition(-1.0);
  88. String infotext = String(processor.getPreBufferingPercent(), 1) + " " + String(processor.getStretchSource()->m_param_change_count);
  89. m_info_label.setText(infotext, dontSendNotification);
  90. }
  91. if (id == 2)
  92. {
  93. if (processor.getAudioFile() != File() && processor.getAudioFile() != m_wavecomponent.getAudioFile())
  94. {
  95. m_wavecomponent.setAudioFile(processor.getAudioFile());
  96. }
  97. if (processor.getAudioFile()==File() && processor.isRecordingEnabled()==false && m_wavecomponent.isUsingAudioBuffer()==false)
  98. {
  99. auto bufptr = processor.getStretchSource()->getSourceAudioBuffer();
  100. if (bufptr!=nullptr)
  101. m_wavecomponent.setAudioBuffer(bufptr,
  102. processor.getSampleRate(), bufptr->getNumSamples());
  103. }
  104. m_wavecomponent.setTimeSelection(processor.getTimeSelection());
  105. }
  106. if (id == 3)
  107. {
  108. //m_specvis.setState(processor.getStretchSource()->getProcessParameters(), processor.getStretchSource()->getFFTSize() / 2,
  109. // processor.getSampleRate());
  110. }
  111. }
  112. void PaulstretchpluginAudioProcessorEditor::setAudioFile(File f)
  113. {
  114. m_wavecomponent.setAudioFile(f);
  115. }
  116. void PaulstretchpluginAudioProcessorEditor::setAudioBuffer(AudioBuffer<float>* buf, int samplerate, int len)
  117. {
  118. MessageManager::callAsync([this,buf, samplerate, len]()
  119. {
  120. m_wavecomponent.setAudioBuffer(buf, samplerate, len);
  121. });
  122. }
  123. void PaulstretchpluginAudioProcessorEditor::beginAddingAudioBlocks(int channels, int samplerate, int totalllen)
  124. {
  125. m_wavecomponent.beginAddingAudioBlocks(channels, samplerate, totalllen);
  126. }
  127. void PaulstretchpluginAudioProcessorEditor::addAudioBlock(AudioBuffer<float>& buf, int samplerate, int pos)
  128. {
  129. m_wavecomponent.addAudioBlock(buf, samplerate, pos);
  130. }
  131. void PaulstretchpluginAudioProcessorEditor::chooseFile()
  132. {
  133. #ifdef WIN32
  134. File initialloc("C:/MusicAudio/sourcesamples");
  135. #else
  136. File initialloc("/Users/teemu/AudioProjects/sourcesamples");
  137. #endif
  138. FileChooser myChooser("Please select audio file...",
  139. initialloc,
  140. "*.wav");
  141. if (myChooser.browseForFileToOpen())
  142. {
  143. processor.setAudioFile(myChooser.getResult());
  144. if (processor.getAudioFile() != File())
  145. {
  146. m_wavecomponent.setAudioFile(processor.getAudioFile());
  147. }
  148. }
  149. }
  150. WaveformComponent::WaveformComponent(AudioFormatManager* afm)
  151. {
  152. TimeSelectionChangedCallback = [](Range<double>, int) {};
  153. if (m_use_opengl == true)
  154. m_ogl.attachTo(*this);
  155. // The default priority of 2 is a bit too low in some cases, it seems...
  156. m_thumbcache->getTimeSliceThread().setPriority(3);
  157. m_thumb = std::make_unique<AudioThumbnail>(512, *afm, *m_thumbcache);
  158. m_thumb->addChangeListener(this);
  159. setOpaque(true);
  160. }
  161. WaveformComponent::~WaveformComponent()
  162. {
  163. if (m_use_opengl == true)
  164. m_ogl.detach();
  165. }
  166. void WaveformComponent::changeListenerCallback(ChangeBroadcaster * /*cb*/)
  167. {
  168. m_waveimage = Image();
  169. repaint();
  170. }
  171. void WaveformComponent::paint(Graphics & g)
  172. {
  173. //Logger::writeToLog("Waveform component paint");
  174. g.fillAll(Colours::black);
  175. g.setColour(Colours::darkgrey);
  176. g.fillRect(0, 0, getWidth(), m_topmargin);
  177. if (m_thumb == nullptr || m_thumb->getTotalLength() < 0.1)
  178. {
  179. g.setColour(Colours::aqua.darker());
  180. g.drawText("No file loaded", 2, m_topmargin + 2, getWidth(), 20, Justification::topLeft);
  181. return;
  182. }
  183. g.setColour(Colours::lightslategrey);
  184. double thumblen = m_thumb->getTotalLength();
  185. double tick_interval = 1.0;
  186. if (thumblen > 60.0)
  187. tick_interval = 5.0;
  188. for (double secs = 0.0; secs < thumblen; secs += tick_interval)
  189. {
  190. float tickxcor = (float)jmap<double>(secs,
  191. thumblen*m_view_range.getStart(), thumblen*m_view_range.getEnd(), 0.0f, (float)getWidth());
  192. g.drawLine(tickxcor, 0.0, tickxcor, (float)m_topmargin, 1.0f);
  193. }
  194. bool m_use_cached_image = true;
  195. if (m_use_cached_image == true)
  196. {
  197. if (m_waveimage.isValid() == false || m_waveimage.getWidth() != getWidth()
  198. || m_waveimage.getHeight() != getHeight() - m_topmargin)
  199. {
  200. //Logger::writeToLog("updating cached waveform image");
  201. m_waveimage = Image(Image::ARGB, getWidth(), getHeight() - m_topmargin, true);
  202. Graphics tempg(m_waveimage);
  203. tempg.fillAll(Colours::black);
  204. tempg.setColour(Colours::darkgrey);
  205. m_thumb->drawChannels(tempg, { 0,0,getWidth(),getHeight() - m_topmargin },
  206. thumblen*m_view_range.getStart(), thumblen*m_view_range.getEnd(), 1.0f);
  207. }
  208. g.drawImage(m_waveimage, 0, m_topmargin, getWidth(), getHeight() - m_topmargin, 0, 0, getWidth(), getHeight() - m_topmargin);
  209. }
  210. else
  211. {
  212. //g.fillAll(Colours::black);
  213. g.setColour(Colours::darkgrey);
  214. m_thumb->drawChannels(g, { 0,m_topmargin,getWidth(),getHeight() - m_topmargin },
  215. thumblen*m_view_range.getStart(), thumblen*m_view_range.getEnd(), 1.0f);
  216. }
  217. //g.setColour(Colours::darkgrey);
  218. //m_thumb->drawChannels(g, { 0,m_topmargin,getWidth(),getHeight()-m_topmargin },
  219. // 0.0, thumblen, 1.0f);
  220. g.setColour(Colours::white.withAlpha(0.5f));
  221. int xcorleft = (int)jmap<double>(m_time_sel_start, m_view_range.getStart(), m_view_range.getEnd(), 0, getWidth());
  222. int xcorright = (int)jmap<double>(m_time_sel_end, m_view_range.getStart(), m_view_range.getEnd(), 0, getWidth());
  223. g.fillRect(xcorleft, m_topmargin, xcorright - xcorleft, getHeight() - m_topmargin);
  224. if (m_file_cached.first.getLength() > 0.0 &&
  225. (bool)ShowFileCacheRange.getValue())
  226. {
  227. g.setColour(Colours::red.withAlpha(0.2f));
  228. xcorleft = (int)jmap<double>(m_file_cached.first.getStart(), m_view_range.getStart(), m_view_range.getEnd(), 0, getWidth());
  229. xcorright = (int)jmap<double>(m_file_cached.first.getEnd(), m_view_range.getStart(), m_view_range.getEnd(), 0, getWidth());
  230. g.fillRect(xcorleft, 0, xcorright - xcorleft, m_topmargin / 2);
  231. xcorleft = (int)jmap<double>(m_file_cached.second.getStart(), m_view_range.getStart(), m_view_range.getEnd(), 0, getWidth());
  232. xcorright = (int)jmap<double>(m_file_cached.second.getEnd(), m_view_range.getStart(), m_view_range.getEnd(), 0, getWidth());
  233. if (xcorright - xcorleft>0)
  234. {
  235. g.setColour(Colours::blue.withAlpha(0.2f));
  236. g.fillRect(xcorleft, m_topmargin / 2, xcorright - xcorleft, m_topmargin / 2);
  237. }
  238. }
  239. g.setColour(Colours::white);
  240. if (CursorPosCallback)
  241. {
  242. double pos = jmap<double>(CursorPosCallback(), m_view_range.getStart(), m_view_range.getEnd(), 0, getWidth());
  243. g.fillRect((int)pos, m_topmargin, 1, getHeight() - m_topmargin);
  244. }
  245. if (m_rec_pos >= 0.0)
  246. {
  247. g.setColour(Colours::lightpink);
  248. double pos = jmap<double>(m_rec_pos, m_view_range.getStart(), m_view_range.getEnd(), 0, getWidth());
  249. g.fillRect((int)pos, m_topmargin, 1, getHeight() - m_topmargin);
  250. }
  251. g.setColour(Colours::aqua.darker());
  252. g.drawText(m_curfile.getFullPathName(), 2, m_topmargin + 2, getWidth(), 20, Justification::topLeft);
  253. }
  254. void WaveformComponent::setAudioFile(File f)
  255. {
  256. if (f.existsAsFile())
  257. {
  258. m_waveimage = Image();
  259. if (m_thumb != nullptr && f == m_curfile) // reloading same file, might happen that the overview needs to be redone...
  260. m_thumbcache->removeThumb(m_thumb->getHashCode());
  261. if (m_thumb != nullptr)
  262. m_thumb->reset(0, 0.0);
  263. m_thumb->setSource(new FileInputSource(f));
  264. m_curfile = f;
  265. m_using_audio_buffer = false;
  266. }
  267. else
  268. {
  269. m_thumb->setSource(nullptr);
  270. m_curfile = File();
  271. }
  272. repaint();
  273. }
  274. void WaveformComponent::setAudioBuffer(AudioBuffer<float>* buf, int samplerate, int len)
  275. {
  276. jassert(buf!=nullptr);
  277. m_using_audio_buffer = true;
  278. m_waveimage = Image();
  279. m_curfile = File();
  280. m_thumb->reset(buf->getNumChannels(), samplerate, len);
  281. m_thumb->addBlock(0, *buf, 0, len);
  282. }
  283. void WaveformComponent::beginAddingAudioBlocks(int channels, int samplerate, int totalllen)
  284. {
  285. m_waveimage = Image();
  286. m_curfile = File();
  287. m_thumb->reset(channels, samplerate, totalllen);
  288. }
  289. void WaveformComponent::addAudioBlock(AudioBuffer<float>& buf, int samplerate, int pos)
  290. {
  291. m_thumb->addBlock(pos, buf, 0, buf.getNumSamples());
  292. }
  293. void WaveformComponent::timerCallback()
  294. {
  295. repaint();
  296. }
  297. void WaveformComponent::setFileCachedRange(std::pair<Range<double>, Range<double>> rng)
  298. {
  299. m_file_cached = rng;
  300. //repaint();
  301. }
  302. void WaveformComponent::setTimerEnabled(bool b)
  303. {
  304. if (b == true)
  305. startTimer(100);
  306. else
  307. stopTimer();
  308. }
  309. void WaveformComponent::setViewRange(Range<double> rng)
  310. {
  311. m_view_range = rng;
  312. m_waveimage = Image();
  313. repaint();
  314. }
  315. void WaveformComponent::mouseDown(const MouseEvent & e)
  316. {
  317. m_mousedown = true;
  318. m_lock_timesel_set = true;
  319. double pos = jmap<double>(e.x, 0, getWidth(), m_view_range.getStart(), m_view_range.getEnd());
  320. if (e.y < m_topmargin)
  321. {
  322. if (SeekCallback)
  323. SeekCallback(pos);
  324. m_didseek = true;
  325. }
  326. else
  327. {
  328. m_time_sel_drag_target = getTimeSelectionEdge(e.x, e.y);
  329. m_drag_time_start = pos;
  330. if (m_time_sel_drag_target == 0)
  331. {
  332. m_time_sel_start = -1.0;
  333. m_time_sel_end = -1.0;
  334. }
  335. }
  336. repaint();
  337. }
  338. void WaveformComponent::mouseUp(const MouseEvent & /*e*/)
  339. {
  340. m_lock_timesel_set = false;
  341. m_mousedown = false;
  342. m_didseek = false;
  343. if (m_didchangetimeselection)
  344. {
  345. TimeSelectionChangedCallback(Range<double>(m_time_sel_start, m_time_sel_end), 1);
  346. m_didchangetimeselection = false;
  347. }
  348. }
  349. void WaveformComponent::mouseDrag(const MouseEvent & e)
  350. {
  351. if (m_didseek == true)
  352. return;
  353. if (m_time_sel_drag_target == 0)
  354. {
  355. m_time_sel_start = m_drag_time_start;
  356. m_time_sel_end = jmap<double>(e.x, 0, getWidth(), m_view_range.getStart(), m_view_range.getEnd());
  357. }
  358. if (m_time_sel_drag_target == 1)
  359. {
  360. m_time_sel_start = jmap<double>(e.x, 0, getWidth(), m_view_range.getStart(), m_view_range.getEnd());
  361. }
  362. if (m_time_sel_drag_target == 2)
  363. {
  364. m_time_sel_end = jmap<double>(e.x, 0, getWidth(), m_view_range.getStart(), m_view_range.getEnd());
  365. }
  366. if (m_time_sel_start > m_time_sel_end)
  367. {
  368. std::swap(m_time_sel_start, m_time_sel_end);
  369. if (m_time_sel_drag_target == 1)
  370. m_time_sel_drag_target = 2;
  371. else if (m_time_sel_drag_target == 2)
  372. m_time_sel_drag_target = 1;
  373. }
  374. m_time_sel_start = jlimit(0.0, 1.0, m_time_sel_start);
  375. m_time_sel_end = jlimit(0.0, 1.0, m_time_sel_end);
  376. if (TimeSelectionChangedCallback)
  377. {
  378. if (m_time_sel_end>m_time_sel_start)
  379. TimeSelectionChangedCallback(Range<double>(m_time_sel_start, m_time_sel_end), 0);
  380. else
  381. TimeSelectionChangedCallback(Range<double>(0.0, 1.0), 0);
  382. }
  383. m_didchangetimeselection = true;
  384. repaint();
  385. }
  386. void WaveformComponent::mouseMove(const MouseEvent & e)
  387. {
  388. m_time_sel_drag_target = getTimeSelectionEdge(e.x, e.y);
  389. if (m_time_sel_drag_target == 0)
  390. setMouseCursor(MouseCursor::NormalCursor);
  391. if (m_time_sel_drag_target == 1)
  392. setMouseCursor(MouseCursor::LeftRightResizeCursor);
  393. if (m_time_sel_drag_target == 2)
  394. setMouseCursor(MouseCursor::LeftRightResizeCursor);
  395. }
  396. int WaveformComponent::getTimeSelectionEdge(int x, int y)
  397. {
  398. int xcorleft = (int)jmap<double>(m_time_sel_start, m_view_range.getStart(), m_view_range.getEnd(), 0, getWidth());
  399. int xcorright = (int)jmap<double>(m_time_sel_end, m_view_range.getStart(), m_view_range.getEnd(), 0, getWidth());
  400. if (juce::Rectangle<int>(xcorleft - 5, m_topmargin, 10, getHeight() - m_topmargin).contains(x, y))
  401. return 1;
  402. if (juce::Rectangle<int>(xcorright - 5, m_topmargin, 10, getHeight() - m_topmargin).contains(x, y))
  403. return 2;
  404. return 0;
  405. }
  406. SpectralVisualizer::SpectralVisualizer()
  407. {
  408. m_img = Image(Image::RGB, 500, 200, true);
  409. }
  410. void SpectralVisualizer::setState(const ProcessParameters & pars, int nfreqs, double samplerate)
  411. {
  412. double t0 = Time::getMillisecondCounterHiRes();
  413. double hz = 440.0;
  414. int numharmonics = 40;
  415. double scaler = 1.0 / numharmonics;
  416. if (m_img.getWidth()!=getWidth() || m_img.getHeight()!=getHeight())
  417. m_img = Image(Image::RGB, getWidth(), getHeight(), true);
  418. if (m_nfreqs == 0 || nfreqs != m_nfreqs)
  419. {
  420. m_nfreqs = nfreqs;
  421. m_insamples = std::vector<REALTYPE>(nfreqs * 2);
  422. m_freqs1 = std::vector<REALTYPE>(nfreqs);
  423. m_freqs2 = std::vector<REALTYPE>(nfreqs);
  424. m_freqs3 = std::vector<REALTYPE>(nfreqs);
  425. m_fft = std::make_unique<FFT>(nfreqs*2);
  426. std::fill(m_insamples.begin(), m_insamples.end(), 0.0f);
  427. for (int i = 0; i < nfreqs; ++i)
  428. {
  429. for (int j = 0; j < numharmonics; ++j)
  430. {
  431. double oscgain = 1.0 - (1.0 / numharmonics)*j;
  432. m_insamples[i] += scaler * oscgain * sin(2 * 3.141592653 / samplerate * i* (hz + hz * j));
  433. }
  434. }
  435. }
  436. //std::fill(m_freqs1.begin(), m_freqs1.end(), 0.0f);
  437. //std::fill(m_freqs2.begin(), m_freqs2.end(), 0.0f);
  438. //std::fill(m_freqs3.begin(), m_freqs3.end(), 0.0f);
  439. //std::fill(m_fft->freq.begin(), m_fft->freq.end(), 0.0f);
  440. for (int i = 0; i < nfreqs; ++i)
  441. {
  442. m_fft->smp[i] = m_insamples[i];
  443. }
  444. m_fft->applywindow(W_HAMMING);
  445. m_fft->smp2freq();
  446. double ratio = pow(2.0f, pars.pitch_shift.cents / 1200.0f);
  447. spectrum_do_pitch_shift(pars, nfreqs, m_fft->freq.data(), m_freqs2.data(), ratio);
  448. spectrum_do_freq_shift(pars, nfreqs, samplerate, m_freqs2.data(), m_freqs1.data());
  449. spectrum_do_compressor(pars, nfreqs, m_freqs1.data(), m_freqs2.data());
  450. spectrum_spread(nfreqs, samplerate, m_freqs3, m_freqs2.data(), m_freqs1.data(), pars.spread.bandwidth);
  451. if (pars.harmonics.enabled)
  452. spectrum_do_harmonics(pars, m_freqs3, nfreqs, samplerate, m_freqs1.data(), m_freqs2.data());
  453. else spectrum_copy(nfreqs, m_freqs1.data(), m_freqs2.data());
  454. Graphics g(m_img);
  455. g.fillAll(Colours::black);
  456. g.setColour(Colours::white);
  457. for (int i = 0; i < nfreqs; ++i)
  458. {
  459. double binfreq = (samplerate / 2 / nfreqs)*i;
  460. double xcor = jmap<double>(binfreq, 0.0, samplerate / 2.0, 0.0, getWidth());
  461. double ycor = getHeight()- jmap<double>(m_freqs2[i], 0.0, nfreqs/128, 0.0, getHeight());
  462. ycor = jlimit<double>(0.0, getHeight(), ycor);
  463. g.drawLine(xcor, getHeight(), xcor, ycor, 1.0);
  464. }
  465. double t1 = Time::getMillisecondCounterHiRes();
  466. m_elapsed = t1 - t0;
  467. repaint();
  468. }
  469. void SpectralVisualizer::paint(Graphics & g)
  470. {
  471. g.drawImage(m_img, 0, 0, getWidth(), getHeight(), 0, 0, m_img.getWidth(), m_img.getHeight());
  472. g.setColour(Colours::yellow);
  473. g.drawText(String(m_elapsed, 1)+" ms", 1, 1, getWidth(), 30, Justification::topLeft);
  474. }
  475. void SpectralChainEditor::paint(Graphics & g)
  476. {
  477. g.fillAll(Colours::black);
  478. if (m_src == nullptr)
  479. return;
  480. int box_w = getWidth() / m_order.size();
  481. int box_h = getHeight();
  482. for (int i = 0; i < m_order.size(); ++i)
  483. {
  484. //if (i!=m_cur_index)
  485. drawBox(g, i, i*box_w, 0, box_w - 30, box_h);
  486. if (i<m_order.size() - 1)
  487. g.drawArrow(juce::Line<float>(i*box_w + (box_w - 30), box_h / 2, i*box_w + box_w, box_h / 2), 2.0f, 15.0f, 15.0f);
  488. }
  489. if (m_drag_x>=0 && m_drag_x<getWidth() && m_cur_index>=0)
  490. drawBox(g, m_cur_index, m_drag_x, 0, box_w - 30, box_h);
  491. }
  492. void SpectralChainEditor::mouseDown(const MouseEvent & ev)
  493. {
  494. m_did_drag = false;
  495. int box_w = getWidth() / m_order.size();
  496. int box_h = getHeight();
  497. m_cur_index = ev.x / box_w;
  498. m_drag_x = -1;
  499. repaint();
  500. }
  501. void SpectralChainEditor::mouseDrag(const MouseEvent & ev)
  502. {
  503. if (m_cur_index >= 0 && m_cur_index < m_order.size())
  504. {
  505. int box_w = getWidth() / m_order.size();
  506. int box_h = getHeight();
  507. int new_index = ev.x / box_w;
  508. if (new_index >= 0 && new_index < m_order.size() && new_index != m_cur_index)
  509. {
  510. std::swap(m_order[m_cur_index], m_order[new_index]);
  511. m_cur_index = new_index;
  512. m_did_drag = true;
  513. m_src->setSpectrumProcessOrder(m_order);
  514. }
  515. m_drag_x = ev.x;
  516. repaint();
  517. }
  518. }
  519. void SpectralChainEditor::mouseUp(const MouseEvent & ev)
  520. {
  521. m_drag_x = -1;
  522. //m_cur_index = -1;
  523. repaint();
  524. }
  525. void SpectralChainEditor::drawBox(Graphics & g, int index, int x, int y, int w, int h)
  526. {
  527. String txt;
  528. if (m_order[index] == 0)
  529. txt = "Harmonics";
  530. if (m_order[index] == 1)
  531. txt = "Tonal vs Noise";
  532. if (m_order[index] == 2)
  533. txt = "Frequency shift";
  534. if (m_order[index] == 3)
  535. txt = "Pitch shift";
  536. if (m_order[index] == 4)
  537. txt = "Octaves";
  538. if (m_order[index] == 5)
  539. txt = "Spread";
  540. if (m_order[index] == 6)
  541. txt = "Filter";
  542. if (m_order[index] == 7)
  543. txt = "Compressor";
  544. if (index == m_cur_index)
  545. {
  546. g.setColour(Colours::darkgrey);
  547. //g.fillRect(i*box_w, 0, box_w - 30, box_h - 1);
  548. g.fillRect(x, y, w, h);
  549. }
  550. g.setColour(Colours::white);
  551. g.drawRect(x, y, w, h);
  552. g.drawFittedText(txt, x,y,w,h, Justification::centred, 3);
  553. }