WorkflowExtras.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. #include "ui/WorkflowExtras.h"
  2. #include <utility>
  3. #include "core/EscClose.h"
  4. #include "core/RulerGestures.h" // round 190nq (#227)
  5. #include "core/Sections.h" // round 190ol (P1)
  6. #include "core/ChordLane.h" // round 190pf (P13)
  7. #include "core/TrackClips.h"
  8. #include "core/TrackStates.h"
  9. #include "core/TrackVersions.h" // round 190pe (P20)
  10. #include "core/LaneView.h"
  11. #include "core/SimpleTracks.h"
  12. #include "core/LayoutStyle.h"
  13. #include "core/LiveScaleControl.h" // round 190oo (O-5)
  14. #include "core/MidiDrop.h"
  15. #include "core/LoopAnalysis.h" // round 190kx
  16. #include "core/PlaylistViewOptions.h"
  17. #include "core/PlaylistTrackOps.h"
  18. #include "core/TakeCleanup.h"
  19. #include "core/TransportEdit.h"
  20. #include "core/MuteKeys.h"
  21. #include "core/SaveExtras.h" // round 190qo (#215, #251)
  22. #include "core/StartPage.h"
  23. #include "core/TrackOnly.h"
  24. #include "core/WheelZones.h"
  25. #include "core/RangeEdit.h" // round 190pa (P14)
  26. #include "core/ZoomAnchor.h" // round 190qr (#276)
  27. #include "core/EditorFeel.h" // round 190ro (D-2: zoomanchor::lynxKeys)
  28. #include "core/ExportDone.h" // round 190qr (#280)
  29. #include "core/ClipHandle.h" // round 190qr (#274)
  30. #include "core/PluginPicks.h" // round 190qi (rollup 0.1.32 step 3: the extras' switches)
  31. #include "core/MidiPreview.h"
  32. #include "core/BrowserTags.h"
  33. #include "core/BrowserDoubleClick.h" // round 190se (issue #323)
  34. #include "core/MarkerJump.h" // round 190so (#312)
  35. #include "core/MixerRows.h" // round 190so (#294, #295)
  36. #include "core/PinnedTracks.h" // round 190so (#293)
  37. #include "core/ViewExtras.h" // round 190so (#294, #305, #343)
  38. #include "core/SliceExtras.h" // round 190st (#339, #340)
  39. #include "core/FileMarkers.h" // round 190st (#316)
  40. #include "core/ClipWarp.h" // round 190st (#314)
  41. #include "core/StretchGrip.h" // round 190st (#291)
  42. #include "engine/AudioEngine.h"
  43. #include "engine/MidiFileIo.h"
  44. #include "ui/HintBar.h"
  45. #include "ui/I18n.h"
  46. namespace lynx::workflowextras
  47. {
  48. namespace
  49. {
  50. AudioEngine* boundEngine = nullptr;
  51. // Track-only mode switched on in a project made with the Channel rack: one step gives each instrument its own track
  52. void offerTracksForEveryInstrument()
  53. {
  54. if (boundEngine == nullptr || ! trackonly::active())
  55. return;
  56. const auto count = trackonly::withoutTrack (boundEngine->getSong());
  57. if (count == 0)
  58. return;
  59. juce::AlertWindow::showOkCancelBox (juce::MessageBoxIconType::QuestionIcon, tr ("Track-only mode"),
  60. tr ("{0} instruments of this project have no track of their own. Give each one an instrument track now? (One step: Edit › Undo takes it back.)",
  61. { juce::String (count) }),
  62. tr ("Yes"), tr ("No"), nullptr, juce::ModalCallbackFunction::create ([] (int result) {
  63. if (result == 1 && boundEngine != nullptr)
  64. boundEngine->editSong ([] (Song& s) { trackonly::assignAll (s); });
  65. }));
  66. }
  67. } // namespace
  68. void bind (AudioEngine* engine) { boundEngine = engine; }
  69. bool channelRackOpened()
  70. {
  71. // issue #246 (round 190oq): the Channel rack opens in Track-only mode too (FL keeps an instrument track's channel in
  72. // its Channel rack); a hint says what it lists, once per session
  73. static bool told = false;
  74. if (! trackonly::active() || std::exchange (told, true))
  75. return false;
  76. ui::postHint ({ tr ("Track-only mode: the Channel rack lists the instruments of the instrument tracks; each plays through its track's mixer track"), {} }, 4000);
  77. return true;
  78. }
  79. bool trackOnlySwitchedOn()
  80. {
  81. // (the rack is hidden when the mode comes on, not again at every other switch)
  82. static bool last = false;
  83. const auto now = trackonly::active();
  84. return now && ! std::exchange (last, now);
  85. }
  86. void addLayoutItems (juce::PopupMenu& menu, bool patternLayout)
  87. {
  88. menu.addSeparator();
  89. menu.addItem (tr ("Track-only mode (1 track = 1 instrument, the Channel rack hidden)"), patternLayout, trackonly::enabled(),
  90. [] { setExtra ("layout.trackOnly", ! trackonly::enabled()); });
  91. // round 190qu (Discord 11-24, sidthenugget): a pattern project into 1 track = 1 instrument, with FL's Split by channel
  92. menu.addItem (tr ("Convert project to Track-only..."), patternLayout && boundEngine != nullptr, false, [] { runAction ("layout.convertTrackOnly"); });
  93. }
  94. // Round 190qu: "Convert project to Track-only" (trackonly::convertProject) after a confirmation; switches the mode on
  95. static void convertToTrackOnly()
  96. {
  97. if (boundEngine == nullptr)
  98. return;
  99. juce::AlertWindow::showOkCancelBox (
  100. juce::MessageBoxIconType::QuestionIcon, tr ("Convert project to Track-only"),
  101. tr ("Every pattern clip of the arrangement is split by channel (Patterns › Split by channel) and each part goes onto its instrument's own track, at the same place. The song sounds the same; one step: Edit › Undo takes it back. Track-only mode is switched on."),
  102. tr ("Convert"), tr ("Cancel"), nullptr, juce::ModalCallbackFunction::create ([] (int result) {
  103. if (result != 1 || boundEngine == nullptr)
  104. return;
  105. trackonly::ConvertReport report;
  106. boundEngine->editSong ([&report] (Song& s) { report = trackonly::convertProject (s); });
  107. if (! trackonly::enabled())
  108. setExtra ("layout.trackOnly", true);
  109. ui::postHint ({ tr ("Track-only: {0} clips on their instruments' tracks, {1} patterns split, {2} tracks made",
  110. { juce::String (report.clipsMoved), juce::String (report.patternsSplit), juce::String (report.tracksMade) }), {} }, 5000);
  111. }));
  112. }
  113. // --- settings ---------------------------------------------------------------------------------------------------------
  114. bool readUiOption (const juce::String& key, bool on)
  115. {
  116. if (key == "wheelZones")
  117. wheelzones::setEnabled (on);
  118. else if (key == "tempTools")
  119. temptool::setEnabled (on);
  120. else if (key == "midiDrop")
  121. mididrop::setPlaylistDrop (on);
  122. else if (key == "trackOnly")
  123. trackonly::setEnabled (on);
  124. else if (key == "headerWidthDrag") // round 190jq (issue #164)
  125. headerwidth::draggable = on;
  126. else if (key == "pointerClickButton") // round 190jq (issue #191): the switch's button, then the switch
  127. pointerclick::buttonShown = on;
  128. else if (key == "pointerClick")
  129. pointerclick::on = on && pointerclick::buttonShown;
  130. else if (key == "clipLanesPattern") // round 190jq (issue #191.3)
  131. cliplanes::patternOn = on;
  132. else if (key == "clipLanesLive")
  133. cliplanes::liveOn = on;
  134. else if (key == "wToStart") // issue #195: REAPER's W goes to the start (LYNX extra)
  135. transportedit::setWGoesToStart (on);
  136. else if (key == "simpleLoopDetect") // round 190kx: Simple drops take the tempo and key found in the audio
  137. loopanalysis::dropDetects() = on;
  138. else if (key == "escClosesWindows") // issue #217 (round 190ng): FL's Esc closes the focused window
  139. escclose::enabled() = on;
  140. else if (key == "trackClipsShown") // round 190ne: track clips listed in the pattern selector too (the Picker group's switch)
  141. trackclips::setShownInSelector (on);
  142. else if (key == "rulerSeeksAnyTool") // issue #227 (round 190nq, LYNX extra)
  143. ruler::seekWithAnyTool() = on;
  144. else if (key == "zoomAtSongPosition") // issue #276 (round 190qr, LYNX extra)
  145. zoomanchor::atSongPosition() = on;
  146. else if (key == "zoomKeysLynx") // round 190ro (D-2): round 190qe's zoom keys, a LYNX extra
  147. zoomanchor::lynxKeys() = on;
  148. else if (key == "exportDoneSound") // issue #280 (round 190qr, LYNX extra)
  149. exportdone::sound() = on;
  150. else if (key == "exportDoneWindow")
  151. exportdone::window() = on;
  152. else if (key == "gainHandleFollowsView") // issue #274 (round 190qr, LYNX extra)
  153. cliphandle::gainFollowsView() = on;
  154. else if (key == "sectionsLane") // round 190ol (P1): the Pattern layout's Sections lane
  155. sections::patternLaneOn() = on;
  156. else if (key == "chordLane") // round 190pf (P13): the Chord lane, every layout
  157. chordlane::laneOn() = on;
  158. else if (key == "prChordHighlight") // round 190pf (P13): the Piano roll lights the Chord lane's chord
  159. chordlane::pianoRollHighlight() = on;
  160. else if (key == "clipLanesFoldedLive") // round 190oo (CS O-3, LYNX extra)
  161. cliplanes::foldedOnOpen = on;
  162. else if (key == "liveScaleControl") // round 190oo (O-5, LYNX extra)
  163. livescale::shown = on;
  164. else if (key == "trackStates") // round 190op (P4, LYNX extra): Hide / Deactivate in the Pattern layout's menus
  165. trackstates::patternMenus() = on;
  166. else if (key == "trackVersions") // round 190pe (P20, LYNX extra): Track versions in the Pattern layout's track menu
  167. trackversions::patternMenus() = on;
  168. else if (key == "muteKeyToggles") // issue #249 (round 190oq, LYNX extra)
  169. mutekeys::setToggles (on);
  170. else if (key == "startPage") // issue #252 (round 190oq; on by default, FL-exact)
  171. startpage::setEnabled (on);
  172. else if (key == "rangeEdits") // round 190pa (P14, LYNX extra): Ctrl+Alt+drag ranges in the Pattern layout
  173. rangeedit::patternLayoutOn() = on;
  174. else if (key == "alwaysCollect") // issue #251 (round 190qo, LYNX extra)
  175. saveextras::setAlwaysCollect (on);
  176. else if (key == "exportNoDialog") // issue #215 (round 190qo, LYNX extra)
  177. saveextras::setExportNoDialog (on);
  178. else if (key == "simpleDropStrip") // round 190qu (Discord 11-24): the Simple drop strip under the tracks, always
  179. simpletracks::dropStripAlways = on;
  180. else if (key == "pluginRecent") // round 190qi's lists (rollup 0.1.32 step 3: switches on the extras page)
  181. pluginpicks::recentShown() = on;
  182. else if (key == "pluginOneRow")
  183. pluginpicks::oneRowPerPlugin() = on;
  184. else if (key == "browserMidiPreview")
  185. midipreview::enabled() = on;
  186. else if (key == "browserTabCompletes")
  187. browsertags::tabCompletes() = on;
  188. else if (key == "browserDoubleClickAdds") // issue #323 (round 190se, LYNX extra)
  189. browserclick::doubleClickAdds() = on;
  190. // round 190so (0.1.33 block A3, the Playlist view group)
  191. else if (key == "pinnedTracks")
  192. pinned::enabled = on;
  193. else if (key == "playlistMixerRows")
  194. mixerrows::shown = on;
  195. else if (key == "mixerRowsReturns")
  196. mixerrows::returnsShown = on;
  197. else if (key == "mixerRowsMaster")
  198. mixerrows::masterShown = on;
  199. else if (key == "playlistWideMeters")
  200. widemeter::on = on;
  201. else if (key == "toolbarMeterValues")
  202. toolbarextras::meterValues = on;
  203. else if (key == "secondaryTime")
  204. toolbarextras::secondaryTime = on;
  205. else if (key == "markerNumberKeys")
  206. markerjump::numberKeys = on;
  207. else if (key == "emptyDoubleClick")
  208. emptyworkspace::doubleClick = on;
  209. else if (key == "sliceEscape") // round 190st (#339)
  210. sliceextras::escapeCancels = on;
  211. else if (key == "sliceHoverLine") // round 190st (#340)
  212. sliceextras::hoverLine = on;
  213. else if (key == "fileMarkerHints") // round 190st (#316)
  214. filemarkers::hintsOn = on;
  215. else if (key == "stretchSpeeds") // round 190st (#314)
  216. clipwarp::showSpeeds = on;
  217. else if (key == "stretchGrip") // round 190st (#291)
  218. stretchgrip::patternOn = on;
  219. else if (key == "stretchGripOther")
  220. stretchgrip::otherOn = on;
  221. else if (key == "alwaysPianoRoll")
  222. patternclipopen::enabled() = on;
  223. else
  224. return false;
  225. return true;
  226. }
  227. bool readUiValue (const juce::String& key, const juce::String& value)
  228. {
  229. if (key == "secondaryTimeUnit") // round 190so (#343): the second readout's unit (core/ViewExtras.h)
  230. {
  231. toolbarextras::secondaryUnit = toolbarextras::unitFromInt (value.getIntValue());
  232. return true;
  233. }
  234. if (key != "headerWidthExtra") // round 190jq (issue #164): px added to the header column's own width
  235. return false;
  236. headerwidth::extra = headerwidth::clampExtra (value.getIntValue());
  237. return true;
  238. }
  239. juce::String uiOptionsText()
  240. {
  241. return "\nwheelZones=" + juce::String (wheelzones::enabled() ? 1 : 0) + "\ntempTools=" + juce::String (temptool::enabled() ? 1 : 0)
  242. + "\nmidiDrop=" + juce::String (mididrop::playlistDrop() ? 1 : 0) + "\ntrackOnly=" + juce::String (trackonly::enabled() ? 1 : 0)
  243. // round 190jq (the button before its switch: the loader reads them in this order)
  244. + "\nheaderWidthDrag=" + juce::String (headerwidth::draggable ? 1 : 0) + "\nheaderWidthExtra=" + juce::String (headerwidth::clampExtra (headerwidth::extra))
  245. + "\npointerClickButton=" + juce::String (pointerclick::buttonShown ? 1 : 0) + "\npointerClick=" + juce::String (pointerclick::on ? 1 : 0)
  246. + "\nclipLanesPattern=" + juce::String (cliplanes::patternOn ? 1 : 0) + "\nclipLanesLive=" + juce::String (cliplanes::liveOn ? 1 : 0)
  247. + "\nwToStart=" + juce::String (transportedit::wGoesToStart() ? 1 : 0) // (round 190jz, issue #195)
  248. + "\nsimpleLoopDetect=" + juce::String (loopanalysis::dropDetects().load() ? 1 : 0) // (round 190kx)
  249. + "\nescClosesWindows=" + juce::String (escclose::enabled() ? 1 : 0) // (round 190ng, issue #217)
  250. + "\ntrackClipsShown=" + juce::String (trackclips::shownInSelector() ? 1 : 0) // (round 190ne)
  251. + "\nrulerSeeksAnyTool=" + juce::String (ruler::seekWithAnyTool() ? 1 : 0) // (round 190nq, issue #227)
  252. + "\nzoomAtSongPosition=" + juce::String (zoomanchor::atSongPosition() ? 1 : 0) // (round 190qr, issue #276)
  253. + "\nzoomKeysLynx=" + juce::String (zoomanchor::lynxKeys() ? 1 : 0) // (round 190ro, D-2)
  254. + "\nexportDoneSound=" + juce::String (exportdone::sound() ? 1 : 0) + "\nexportDoneWindow=" + juce::String (exportdone::window() ? 1 : 0) // (#280)
  255. + "\ngainHandleFollowsView=" + juce::String (cliphandle::gainFollowsView() ? 1 : 0) // (round 190qr, issue #274)
  256. + "\nsectionsLane=" + juce::String (sections::patternLaneOn() ? 1 : 0) // (round 190ol, P1)
  257. + "\nchordLane=" + juce::String (chordlane::laneOn() ? 1 : 0) // (round 190pf, P13)
  258. + "\nprChordHighlight=" + juce::String (chordlane::pianoRollHighlight() ? 1 : 0) // (round 190pf, P13)
  259. + "\nclipLanesFoldedLive=" + juce::String (cliplanes::foldedOnOpen ? 1 : 0) // (round 190oo, CS O-3)
  260. + "\nliveScaleControl=" + juce::String (livescale::shown ? 1 : 0) // (round 190oo, O-5)
  261. + "\ntrackStates=" + juce::String (trackstates::patternMenus() ? 1 : 0) // (round 190op, P4)
  262. + "\ntrackVersions=" + juce::String (trackversions::patternMenus() ? 1 : 0) // (round 190pe, P20)
  263. + "\nmuteKeyToggles=" + juce::String (mutekeys::toggles() ? 1 : 0) // (round 190oq, issue #249)
  264. + "\nstartPage=" + juce::String (startpage::enabled() ? 1 : 0) // (round 190oq, issue #252)
  265. + "\nrangeEdits=" + juce::String (rangeedit::patternLayoutOn() ? 1 : 0) // (round 190pa, P14)
  266. + "\nalwaysCollect=" + juce::String (saveextras::alwaysCollect() ? 1 : 0) // (round 190qo, issue #251)
  267. + "\nexportNoDialog=" + juce::String (saveextras::exportNoDialog() ? 1 : 0) // (round 190qo, issue #215)
  268. + "\nsimpleDropStrip=" + juce::String (simpletracks::dropStripAlways ? 1 : 0) // (round 190qu)
  269. // (round 190qi's lists; rollup 0.1.32 step 3)
  270. + "\npluginRecent=" + juce::String (pluginpicks::recentShown() ? 1 : 0) + "\npluginOneRow=" + juce::String (pluginpicks::oneRowPerPlugin() ? 1 : 0)
  271. + "\nbrowserMidiPreview=" + juce::String (midipreview::enabled() ? 1 : 0) + "\nbrowserTabCompletes=" + juce::String (browsertags::tabCompletes() ? 1 : 0)
  272. + "\nbrowserDoubleClickAdds=" + juce::String (browserclick::doubleClickAdds() ? 1 : 0) // (round 190se, issue #323)
  273. // (round 190so, 0.1.33 block A3)
  274. + "\npinnedTracks=" + juce::String (pinned::enabled ? 1 : 0) + "\nplaylistMixerRows=" + juce::String (mixerrows::shown ? 1 : 0)
  275. + "\nmixerRowsReturns=" + juce::String (mixerrows::returnsShown ? 1 : 0) + "\nmixerRowsMaster=" + juce::String (mixerrows::masterShown ? 1 : 0)
  276. + "\nplaylistWideMeters=" + juce::String (widemeter::on ? 1 : 0) + "\ntoolbarMeterValues=" + juce::String (toolbarextras::meterValues ? 1 : 0)
  277. + "\nsecondaryTime=" + juce::String (toolbarextras::secondaryTime ? 1 : 0)
  278. + "\nsecondaryTimeUnit=" + juce::String (toolbarextras::unitToInt (toolbarextras::secondaryUnit))
  279. + "\nmarkerNumberKeys=" + juce::String (markerjump::numberKeys ? 1 : 0) + "\nemptyDoubleClick=" + juce::String (emptyworkspace::doubleClick ? 1 : 0)
  280. + "\nalwaysPianoRoll=" + juce::String (patternclipopen::enabled() ? 1 : 0)
  281. + "\nsliceEscape=" + juce::String (sliceextras::escapeCancels ? 1 : 0) + "\nsliceHoverLine=" + juce::String (sliceextras::hoverLine ? 1 : 0)
  282. + "\nfileMarkerHints=" + juce::String (filemarkers::hintsOn ? 1 : 0) + "\nstretchSpeeds=" + juce::String (clipwarp::showSpeeds ? 1 : 0)
  283. + "\nstretchGrip=" + juce::String (stretchgrip::patternOn ? 1 : 0) + "\nstretchGripOther=" + juce::String (stretchgrip::otherOn ? 1 : 0);
  284. }
  285. std::optional<bool> extraOn (std::string_view id)
  286. {
  287. if (id == "playlist.wheelZones")
  288. return wheelzones::enabled();
  289. if (id == "editing.tempTools")
  290. return temptool::enabled();
  291. if (id == "playlist.midiDrop")
  292. return mididrop::playlistDrop();
  293. if (id == "layout.trackOnly")
  294. return trackonly::enabled();
  295. if (id == "playlist.headerWidth") // round 190jq
  296. return headerwidth::draggable;
  297. if (id == "playlist.pointerClick")
  298. return pointerclick::buttonShown;
  299. if (id == "playlist.clipLanes") // (the Pattern layout's switch; the Clip-launch layout has its own, on by default)
  300. return cliplanes::patternOn;
  301. if (id == "transport.wToStart")
  302. return transportedit::wGoesToStart();
  303. if (id == "simple.loopDetect") // round 190kx
  304. return loopanalysis::dropDetects().load();
  305. if (id == "general.escCloses") // round 190ng (issue #217)
  306. return escclose::enabled();
  307. if (id == "playlist.rulerSeeksAnyTool") // round 190nq (issue #227)
  308. return ruler::seekWithAnyTool();
  309. if (id == "editing.zoomAtSongPosition") // round 190qr (issue #276)
  310. return zoomanchor::atSongPosition();
  311. if (id == "editing.zoomKeysLynx") // round 190ro (D-2)
  312. return zoomanchor::lynxKeys();
  313. if (id == "export.doneSound") // round 190qr (issue #280)
  314. return exportdone::sound();
  315. if (id == "export.doneWindow")
  316. return exportdone::window();
  317. if (id == "playlist.gainHandleFollowsView") // round 190qr (issue #274)
  318. return cliphandle::gainFollowsView();
  319. if (id == "playlist.sectionsLane") // round 190ol (P1)
  320. return sections::patternLaneOn();
  321. if (id == "playlist.chordLane") // round 190pf (P13)
  322. return chordlane::laneOn();
  323. if (id == "pianoRoll.chordHighlight") // round 190pf (P13)
  324. return chordlane::pianoRollHighlight();
  325. if (id == "playlist.clipLanesFolded") // round 190oo (CS O-3)
  326. return cliplanes::foldedOnOpen;
  327. if (id == "controlBar.liveScale") // round 190oo (O-5)
  328. return livescale::shown;
  329. if (id == "playlist.trackStates") // round 190op (P4)
  330. return trackstates::patternMenus();
  331. if (id == "playlist.trackVersions") // round 190pe (P20)
  332. return trackversions::patternMenus();
  333. if (id == "editing.muteKeyToggles") // round 190oq (issue #249)
  334. return mutekeys::toggles();
  335. if (id == "general.startPage") // round 190oq (issue #252)
  336. return startpage::enabled();
  337. if (id == "playlist.rangeEdits") // round 190pa (P14)
  338. return rangeedit::patternLayoutOn();
  339. if (id == "file.alwaysCollect") // round 190qo (issue #251)
  340. return saveextras::alwaysCollect();
  341. if (id == "export.noDialog") // round 190qo (issue #215)
  342. return saveextras::exportNoDialog();
  343. if (id == "simple.dropStrip") // round 190qu
  344. return simpletracks::dropStripAlways;
  345. if (id == "plugins.recent") // round 190qi (rollup 0.1.32 step 3)
  346. return pluginpicks::recentShown();
  347. if (id == "plugins.oneRow")
  348. return pluginpicks::oneRowPerPlugin();
  349. if (id == "browser.midiPreview")
  350. return midipreview::enabled();
  351. if (id == "browser.tabCompletes")
  352. return browsertags::tabCompletes();
  353. if (id == "browser.doubleClickAdds") // round 190se (issue #323)
  354. return browserclick::doubleClickAdds();
  355. // round 190so (0.1.33 block A3)
  356. if (id == "playlist.pinnedTracks")
  357. return pinned::enabled;
  358. if (id == "playlist.mixerRows")
  359. return mixerrows::shown;
  360. if (id == "playlist.wideMeters")
  361. return widemeter::on;
  362. if (id == "toolbar.meterValues")
  363. return toolbarextras::meterValues;
  364. if (id == "toolbar.secondaryTime")
  365. return toolbarextras::secondaryTime;
  366. if (id == "playlist.markerNumberKeys")
  367. return markerjump::numberKeys;
  368. if (id == "general.emptyDoubleClick")
  369. return emptyworkspace::doubleClick;
  370. if (id == "playlist.sliceEscape") // round 190st (#339)
  371. return sliceextras::escapeCancels;
  372. if (id == "playlist.sliceHoverLine") // round 190st (#340)
  373. return sliceextras::hoverLine;
  374. if (id == "playlist.fileMarkerHints") // round 190st (#316)
  375. return filemarkers::hintsOn;
  376. if (id == "playlist.stretchSpeeds") // round 190st (#314)
  377. return clipwarp::showSpeeds;
  378. if (id == "playlist.stretchGrip") // round 190st (#291)
  379. return stretchgrip::patternOn;
  380. if (id == "playlist.stretchGripOther")
  381. return stretchgrip::otherOn;
  382. if (id == "playlist.alwaysPianoRoll")
  383. return patternclipopen::enabled();
  384. return std::nullopt;
  385. }
  386. bool setExtra (std::string_view id, bool on)
  387. {
  388. if (id == "playlist.wheelZones")
  389. wheelzones::setEnabled (on);
  390. else if (id == "editing.tempTools")
  391. {
  392. temptool::setEnabled (on);
  393. if (! on)
  394. tempTools().toolKey (temptool::Editor::none, 0, EditTool::pencil, EditTool::pencil, nullptr, nullptr); // (ends a hold)
  395. }
  396. else if (id == "playlist.midiDrop")
  397. mididrop::setPlaylistDrop (on);
  398. else if (id == "layout.trackOnly")
  399. trackonly::setEnabled (on);
  400. else if (id == "playlist.headerWidth") // round 190jq (issue #164; the dragged width is kept for when it is on again)
  401. headerwidth::draggable = on;
  402. else if (id == "playlist.pointerClick") // (issue #191: the toolbar switch, lit when shown)
  403. pointerclick::setButtonShown (on);
  404. else if (id == "playlist.clipLanes") // (issue #191.3)
  405. cliplanes::patternOn = on;
  406. else if (id == "transport.wToStart")
  407. transportedit::setWGoesToStart (on);
  408. else if (id == "simple.loopDetect") // round 190kx
  409. loopanalysis::dropDetects() = on;
  410. else if (id == "general.escCloses") // round 190ng (issue #217)
  411. escclose::enabled() = on;
  412. else if (id == "playlist.rulerSeeksAnyTool") // round 190nq (issue #227)
  413. ruler::seekWithAnyTool() = on;
  414. else if (id == "editing.zoomAtSongPosition") // round 190qr (issue #276)
  415. zoomanchor::atSongPosition() = on;
  416. else if (id == "editing.zoomKeysLynx") // round 190ro (D-2)
  417. zoomanchor::lynxKeys() = on;
  418. else if (id == "export.doneSound") // round 190qr (issue #280)
  419. exportdone::sound() = on;
  420. else if (id == "export.doneWindow")
  421. exportdone::window() = on;
  422. else if (id == "playlist.gainHandleFollowsView") // round 190qr (issue #274)
  423. cliphandle::gainFollowsView() = on;
  424. else if (id == "playlist.sectionsLane") // round 190ol (P1)
  425. sections::patternLaneOn() = on;
  426. else if (id == "playlist.chordLane") // round 190pf (P13)
  427. chordlane::laneOn() = on;
  428. else if (id == "pianoRoll.chordHighlight") // round 190pf (P13)
  429. chordlane::pianoRollHighlight() = on;
  430. else if (id == "playlist.clipLanesFolded") // round 190oo (CS O-3: from the next project opened)
  431. cliplanes::foldedOnOpen = on;
  432. else if (id == "controlBar.liveScale") // round 190oo (O-5)
  433. livescale::shown = on;
  434. else if (id == "playlist.trackStates") // round 190op (P4)
  435. trackstates::patternMenus() = on;
  436. else if (id == "playlist.trackVersions") // round 190pe (P20)
  437. trackversions::patternMenus() = on;
  438. else if (id == "editing.muteKeyToggles") // round 190oq (issue #249)
  439. mutekeys::setToggles (on);
  440. else if (id == "general.startPage") // round 190oq (issue #252)
  441. startpage::setEnabled (on);
  442. else if (id == "playlist.rangeEdits") // round 190pa (P14)
  443. rangeedit::patternLayoutOn() = on;
  444. else if (id == "file.alwaysCollect") // round 190qo (issue #251)
  445. saveextras::setAlwaysCollect (on);
  446. else if (id == "export.noDialog") // round 190qo (issue #215)
  447. saveextras::setExportNoDialog (on);
  448. else if (id == "simple.dropStrip") // round 190qu
  449. simpletracks::dropStripAlways = on;
  450. else if (id == "plugins.recent") // round 190qi's lists (rollup 0.1.32 step 3; the lists read them when they open)
  451. pluginpicks::recentShown() = on;
  452. else if (id == "plugins.oneRow")
  453. pluginpicks::oneRowPerPlugin() = on;
  454. else if (id == "browser.midiPreview")
  455. midipreview::enabled() = on;
  456. else if (id == "browser.tabCompletes")
  457. browsertags::tabCompletes() = on;
  458. else if (id == "browser.doubleClickAdds") // round 190se (issue #323)
  459. browserclick::doubleClickAdds() = on;
  460. else if (id == "playlist.pinnedTracks") // round 190so (#293)
  461. pinned::enabled = on;
  462. else if (id == "playlist.mixerRows") // round 190so (#294, kainproctor)
  463. mixerrows::shown = on;
  464. else if (id == "playlist.wideMeters") // round 190so (#295)
  465. widemeter::on = on;
  466. else if (id == "toolbar.meterValues") // round 190so (#294)
  467. toolbarextras::meterValues = on;
  468. else if (id == "toolbar.secondaryTime") // round 190so (#343)
  469. toolbarextras::secondaryTime = on;
  470. else if (id == "playlist.markerNumberKeys") // round 190so (#312)
  471. markerjump::numberKeys = on;
  472. else if (id == "general.emptyDoubleClick") // round 190so (#305)
  473. emptyworkspace::doubleClick = on;
  474. else if (id == "playlist.sliceEscape") // round 190st (#339)
  475. sliceextras::escapeCancels = on;
  476. else if (id == "playlist.sliceHoverLine") // round 190st (#340)
  477. sliceextras::hoverLine = on;
  478. else if (id == "playlist.fileMarkerHints") // round 190st (#316)
  479. filemarkers::hintsOn = on;
  480. else if (id == "playlist.stretchSpeeds") // round 190st (#314)
  481. clipwarp::showSpeeds = on;
  482. else if (id == "playlist.stretchGrip") // round 190st (#291)
  483. stretchgrip::patternOn = on;
  484. else if (id == "playlist.stretchGripOther")
  485. stretchgrip::otherOn = on;
  486. else if (id == "playlist.alwaysPianoRoll")
  487. patternclipopen::enabled() = on;
  488. else
  489. return false;
  490. if (onChanged)
  491. onChanged();
  492. if (id == "layout.trackOnly" && on)
  493. offerTracksForEveryInstrument();
  494. return true;
  495. }
  496. bool runAction (const std::string& id)
  497. {
  498. if (id == "playlist.wheelZones" || id == "editing.tempTools" || id == "playlist.midiDrop" || id == "layout.trackOnly" || id == "playlist.headerWidth"
  499. || id == "playlist.clipLanesFolded" || id == "controlBar.liveScale" // (round 190oo: CS O-3, O-5)
  500. || id == "simple.dropStrip" // (round 190qu)
  501. || id == "playlist.mixerRows" || id == "playlist.wideMeters" || id == "toolbar.meterValues" || id == "toolbar.secondaryTime") // (round 190so)
  502. return setExtra (id, ! extraOn (id).value_or (true));
  503. // round 190jq: the pointer-click switch itself (toolbar button, menu, key); on also shows its button
  504. if (id == "playlist.pointerClick")
  505. {
  506. pointerclick::setOn (! pointerclick::on);
  507. ui::postHint ({ tr ("Click on an empty spot selects and moves the song position (pointer click)"), pointerclick::on ? tr ("On") : tr ("Off"), false, false });
  508. if (onChanged)
  509. onChanged();
  510. return true;
  511. }
  512. // automation clips as lanes: the switch of the layout shown (Pattern / Clip-launch)
  513. if (id == "playlist.clipLanes")
  514. {
  515. const auto clipLaunch = layoutstyle::current() == layoutstyle::Style::clipLaunch;
  516. cliplanes::setShownIn (clipLaunch, ! cliplanes::shownIn (clipLaunch, false));
  517. if (onChanged)
  518. onChanged();
  519. return true;
  520. }
  521. if (id == "playlist.clipsToLanes") // #191.3
  522. {
  523. if (boundEngine == nullptr || ! autolanes::shown() || laneview::movableClips (boundEngine->getSong()).empty())
  524. return true;
  525. int moved = 0;
  526. boundEngine->editSong ([&moved] (Song& s) { moved = laneview::clipsToLanes (s); });
  527. ui::postHint ({ tr ("{0} automation clips moved into their tracks' lanes (Edit › Undo takes it back)", { juce::String (moved) }), {} }, 3000);
  528. if (onChanged)
  529. onChanged();
  530. return true;
  531. }
  532. if (id == "layout.convertTrackOnly") // round 190qu (Discord 11-24)
  533. {
  534. if (layoutstyle::current() == layoutstyle::Style::pattern)
  535. convertToTrackOnly();
  536. return true;
  537. }
  538. if (id == "playlist.lanesToClips") // round 190qu (Discord 11-24): the way back, every lane of the tracks a clip again
  539. {
  540. if (boundEngine == nullptr || laneview::laneCount (boundEngine->getSong()) == 0)
  541. return true;
  542. int made = 0;
  543. boundEngine->editSong ([&made] (Song& s) { made = autolanes::lanesToClips (s); });
  544. ui::postHint ({ tr ("{0} automation lanes turned back into clips (Edit › Undo takes it back)", { juce::String (made) }), {} }, 3000);
  545. if (onChanged)
  546. onChanged();
  547. return true;
  548. }
  549. return false;
  550. }
  551. void addPlaylistMenuItems (const std::function<void (const char*, const juce::String&, bool, bool)>& add)
  552. {
  553. // (#191.3: shown while the lanes are on, with how many clips it would move)
  554. if (autolanes::shown())
  555. {
  556. const auto movable = boundEngine != nullptr ? (int) laneview::movableClips (boundEngine->getSong()).size() : 0;
  557. add ("playlist.clipsToLanes", tr ("Move automation clips into their tracks' lanes ({0})", { juce::String (movable) }), movable > 0, false);
  558. // round 190qu (Discord 11-24): and back
  559. const auto lanes = boundEngine != nullptr ? laneview::laneCount (boundEngine->getSong()) : 0;
  560. add ("playlist.lanesToClips", tr ("Turn automation lanes back into clips ({0})", { juce::String (lanes) }), lanes > 0, false);
  561. }
  562. // round 190qu (Discord 11-24): the Simple layout's drop strip once the project has tracks
  563. if (layoutstyle::current() == layoutstyle::Style::simple)
  564. add ("simple.dropStrip", tr ("Show the drop strip under the tracks when the project has tracks"), true, simpletracks::dropStripAlways);
  565. // round 190jq (issues #191.3, #191, #164)
  566. {
  567. const auto style = layoutstyle::current();
  568. add ("playlist.clipLanes", tr ("Automation clips as lanes under their tracks"), style != layoutstyle::Style::simple,
  569. cliplanes::shownIn (style == layoutstyle::Style::clipLaunch, style == layoutstyle::Style::simple));
  570. if (style == layoutstyle::Style::clipLaunch) // round 190oo (CS O-3, LYNX extra: Live folds its automation lanes)
  571. add ("playlist.clipLanesFolded", tr ("Automation lanes start folded when a project opens (Clip-launch layout)"), true, cliplanes::foldedOnOpen);
  572. add ("playlist.pointerClick", tr ("Click on an empty spot selects and moves the song position (pointer click)"), style != layoutstyle::Style::simple, pointerclick::on);
  573. add ("playlist.headerWidth", tr ("Drag the track header column's right edge to widen it"), style != layoutstyle::Style::simple, headerwidth::draggable);
  574. }
  575. add ("playlist.wheelZones", tr ("Wheel: scroll over the track headers, zoom over the arrangement"), true, wheelzones::enabled());
  576. add ("editing.tempTools", tr ("Hold a tool key for a temporary tool"), true, temptool::enabled());
  577. add ("playlist.midiDrop", tr ("MIDI files dropped on the Playlist become pattern clips"), true, mididrop::playlistDrop());
  578. }
  579. // --- #191.1 temporary tools -------------------------------------------------------------------------------------------
  580. TempToolHold& tempTools()
  581. {
  582. static TempToolHold instance;
  583. return instance;
  584. }
  585. void TempToolHold::toolKey (temptool::Editor editor, int keyCode, EditTool before, EditTool chosen, std::function<EditTool()> now,
  586. std::function<void (EditTool)> back)
  587. {
  588. if (keyCode == 0 || ! temptool::enabled())
  589. {
  590. hold.cancel(); // a tool picked by a menu or a click ends any hold: that choice stays
  591. stopTimer();
  592. toolNow = nullptr;
  593. restore = nullptr;
  594. return;
  595. }
  596. if (hold.press (editor, keyCode, before, chosen, juce::Time::getMillisecondCounter()))
  597. {
  598. toolNow = std::move (now);
  599. restore = std::move (back);
  600. startTimerHz (30); // (only while a key is held)
  601. }
  602. }
  603. void TempToolHold::releaseNow (std::uint32_t now)
  604. {
  605. stopTimer();
  606. EditTool back = EditTool::pencil;
  607. const auto current = toolNow ? toolNow() : hold.held;
  608. if (hold.release (now, current, back) && restore)
  609. restore (back);
  610. toolNow = nullptr;
  611. restore = nullptr;
  612. }
  613. void TempToolHold::timerCallback()
  614. {
  615. if (! hold.active())
  616. {
  617. stopTimer();
  618. return;
  619. }
  620. if (juce::ModifierKeys::currentModifiers.isAnyMouseButtonDown())
  621. hold.mouseUsed();
  622. if (! juce::KeyPress::isKeyCurrentlyDown (hold.keyCode))
  623. releaseNow (juce::Time::getMillisecondCounter());
  624. }
  625. // --- #191.2 MIDI files ------------------------------------------------------------------------------------------------
  626. bool isMidiFile (const juce::String& path)
  627. {
  628. const juce::File f (path);
  629. return f.hasFileExtension ("mid;midi;smf") && ! f.isDirectory();
  630. }
  631. bool anyMidiFile (const juce::StringArray& files)
  632. {
  633. return std::any_of (files.begin(), files.end(), [] (const juce::String& f) { return isMidiFile (f); });
  634. }
  635. namespace
  636. {
  637. juce::String refusal (const std::string& error, const juce::File& file)
  638. {
  639. if (error == "audio track")
  640. return tr ("{0}: an audio track can't hold MIDI. Drop it on an instrument track or an empty track", { file.getFileName() });
  641. if (error == "no notes")
  642. return tr ("{0} has no notes", { file.getFileName() });
  643. return tr ("{0}: no track free for it", { file.getFileName() });
  644. }
  645. // `apply` makes the edit; `placed` hears each real (not trial) result, to move on to the next place
  646. template <typename Apply, typename Placed>
  647. bool dropEach (AudioEngine& engine, const juce::StringArray& files, Apply&& apply, Placed&& placed)
  648. {
  649. bool any = false;
  650. for (const auto& path : files)
  651. {
  652. if (! isMidiFile (path))
  653. continue;
  654. const juce::File file (path);
  655. juce::String error;
  656. const auto midi = MidiFileIo::parseFile (file, error);
  657. if (! midi)
  658. {
  659. ui::postNotice ({ tr ("{0} could not be read: {1}", { file.getFileName(), error }), {} }, 4000);
  660. continue;
  661. }
  662. const auto name = file.getFileNameWithoutExtension().toStdString();
  663. // (a refused drop leaves no undo step: tried on a copy first)
  664. auto trial = engine.getSong();
  665. if (const auto check = apply (trial, *midi, name); ! check.ok)
  666. {
  667. ui::postNotice ({ refusal (check.error, file), {} }, 4000);
  668. continue;
  669. }
  670. mididrop::Result r;
  671. engine.editSong ([&] (Song& s) { r = apply (s, *midi, name); });
  672. any = any || r.ok;
  673. if (r.ok)
  674. placed (r);
  675. if (r.ok)
  676. ui::postHint ({ tr ("MIDI file {0}: a clip of pattern \"{1}\"", { file.getFileName(), juce::String::fromUTF8 (name.c_str()) }), {} }, 2500);
  677. }
  678. return any;
  679. }
  680. } // namespace
  681. bool dropMidiOnPlaylist (AudioEngine& engine, const juce::StringArray& files, int track, std::int64_t start, bool liveStyle)
  682. {
  683. liveStyle = liveStyle || trackonly::active(); // (Track-only mode: one instrument per track, as Live's arrangement)
  684. int next = track;
  685. return dropEach (
  686. engine, files,
  687. [&next, start, liveStyle] (Song& s, const midiimport::ParsedMidi& midi, const std::string& name) {
  688. return mididrop::dropOnPlaylist (s, midi, name, next, start, liveStyle);
  689. },
  690. [&next] (const mididrop::Result& r) {
  691. if (! r.tracks.empty())
  692. next = *std::max_element (r.tracks.begin(), r.tracks.end()) + 1; // (several files: one below the other)
  693. });
  694. }
  695. bool dropMidiOnSlot (AudioEngine& engine, const juce::StringArray& files, int track, int scene)
  696. {
  697. int next = scene;
  698. return dropEach (
  699. engine, files,
  700. [&next, track] (Song& s, const midiimport::ParsedMidi& midi, const std::string& name) { return mididrop::dropOnSlot (s, midi, name, track, next); },
  701. [&next] (const mididrop::Result&) { ++next; });
  702. }
  703. // --- #191.6 takes and recorded envelopes -----------------------------------------------------------------------------
  704. void showPickerItemMenu (AudioEngine& engine, ClipKind kind, int index, std::function<void()> edited)
  705. {
  706. const auto& song = engine.getSong();
  707. juce::PopupMenu menu;
  708. if (kind == ClipKind::audio && index >= 0 && index < (int) song.channels.size())
  709. {
  710. const auto name = juce::String::fromUTF8 (song.channels[(std::size_t) index].name.c_str());
  711. menu.addSectionHeader (name);
  712. menu.addItem (tr ("Delete (its clips and its channel)"), [&engine, index, edited] {
  713. engine.editSong ([index] (Song& s) { takecleanup::deleteAudioClip (s, index); });
  714. if (edited)
  715. edited();
  716. });
  717. }
  718. else if (kind == ClipKind::automation && index >= 0 && index < (int) song.automations.size())
  719. {
  720. const auto name = juce::String::fromUTF8 (song.automations[(std::size_t) index].name.c_str());
  721. menu.addSectionHeader (name);
  722. const auto uses = takecleanup::automationUses (song, index);
  723. menu.addItem (uses > 0 ? tr ("Delete (with its {0} clips)", { juce::String (uses) }) : tr ("Delete"), [&engine, index, edited] {
  724. engine.editSong ([index] (Song& s) { takecleanup::deleteAutomation (s, index); });
  725. if (edited)
  726. edited();
  727. });
  728. }
  729. else
  730. return;
  731. menu.showMenuAsync (juce::PopupMenu::Options().withMousePosition());
  732. }
  733. void addPickerCleanupItems (juce::PopupMenu& menu, AudioEngine& engine, std::function<void()> edited)
  734. {
  735. const auto& song = engine.getSong();
  736. const auto audio = (int) pltracks::unusedAudioClipChannels (song).size();
  737. const auto automations = (int) takecleanup::unusedAutomations (song).size();
  738. menu.addItem (tr ("Purge unused audio clips") + " (" + juce::String (audio) + ")", audio > 0, false, [&engine, edited] {
  739. engine.editSong ([] (Song& s) { pltracks::purgeUnusedAudioClips (s); });
  740. if (edited)
  741. edited();
  742. });
  743. menu.addItem (tr ("Delete unused automation clips ({0})", { juce::String (automations) }), automations > 0, false, [&engine, edited] {
  744. engine.editSong ([] (Song& s) { takecleanup::deleteUnusedAutomations (s); });
  745. if (edited)
  746. edited();
  747. });
  748. }
  749. void addBrowserDeleteItem (juce::PopupMenu& menu, AudioEngine& engine, bool automation, int index)
  750. {
  751. const auto& song = engine.getSong();
  752. if (automation)
  753. {
  754. if (index < 0 || index >= (int) song.automations.size())
  755. return;
  756. menu.addSeparator();
  757. menu.addItem (tr ("Delete"), [&engine, index] { engine.editSong ([index] (Song& s) { takecleanup::deleteAutomation (s, index); }); });
  758. return;
  759. }
  760. if (index < 0 || index >= (int) song.channels.size() || song.channels[(std::size_t) index].instrument != InstrumentKind::audioClip)
  761. return;
  762. menu.addSeparator();
  763. menu.addItem (tr ("Delete (its clips and its channel)"), [&engine, index] {
  764. engine.editSong ([index] (Song& s) { takecleanup::deleteAudioClip (s, index); });
  765. });
  766. }
  767. } // namespace lynx::workflowextras