FinishDock.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. #include "ui/FinishDock.h"
  2. #include <cmath>
  3. #include <thread>
  4. #include "core/MasterLooks.h"
  5. #include "core/Mastering.h"
  6. #include "engine/AudioEngine.h"
  7. #include "engine/Exporter.h"
  8. #include "ui/I18n.h"
  9. #include "ui/Theme.h"
  10. namespace lynx
  11. {
  12. namespace
  13. {
  14. // --- each look's picture: LYNX's own simple line drawing in a 1×1 box -------------------------------------------------
  15. juce::Path lookGlyph (int id)
  16. {
  17. juce::Path p;
  18. switch (id)
  19. {
  20. case looks::balanced: // a level with two even pans
  21. p.startNewSubPath (0.5f, 0.12f); p.lineTo (0.5f, 0.88f);
  22. p.startNewSubPath (0.12f, 0.3f); p.lineTo (0.88f, 0.3f);
  23. p.addArc (0.06f, 0.3f, 0.26f, 0.26f, juce::MathConstants<float>::halfPi, juce::MathConstants<float>::halfPi * 3.0f, true);
  24. p.addArc (0.68f, 0.3f, 0.26f, 0.26f, juce::MathConstants<float>::halfPi, juce::MathConstants<float>::halfPi * 3.0f, true);
  25. p.startNewSubPath (0.3f, 0.88f); p.lineTo (0.7f, 0.88f);
  26. break;
  27. case looks::loud: // a meter in the red
  28. for (int i = 0; i < 5; ++i)
  29. {
  30. const auto x = 0.14f + 0.16f * (float) i, h = 0.18f + 0.15f * (float) i;
  31. p.addRoundedRectangle (x, 0.88f - h, 0.1f, h, 0.02f);
  32. }
  33. break;
  34. case looks::clarity: // a diamond with sparkles
  35. p.startNewSubPath (0.42f, 0.2f); p.lineTo (0.72f, 0.5f); p.lineTo (0.42f, 0.86f); p.lineTo (0.12f, 0.5f); p.closeSubPath();
  36. p.startNewSubPath (0.82f, 0.1f); p.lineTo (0.82f, 0.3f);
  37. p.startNewSubPath (0.72f, 0.2f); p.lineTo (0.92f, 0.2f);
  38. break;
  39. case looks::warmTape: // a cassette
  40. p.addRoundedRectangle (0.08f, 0.24f, 0.84f, 0.56f, 0.06f);
  41. p.addEllipse (0.24f, 0.4f, 0.16f, 0.16f);
  42. p.addEllipse (0.6f, 0.4f, 0.16f, 0.16f);
  43. p.startNewSubPath (0.32f, 0.4f); p.lineTo (0.68f, 0.4f);
  44. break;
  45. case looks::gentle: // a soft wave
  46. p.startNewSubPath (0.08f, 0.5f);
  47. p.cubicTo (0.25f, 0.25f, 0.4f, 0.25f, 0.5f, 0.5f);
  48. p.cubicTo (0.6f, 0.75f, 0.75f, 0.75f, 0.92f, 0.5f);
  49. break;
  50. case looks::punchy: // a burst
  51. for (int i = 0; i < 8; ++i)
  52. {
  53. const auto a = juce::MathConstants<float>::twoPi * (float) i / 8.0f;
  54. const auto r0 = 0.16f, r1 = i % 2 == 0 ? 0.42f : 0.3f;
  55. p.startNewSubPath (0.5f + r0 * std::cos (a), 0.5f + r0 * std::sin (a));
  56. p.lineTo (0.5f + r1 * std::cos (a), 0.5f + r1 * std::sin (a));
  57. }
  58. break;
  59. case looks::wide: // arrows out
  60. p.startNewSubPath (0.1f, 0.5f); p.lineTo (0.9f, 0.5f);
  61. p.startNewSubPath (0.24f, 0.36f); p.lineTo (0.1f, 0.5f); p.lineTo (0.24f, 0.64f);
  62. p.startNewSubPath (0.76f, 0.36f); p.lineTo (0.9f, 0.5f); p.lineTo (0.76f, 0.64f);
  63. p.startNewSubPath (0.5f, 0.3f); p.lineTo (0.5f, 0.7f);
  64. break;
  65. case looks::cinematic: // a film frame
  66. p.addRoundedRectangle (0.1f, 0.22f, 0.8f, 0.56f, 0.04f);
  67. for (int i = 0; i < 4; ++i)
  68. {
  69. p.addRectangle (0.18f + 0.18f * (float) i, 0.27f, 0.08f, 0.06f);
  70. p.addRectangle (0.18f + 0.18f * (float) i, 0.67f, 0.08f, 0.06f);
  71. }
  72. break;
  73. default: break;
  74. }
  75. return p;
  76. }
  77. juce::String percent (float v) { return juce::String (juce::roundToInt (v * 100.0f)) + " %"; }
  78. juce::String db (float v) { return (v > 0.0f ? "+" : "") + juce::String (v, 1) + " dB"; }
  79. } // namespace
  80. class FinishDock::LookTile final : public juce::Component,
  81. public juce::SettableTooltipClient
  82. {
  83. public:
  84. LookTile (int i) : id (i)
  85. {
  86. setWantsKeyboardFocus (true);
  87. setMouseCursor (juce::MouseCursor::PointingHandCursor);
  88. setTitle (tr (looks::name (id)));
  89. setTooltip (tr (looks::description (id)));
  90. }
  91. std::function<void()> onClick;
  92. bool selected = false;
  93. void paint (juce::Graphics& g) override
  94. {
  95. auto r = getLocalBounds().toFloat().reduced (2.0f);
  96. const auto hover = isMouseOver (true);
  97. g.setColour (selected ? theme::colour::bg5 : hover ? theme::colour::bg4 : theme::colour::bg3);
  98. g.fillRoundedRectangle (r, theme::radius::lg);
  99. g.setColour (selected || hasKeyboardFocus (false) ? theme::colour::accent : hover ? theme::colour::borderStrong : theme::colour::border);
  100. g.drawRoundedRectangle (r.reduced (0.5f), theme::radius::lg, selected ? 1.5f : 1.0f);
  101. const auto side = juce::jmin (28.0f, r.getHeight() - 26.0f);
  102. const juce::Rectangle<float> box (r.getCentreX() - side / 2.0f, r.getY() + 8.0f, side, side);
  103. auto glyph = lookGlyph (id);
  104. glyph.applyTransform (juce::AffineTransform::scale (side).translated (box.getX(), box.getY()));
  105. g.setColour (selected ? theme::colour::accent : theme::colour::textSecondary);
  106. g.strokePath (glyph, juce::PathStrokeType (1.6f, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));
  107. g.setColour (selected ? theme::colour::textPrimary : theme::colour::textSecondary);
  108. g.setFont (theme::font (theme::type::body, selected));
  109. g.drawFittedText (tr (looks::name (id)), getLocalBounds().removeFromBottom (24).reduced (4, 0), juce::Justification::centred, 1, 0.8f);
  110. }
  111. void mouseEnter (const juce::MouseEvent&) override { repaint(); }
  112. void mouseExit (const juce::MouseEvent&) override { repaint(); }
  113. void mouseUp (const juce::MouseEvent& e) override
  114. {
  115. if (e.mouseWasClicked() && getLocalBounds().contains (e.getPosition()) && onClick)
  116. onClick();
  117. }
  118. bool keyPressed (const juce::KeyPress& key) override
  119. {
  120. if ((key == juce::KeyPress::returnKey || key == juce::KeyPress::spaceKey) && onClick)
  121. {
  122. onClick();
  123. return true;
  124. }
  125. return false;
  126. }
  127. void focusGained (FocusChangeType) override { repaint(); }
  128. void focusLost (FocusChangeType) override { repaint(); }
  129. private:
  130. int id;
  131. };
  132. // "Save the song as a file": one row per format — its name, what it is good for, and about how big the file will be
  133. class FinishDock::SaveRow final : public juce::Component,
  134. public juce::SettableTooltipClient
  135. {
  136. public:
  137. SaveRow (juce::String n, juce::String h) : name (std::move (n)), help (std::move (h))
  138. {
  139. setWantsKeyboardFocus (true);
  140. setMouseCursor (juce::MouseCursor::PointingHandCursor);
  141. setTitle (name);
  142. setDescription (help);
  143. }
  144. std::function<void()> onClick;
  145. void setSize (const juce::String& text)
  146. {
  147. if (size != text)
  148. {
  149. size = text;
  150. repaint();
  151. }
  152. }
  153. void paint (juce::Graphics& g) override
  154. {
  155. auto r = getLocalBounds().toFloat().reduced (1.0f);
  156. const auto hover = isMouseOver (true), down = isMouseButtonDown();
  157. g.setColour (down ? theme::colour::bg5 : hover ? theme::colour::bg4 : theme::colour::bg3);
  158. g.fillRoundedRectangle (r, theme::radius::md);
  159. g.setColour (hasKeyboardFocus (false) ? theme::colour::accent : hover ? theme::colour::borderStrong : theme::colour::border);
  160. g.drawRoundedRectangle (r.reduced (0.5f), theme::radius::md, 1.0f);
  161. auto text = getLocalBounds().reduced (10, 0);
  162. g.setColour (theme::colour::textPrimary);
  163. g.setFont (theme::font (theme::type::body, true));
  164. g.drawText (name, text.removeFromLeft (40), juce::Justification::centredLeft, false);
  165. g.setColour (theme::colour::textSecondary);
  166. g.setFont (theme::font (theme::type::small));
  167. g.drawText (size, text.removeFromRight (64), juce::Justification::centredRight, false);
  168. g.drawFittedText (help, text, juce::Justification::centredLeft, 1, 0.75f);
  169. }
  170. void mouseEnter (const juce::MouseEvent&) override { repaint(); }
  171. void mouseExit (const juce::MouseEvent&) override { repaint(); }
  172. void mouseDown (const juce::MouseEvent&) override { repaint(); }
  173. void mouseUp (const juce::MouseEvent& e) override
  174. {
  175. repaint();
  176. if (e.mouseWasClicked() && getLocalBounds().contains (e.getPosition()) && onClick)
  177. onClick();
  178. }
  179. bool keyPressed (const juce::KeyPress& key) override
  180. {
  181. if ((key == juce::KeyPress::returnKey || key == juce::KeyPress::spaceKey) && onClick)
  182. {
  183. onClick();
  184. return true;
  185. }
  186. return false;
  187. }
  188. void focusGained (FocusChangeType) override { repaint(); }
  189. void focusLost (FocusChangeType) override { repaint(); }
  190. private:
  191. juce::String name, help, size;
  192. };
  193. FinishDock::FinishDock (AudioEngine& e, std::function<void()> close, Saving s)
  194. : engine (e), onClose (std::move (close)), saving (std::move (s)), measuring (std::make_shared<std::atomic<int>> (0)),
  195. measuredLufs (std::make_shared<std::atomic<float>> (0.0f))
  196. {
  197. setTitle (tr ("Master looks"));
  198. title.setText (tr ("Master looks"), juce::dontSendNotification);
  199. title.setFont (theme::font (theme::type::title, true));
  200. addAndMakeVisible (title);
  201. status.setFont (theme::font (theme::type::small));
  202. status.setColour (juce::Label::textColourId, theme::colour::textSecondary);
  203. addAndMakeVisible (status);
  204. closeButton.setButtonText (juce::String::fromUTF8 ("\xc3\x97"));
  205. closeButton.setTooltip (tr ("Close"));
  206. closeButton.onClick = [this] {
  207. if (onClose)
  208. onClose();
  209. };
  210. addAndMakeVisible (closeButton);
  211. hearWithout.setButtonText (tr ("Hear without"));
  212. hearWithout.setTooltip (tr ("Switches the look off and on, to compare (A/B)"));
  213. hearWithout.setClickingTogglesState (true);
  214. hearWithout.onClick = [this] {
  215. if (updating)
  216. return;
  217. const auto off = hearWithout.getToggleState();
  218. engine.editSong ([off] (Song& s) { looks::setBypassed (s, off); });
  219. };
  220. addAndMakeVisible (hearWithout);
  221. for (int i = 0; i < looks::count; ++i)
  222. {
  223. tiles[i] = std::make_unique<LookTile> (i + 1);
  224. tiles[i]->onClick = [this, id = i + 1] { choose (id); };
  225. addAndMakeVisible (*tiles[i]);
  226. }
  227. intensityLabel.setText (tr ("Intensity"), juce::dontSendNotification);
  228. intensityLabel.setFont (theme::font (theme::type::body, true));
  229. addAndMakeVisible (intensityLabel);
  230. intensity.setSliderStyle (juce::Slider::LinearHorizontal);
  231. intensity.setTextBoxStyle (juce::Slider::NoTextBox, false, 0, 0);
  232. intensity.setRange (0.0, 1.0, 0.01);
  233. intensity.setDoubleClickReturnValue (true, 0.5);
  234. intensity.textFromValueFunction = [] (double v) { return percent ((float) v); };
  235. intensity.setPopupDisplayEnabled (true, false, this);
  236. intensity.onValueChange = [this] { changed (false); };
  237. addAndMakeVisible (intensity);
  238. const char* markNames[3] { "Light", "Normal", "Heavy" };
  239. for (int i = 0; i < 3; ++i)
  240. {
  241. marks[i].setText (tr (markNames[i]), juce::dontSendNotification);
  242. marks[i].setFont (theme::font (theme::type::small));
  243. marks[i].setColour (juce::Label::textColourId, theme::colour::textSecondary);
  244. marks[i].setJustificationType (juce::Justification::centred);
  245. addAndMakeVisible (marks[i]);
  246. }
  247. toneLabel.setText (tr ("Tone"), juce::dontSendNotification);
  248. toneLabel.setFont (theme::font (theme::type::body, true));
  249. addAndMakeVisible (toneLabel);
  250. const char* toneText[3] { "Low", "Mid", "High" };
  251. for (int i = 0; i < 3; ++i)
  252. {
  253. auto& k = tone[i];
  254. k.setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
  255. k.setTextBoxStyle (juce::Slider::NoTextBox, false, 0, 0);
  256. k.setRange (-6.0, 6.0, 0.1);
  257. k.setDoubleClickReturnValue (true, 0.0);
  258. k.textFromValueFunction = [] (double v) { return db ((float) v); };
  259. k.setPopupDisplayEnabled (true, false, this);
  260. k.onValueChange = [this] { changed (false); };
  261. addAndMakeVisible (k);
  262. toneNames[i].setText (tr (toneText[i]), juce::dontSendNotification);
  263. toneNames[i].setFont (theme::font (theme::type::small));
  264. toneNames[i].setColour (juce::Label::textColourId, theme::colour::textSecondary);
  265. toneNames[i].setJustificationType (juce::Justification::centred);
  266. addAndMakeVisible (toneNames[i]);
  267. }
  268. autoButton.setButtonText (tr ("Set the input level for me"));
  269. autoButton.setTooltip (tr ("Measures the mix without the look and sets the look's input level for it"));
  270. autoButton.onClick = [this] { autoLevel(); };
  271. addAndMakeVisible (autoButton);
  272. levelInfo.setFont (theme::font (theme::type::small));
  273. levelInfo.setColour (juce::Label::textColourId, theme::colour::textSecondary);
  274. levelInfo.setJustificationType (juce::Justification::centred);
  275. addAndMakeVisible (levelInfo);
  276. // the looks hold sample peaks (FL's Limiter); a release file with a true-peak ceiling comes from the mastering export
  277. const auto arrow = juce::String::fromUTF8 (" \xe2\x80\xba ");
  278. peakHint.setText (tr ("For a file with a true-peak ceiling: {0}", { tr ("File") + arrow + tr ("Export") + arrow + tr ("Master...") }),
  279. juce::dontSendNotification);
  280. peakHint.setFont (theme::font (theme::type::caption));
  281. peakHint.setColour (juce::Label::textColourId, theme::colour::textSecondary);
  282. peakHint.setJustificationType (juce::Justification::centredLeft);
  283. peakHint.setMinimumHorizontalScale (0.8f);
  284. addAndMakeVisible (peakHint);
  285. removeButton.setButtonText (tr ("Remove look"));
  286. removeButton.onClick = [this] {
  287. engine.editSongStructural ([] (Song& s) { looks::remove (s); });
  288. refresh();
  289. };
  290. addAndMakeVisible (removeButton);
  291. // round 190ch: measure a finished track and match its tone and loudness (its own window)
  292. if (saving.referenceMatch)
  293. {
  294. matchButton.setButtonText (tr ("Match a reference track..."));
  295. matchButton.setTooltip (tr ("Measures a finished track and your song, and suggests an EQ curve and a level"));
  296. matchButton.onClick = [this] { saving.referenceMatch(); };
  297. addAndMakeVisible (matchButton);
  298. }
  299. // the last step in plain words: the song as one file, with the look on (round 190t)
  300. if (saving.exportAudio)
  301. {
  302. saveLabel.setText (tr ("Save the song as a file"), juce::dontSendNotification);
  303. saveLabel.setFont (theme::font (theme::type::body, true));
  304. addAndMakeVisible (saveLabel);
  305. saveRows[0] = std::make_unique<SaveRow> ("WAV", tr ("Best quality, larger file"));
  306. saveRows[1] = std::make_unique<SaveRow> ("MP3", tr ("Small, for sharing"));
  307. for (int i = 0; i < 2; ++i)
  308. {
  309. saveRows[i]->onClick = [this, i] { save (i); };
  310. addAndMakeVisible (*saveRows[i]);
  311. }
  312. if (saving.exportOtherApps)
  313. {
  314. otherApps.setButtonText (tr ("For other apps..."));
  315. otherApps.onClick = [this] { save (-1); };
  316. addAndMakeVisible (otherApps);
  317. }
  318. }
  319. refresh();
  320. }
  321. void FinishDock::save (int format)
  322. {
  323. // "Hear without" is for comparing; the file gets the look
  324. if (looks::bypassed (engine.getSong()))
  325. {
  326. engine.editSong ([] (Song& s) { looks::setBypassed (s, false); });
  327. refresh();
  328. }
  329. if (format < 0 && saving.exportOtherApps)
  330. saving.exportOtherApps();
  331. else if (format >= 0 && saving.exportAudio)
  332. saving.exportAudio (format);
  333. }
  334. FinishDock::~FinishDock()
  335. {
  336. stopTimer();
  337. }
  338. void FinishDock::refresh()
  339. {
  340. const juce::ScopedValueSetter<bool> guard (updating, true);
  341. const auto& song = engine.getSong();
  342. const auto has = looks::present (song);
  343. shown = has ? song.masterLook : MasterLookSettings {};
  344. if (! has)
  345. shown.id = 0;
  346. const auto edited = has && looks::custom (song);
  347. for (int i = 0; i < looks::count; ++i)
  348. {
  349. tiles[i]->selected = has && ! edited && shown.id == i + 1;
  350. tiles[i]->repaint();
  351. }
  352. status.setText (! has ? tr ("Choose a look for the whole song.")
  353. : edited ? tr ("Custom: the look was changed in the Mixer.")
  354. : tr ("{0}, on the Master's last slots.", { tr (looks::name (shown.id)) }),
  355. juce::dontSendNotification);
  356. intensity.setValue (has ? shown.intensity : 0.5, juce::dontSendNotification);
  357. for (int i = 0; i < 3; ++i)
  358. tone[i].setValue (has ? shown.tone[(std::size_t) i] : 0.0, juce::dontSendNotification);
  359. hearWithout.setToggleState (looks::bypassed (song), juce::dontSendNotification);
  360. for (auto* c : std::initializer_list<juce::Component*> { &hearWithout, &intensity, &tone[0], &tone[1], &tone[2], &autoButton, &removeButton })
  361. c->setEnabled (has);
  362. if (measuring->load() == 0)
  363. levelInfo.setText (has ? tr ("Input level: {0}", { db (shown.inputDb) }) : juce::String(), juce::dontSendNotification);
  364. // about how big each file will be, from the song's length and the Export window's own defaults
  365. for (int i = 0; i < 2; ++i)
  366. if (saveRows[i] != nullptr)
  367. {
  368. exportopts::Options o;
  369. o.format = i == 0 ? exportopts::Format::wav : exportopts::Format::mp3;
  370. const auto seconds = exportMusicSeconds (song, o);
  371. saveRows[i]->setSize (seconds > 0.0 ? juce::File::descriptionOfSizeInBytes (exportopts::estimatedBytes (o, seconds)) : juce::String());
  372. }
  373. }
  374. void FinishDock::choose (int id)
  375. {
  376. auto s = shown;
  377. if (s.id == 0)
  378. s = MasterLookSettings {};
  379. s.id = id;
  380. bool ok = true;
  381. // adds or replaces Master slots (another look may swap the Soft Clipper for the Stereo Enhancer): a structural edit
  382. engine.editSongStructural ([&ok, s] (Song& song) { ok = looks::apply (song, s); });
  383. if (! ok)
  384. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Master looks"),
  385. tr ("The Master has no room for the look: it needs four free effect slots."));
  386. refresh();
  387. }
  388. void FinishDock::changed (bool)
  389. {
  390. if (updating || shown.id == 0)
  391. return;
  392. shown.intensity = (float) intensity.getValue();
  393. for (int i = 0; i < 3; ++i)
  394. shown.tone[(std::size_t) i] = (float) tone[i].getValue();
  395. const auto s = shown;
  396. engine.editSong ([s] (Song& song) { looks::apply (song, s); });
  397. }
  398. void FinishDock::autoLevel()
  399. {
  400. if (measuring->load() != 0 || shown.id == 0)
  401. return;
  402. // the song without the look, rendered offline on another thread; the loudness sets the look's input level
  403. auto song = engine.getSong();
  404. looks::setBypassed (song, true);
  405. measuring->store (1);
  406. levelInfo.setText (tr ("Measuring the mix..."), juce::dontSendNotification);
  407. autoButton.setEnabled (false);
  408. auto flag = measuring;
  409. auto result = measuredLufs;
  410. std::thread ([song = std::move (song), flag, result] {
  411. exportopts::Options o;
  412. o.format = exportopts::Format::wav;
  413. o.wavBits = 32;
  414. o.sampleRate = 44100.0;
  415. const auto file = juce::File::createTempFile (".wav");
  416. ExportJob job (song, o, file);
  417. job.setExtraData (false);
  418. juce::String error;
  419. float lufs = -100.0f;
  420. if (job.run ([] (double) { return true; }, error))
  421. {
  422. juce::WavAudioFormat wav;
  423. if (std::unique_ptr<juce::AudioFormatReader> reader (wav.createReaderFor (file.createInputStream().release(), true)); reader != nullptr)
  424. {
  425. const auto n = (int) juce::jmin<juce::int64> (reader->lengthInSamples, (juce::int64) (44100.0 * 600.0));
  426. juce::AudioBuffer<float> buf ((int) juce::jmax (2u, reader->numChannels), n);
  427. reader->read (&buf, 0, n, 0, true, true);
  428. std::vector<float> l (buf.getReadPointer (0), buf.getReadPointer (0) + n), r (buf.getReadPointer (1), buf.getReadPointer (1) + n);
  429. double value = 0.0, peak = 0.0;
  430. mastering::measure (l, r, 44100.0, value, peak);
  431. lufs = (float) value;
  432. }
  433. }
  434. file.deleteFile();
  435. result->store (lufs);
  436. flag->store (2);
  437. }).detach();
  438. startTimer (100);
  439. }
  440. void FinishDock::timerCallback()
  441. {
  442. if (measuring->load() != 2)
  443. return;
  444. stopTimer();
  445. measuring->store (0);
  446. autoButton.setEnabled (shown.id != 0);
  447. const auto lufs = measuredLufs->load();
  448. if (lufs < -70.0f)
  449. {
  450. levelInfo.setText (tr ("The mix is silent: nothing to measure."), juce::dontSendNotification);
  451. return;
  452. }
  453. shown.inputDb = looks::autoInputGainDb (lufs);
  454. const auto s = shown;
  455. engine.editSong ([s] (Song& song) { looks::apply (song, s); });
  456. levelInfo.setText (tr ("Mix {0} LUFS: input level {1}", { juce::String (lufs, 1), db (shown.inputDb) }), juce::dontSendNotification);
  457. }
  458. void FinishDock::paint (juce::Graphics& g)
  459. {
  460. g.fillAll (theme::colour::bg2);
  461. g.setColour (theme::colour::border);
  462. g.drawVerticalLine (0, 0.0f, (float) getHeight());
  463. }
  464. void FinishDock::resized()
  465. {
  466. auto r = getLocalBounds().reduced (12, 10);
  467. auto head = r.removeFromTop (28);
  468. closeButton.setBounds (head.removeFromRight (28));
  469. title.setBounds (head);
  470. status.setBounds (r.removeFromTop (34));
  471. r.removeFromTop (4);
  472. // (a short window: the look tiles give way so that the Save rows stay in view)
  473. const auto saveH = (saveRows[0] != nullptr ? 22 + 2 * 36 + (otherApps.isVisible() ? 34 : 0) + 10 : 0) + (matchButton.isVisible() ? 34 : 0);
  474. const auto gap = 6;
  475. const auto tileH = juce::jlimit (46, 64, (r.getHeight() - 306 - saveH) / 4 - gap);
  476. const auto colW = (r.getWidth() - gap) / 2;
  477. for (int i = 0; i < looks::count; ++i)
  478. {
  479. const auto row = i / 2, col = i % 2;
  480. tiles[i]->setBounds (r.getX() + col * (colW + gap), r.getY() + row * (tileH + gap), colW, tileH);
  481. }
  482. r.removeFromTop (4 * (tileH + gap) + 6);
  483. intensityLabel.setBounds (r.removeFromTop (22));
  484. auto bar = r.removeFromTop (24);
  485. intensity.setBounds (bar);
  486. auto markRow = r.removeFromTop (18);
  487. // the marks under their values (Light 25 %, Normal 50 %, Heavy 85 %), inside the slider's track
  488. const auto x0 = bar.getX() + 10, w = bar.getWidth() - 20;
  489. const float at[3] { 0.25f, 0.5f, 0.85f };
  490. for (int i = 0; i < 3; ++i)
  491. marks[i].setBounds (juce::Rectangle<int> (60, markRow.getHeight()).withCentre ({ x0 + (int) (at[i] * (float) w), markRow.getCentreY() }));
  492. r.removeFromTop (10);
  493. toneLabel.setBounds (r.removeFromTop (22));
  494. auto knobs = r.removeFromTop (58);
  495. const auto kw = knobs.getWidth() / 3;
  496. for (int i = 0; i < 3; ++i)
  497. {
  498. auto cell = knobs.removeFromLeft (kw);
  499. toneNames[i].setBounds (cell.removeFromBottom (16));
  500. tone[i].setBounds (cell.withSizeKeepingCentre (42, 42));
  501. }
  502. r.removeFromTop (12);
  503. autoButton.setBounds (r.removeFromTop (30));
  504. levelInfo.setBounds (r.removeFromTop (22));
  505. r.removeFromTop (8);
  506. auto buttons = r.removeFromTop (30);
  507. hearWithout.setBounds (buttons.removeFromLeft (buttons.getWidth() / 2 - 3));
  508. buttons.removeFromLeft (6);
  509. removeButton.setBounds (buttons);
  510. r.removeFromTop (8);
  511. if (matchButton.isVisible())
  512. {
  513. matchButton.setBounds (r.removeFromTop (28));
  514. r.removeFromTop (6);
  515. }
  516. peakHint.setBounds (r.removeFromTop (32));
  517. if (saveRows[0] != nullptr)
  518. {
  519. r.removeFromTop (10);
  520. saveLabel.setBounds (r.removeFromTop (22));
  521. for (auto& row : saveRows)
  522. {
  523. row->setBounds (r.removeFromTop (32));
  524. r.removeFromTop (4);
  525. }
  526. if (otherApps.isVisible())
  527. otherApps.setBounds (r.removeFromTop (30));
  528. }
  529. }
  530. } // namespace lynx