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.

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