SimpleWorkflow.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #pragma once
  2. // The Simple workflow (View › Layout style, round 184a; design: /mnt/e/lynx-work/simple184a/DESIGN.md): one window with
  3. // the tracks and the timeline. This object owns the style's own parts: slice S3's New track chooser (the home screen of
  4. // an empty project and the "Add track" button in the Playlist's title bar) and, in later slices, the dock for the
  5. // selected track and the Finish dock. MainComponent makes it the first time the style is chosen and keeps it for the
  6. // session, so in Pattern and Clip-launch workflow nothing of it exists (the selftest checks `instances` stays 0).
  7. #include <atomic>
  8. #include <functional>
  9. #include <memory>
  10. #include <juce_gui_basics/juce_gui_basics.h>
  11. #include "core/SimpleTracks.h"
  12. namespace lynx
  13. {
  14. class AudioEngine;
  15. class SimpleWorkflow
  16. {
  17. public:
  18. // What the workflow needs from the main window
  19. struct Host
  20. {
  21. std::function<void (juce::Component*)> setOverlay; // shows a component over the Playlist area (nullptr: none)
  22. std::function<void()> showKeys; // an instrument was added from the chooser: the on-screen keyboard
  23. std::function<void (juce::Component*, int)> setTitleAccessory; // the Playlist title bar's accessory (nullptr: none)
  24. std::function<void()> showLoops; // the sample browser, to drag loops onto the timeline
  25. // round 190ch: the Lyrics / Notes panel (the main window's, the same in every layout), Reference match, and a
  26. // new project from the "Start from" list
  27. std::function<void()> toggleLyrics;
  28. std::function<void()> showReferenceMatch;
  29. std::function<void (Song song)> startFrom;
  30. std::function<void (int track)> trackAdded; // a track was added (select it, scroll to it)
  31. // round 190t
  32. std::function<juce::File()> sampleFolder; // where the Sampler tile's file dialog starts (the Browser's samples)
  33. std::function<void (int format)> exportAudio; // the Export window on one format (0 WAV, 1 MP3): the Finish dock
  34. std::function<void()> exportOtherApps; // File › Export › For other apps
  35. std::function<juce::String()> saveStatus; // "Backed up 2 min ago", "Not saved yet"...: beside the title tools
  36. std::function<void (juce::Component*, int)> setSideDock; // the dock on the right of the Playlist (nullptr: none)
  37. };
  38. SimpleWorkflow (AudioEngine& engine, Host host);
  39. ~SimpleWorkflow();
  40. SimpleWorkflow (const SimpleWorkflow&) = delete;
  41. SimpleWorkflow& operator= (const SimpleWorkflow&) = delete;
  42. // The style was chosen / left: the title bar's Add track button comes and goes, and an empty project opens on the
  43. // chooser.
  44. void entered();
  45. void left();
  46. // The song changed (MainComponent's change callback, only while the style is on): a new or emptied project shows the
  47. // chooser again, unless it was closed for this project.
  48. void songChanged();
  49. void showChooser();
  50. void hideChooser();
  51. bool isChooserShowing() const noexcept;
  52. // "Start from" (round 190ch, ui/StartFromPanel.h): LYNX's demo song and the templates, with a preview, over the
  53. // Playlist like the chooser
  54. void showStartFrom();
  55. void hideStartFrom();
  56. bool isStartFromShowing() const noexcept;
  57. juce::Component* startFromForSnapshot(); // (made and shown if needed)
  58. // Adds a track built from `request` (one undo step): arms an audio track's insert, selects an instrument's channel,
  59. // hides the chooser. False (and a message) when it can't be added.
  60. bool add (simpletracks::Request request);
  61. // Files dropped on the timeline below the tracks (slice S4): one new track each (MIDI: one per MIDI track), from `tick`.
  62. void dropFiles (const juce::StringArray& files, std::int64_t tick);
  63. // The Finish dock (slice S8, ui/FinishDock.h): the Master looks, on the right of the Playlist
  64. void showFinish();
  65. void hideFinish();
  66. bool isFinishShowing() const noexcept;
  67. // --simpleshot: the chooser's two pages, as drawn
  68. juce::Component* chooserForSnapshot();
  69. void showStarterPageForSnapshot();
  70. // round 190t: a click on the starter page's button `index` (0 = Empty grid), and the status line showing `text`
  71. void clickStarterForSnapshot (int index);
  72. void setStatusForSnapshot (const juce::String& text);
  73. // how many were ever made in this process (the "nothing exists in Pattern workflow" check)
  74. static inline std::atomic<int> instances { 0 };
  75. private:
  76. class Chooser;
  77. void closeByHand(); // the chooser was closed (✕, Esc, a click outside): it stays closed for this project
  78. void addDefaultInstrument(); // the Instrument tile: LYNX's synth on a new track, ready to play
  79. void chooseInstrument (juce::Component& tile);
  80. void chooseSample();
  81. void importFiles();
  82. void addFiles (const juce::Array<juce::File>& files, std::int64_t start);
  83. void addDrums (const std::string& genre, bool steps, bool useTempo);
  84. void addAudio (simpletracks::Kind kind);
  85. AudioEngine& engine;
  86. Host host;
  87. bool active = false;
  88. std::string dismissedFor; // the project (Song::projectId) whose chooser was closed by hand
  89. std::unique_ptr<juce::Component> startFrom, lyricsButton; // round 190ch
  90. std::unique_ptr<Chooser> chooser;
  91. std::unique_ptr<juce::Component> addButton, finishButton, titleTools;
  92. std::unique_ptr<juce::Component> finishDock;
  93. std::unique_ptr<juce::FileChooser> fileChooser;
  94. juce::File sampleFolder; // where the last sample for a Sampler track came from (this session)
  95. };
  96. } // namespace lynx