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.

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