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.

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