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.

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