Phase 11: Complete and verify the minimal music-making workflow

This commit is contained in:
Johannes Findeisen 2026-10-27 03:25:04 +01:00
commit 461689dd44
12 changed files with 463 additions and 25 deletions

View file

@ -77,12 +77,19 @@ MainWindow::MainWindow(bool prompt_unsaved)
menu->add("Audio/Stop engine", FL_F + 8, stop_callback, this);
menu->add("Audio/Reconnect", FL_F + 6, reconnect_callback, this);
menu->add("Audio/Pause", FL_F + 7, [](Fl_Widget *, void *c) {
(void)static_cast<MainWindow *>(c)->pause_playback();
}, this);
menu->add("Audio/Return to start", FL_Home, [](Fl_Widget *, void *c) {
(void)static_cast<MainWindow *>(c)->return_to_start();
}, this);
play_ = new Fl_Button(12, 40, 80, 30, "Play");
play_->callback(play_callback, this);
play_->tooltip("Start the audio engine (F5 or Space). Play audio clips and the modular graph.");
stop_ = new Fl_Button(100, 40, 80, 30, "Stop");
stop_->callback(stop_callback, this);
stop_->tooltip("Stop the audio engine (F8 or Space).");
stop_->tooltip("Stop playback at its current position; finalize recording (F8 or Space).");
auto *reconnect = new Fl_Button(188, 40, 110, 30, "Reconnect");
reconnect->callback(reconnect_callback, this);
reconnect->tooltip("Close and reopen JACK, leaving the engine stopped (F6).");
@ -92,12 +99,23 @@ MainWindow::MainWindow(bool prompt_unsaved)
auto *panic = new Fl_Button(404, 40, 70, 30, "Panic");
panic->callback(panic_callback, this);
panic->tooltip("Silence held instrument notes (F9).");
indicator_ = new Fl_Box(482, 40, 506, 30, "Audio: disconnected");
pause_ = new Fl_Button(482, 40, 70, 30, "Pause");
pause_->callback([](Fl_Widget *, void *c) {
(void)static_cast<MainWindow *>(c)->pause_playback();
}, this);
pause_->tooltip("Pause at the current sample position (F7). Play resumes; recording uses Stop.");
home_ = new Fl_Button(560, 40, 100, 30, "To start");
home_->callback([](Fl_Widget *, void *c) {
(void)static_cast<MainWindow *>(c)->return_to_start();
}, this);
home_->tooltip("Stop and return to the project beginning (Home). Unavailable while recording.");
indicator_ = new Fl_Box(668, 40, 320, 30, "Audio: disconnected");
indicator_->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
indicator_->labelfont(FL_BOLD);
auto *hint = new Fl_Box(12, 78, 976, 24,
"Edit signal flow in Modular Graph. No hardware ports are connected automatically; Import "
"WAV clips or record JACK input; connect external ports explicitly.");
indicator_->labelsize(12);
auto *hint = new Fl_Box(12, 76, 976, 34,
"Start: Add track, Add MIDI clip, then Piano roll to draw notes; or Import WAV (Ctrl+I).\n"
"Play with F5. Connect JACK output/output_right to playback ports to hear audio.");
hint->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
hint->labelsize(12);
@ -115,7 +133,7 @@ MainWindow::MainWindow(bool prompt_unsaved)
piano->callback(piano_callback, this);
auto *timeline_hint =
new Fl_Box(20, 548, 956, 28,
"Import WAV (Ctrl+I) or Record. Drag body to move, edges to trim; ruler seeks while stopped.");
"Drag clips to move, edges to trim. Click the ruler while stopped to seek; Home returns to start.");
timeline_hint->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
timeline_hint->labelsize(12);
auto *timeline_scroll = new Fl_Scroll(20, 188, 956, 350);
@ -411,6 +429,39 @@ void MainWindow::stop_engine()
refresh_status();
}
xtc_result MainWindow::pause_playback()
{
xtc_result result = recorder_ || !ready_ ? XTC_ERR_INVALID_STATE : xtc_backend_stop(backend_);
if (result != XTC_OK)
report_error("Pause failed; use Stop to finish recording or Reconnect audio", result);
else
set_label(error_, "");
refresh_status();
return result;
}
xtc_result MainWindow::return_to_start()
{
if (recorder_) {
report_error("Stop recording before returning to start", XTC_ERR_INVALID_STATE);
return XTC_ERR_INVALID_STATE;
}
xtc_result result = XTC_OK;
if (ready_) {
result = xtc_backend_stop(backend_);
if (result == XTC_OK)
result = xtc_backend_seek(backend_, 0);
}
if (result != XTC_OK)
report_error("Return to start failed", result);
else {
sequencer_->position(0);
set_label(error_, "");
}
refresh_status();
return result;
}
/**
* @brief Closes and reopens the JACK backend, leaving the engine stopped.
*
@ -501,6 +552,14 @@ void MainWindow::refresh_status()
play_->activate();
else
play_->deactivate();
if (ready_ && running_ && !recorder_)
pause_->activate();
else
pause_->deactivate();
if (!recorder_)
home_->activate();
else
home_->deactivate();
if (can_record)
record_->activate();
else
@ -624,7 +683,7 @@ void MainWindow::view_callback(Fl_Widget *widget, void *view)
*/
void MainWindow::about_callback(Fl_Widget *, void *)
{
fl_message("%s %s\nModular audio workstation\nPhase 9: native C processors and Linux release preparation.",
fl_message("%s %s\nModular audio workstation\nPhase 11: create, arrange, save, reopen and play.",
XTC_PROJECT_NAME, XTC_VERSION_STRING);
}
@ -776,6 +835,7 @@ xtc_result MainWindow::install_project(xtc_project *candidate, bool reset_histor
xtc_midi_plan_destroy(offline_midi);
if (r != XTC_OK) {
xtc_audio_plan_destroy(offline);
refresh_status(); // A failed install may have stopped playback.
return r;
}
std::string issue = ready_ ? xtc_backend_asset_issue(backend_) : "";
@ -796,6 +856,8 @@ xtc_result MainWindow::install_project(xtc_project *candidate, bool reset_histor
graph_widget_->reset_layout();
graph_widget_->set_graph(xtc_project_graph(candidate));
sequencer_->set_project(candidate);
if (reset_history)
tabs_->value(tabs_->child(0));
dirty_ = false;
if (!issue.empty()) {
char text[640];
@ -837,6 +899,23 @@ xtc_result MainWindow::open_project(const char *path)
return r;
}
xtc_result MainWindow::new_project()
{
if (recorder_)
return XTC_ERR_INVALID_STATE;
xtc_project *candidate = nullptr;
xtc_result result = xtc_project_create(&candidate);
if (result == XTC_OK)
result = install_project(candidate);
if (result != XTC_OK)
xtc_project_destroy(candidate);
else {
path_.clear();
copy_label("xtc — Untitled");
}
return result;
}
/**
* @brief FLTK menu callback for the File/New, Open, Save, and Save As items.
*
@ -861,16 +940,7 @@ void MainWindow::file_callback(Fl_Widget *widget, void *context)
if (std::strcmp(action, "New") == 0) {
if (!window->discard_changes())
return;
xtc_project *candidate = nullptr;
r = xtc_project_create(&candidate);
if (r == XTC_OK)
r = window->install_project(candidate);
if (r != XTC_OK)
xtc_project_destroy(candidate);
else {
window->path_.clear();
window->copy_label("xtc — Untitled");
}
r = window->new_project();
} else {
bool open = std::strcmp(action, "Open") == 0;
if (open && !window->discard_changes())

View file

@ -145,6 +145,16 @@ class MainWindow : public Fl_Double_Window {
*/
xtc_result open_project(const char *path);
/** Creates a fresh untitled project; the File menu checks unsaved changes first.
* On failure the current document remains owned by the window. */
xtc_result new_project();
/** Stops playback, retaining its exact sample position. Recording must be
* finalized with Stop instead. Returns the backend failure, if any. */
xtc_result pause_playback();
/** Stops playback and seeks to zero. Refuses during recording. A failed
* stop/seek is reported without moving the displayed cursor to zero. */
xtc_result return_to_start();
private:
MixerWidget *mixer_ = nullptr;
std::unique_ptr<xtc_history, decltype(&xtc_history_destroy)> history_{nullptr, xtc_history_destroy};
@ -283,6 +293,8 @@ class MainWindow : public Fl_Double_Window {
Fl_Button *record_ = nullptr;
Fl_Button *play_ = nullptr;
Fl_Button *stop_ = nullptr;
Fl_Button *pause_ = nullptr;
Fl_Button *home_ = nullptr;
Fl_Box *indicator_ = nullptr;
Fl_Box *status_ = nullptr;
Fl_Box *error_ = nullptr;