feat: compare mixer A/B snapshots with undo and qualify modern editing workflows

This commit is contained in:
Johannes Findeisen 2026-11-06 00:25:23 +01:00
commit 1b668068de
14 changed files with 261 additions and 34 deletions

View file

@ -133,6 +133,10 @@ MainWindow::MainWindow(bool prompt_unsaved,const char *configuration)
menu->add("Edit/Redo alternate", FL_CTRL + 'y', history_callback, this);
menu->add("Audio/MIDI controller mapping", 0, control_map_callback, this);
menu->add("Audio/Panic", FL_F + 9, panic_callback, this);
menu->add("Edit/Mixer comparison/Capture A",0,[](Fl_Widget *,void *c){auto *w=static_cast<MainWindow *>(c);auto r=w->mix_snapshot(0,true);if(r!=XTC_OK)w->report_error("Mixer capture failed",r);},this);
menu->add("Edit/Mixer comparison/Recall A",0,[](Fl_Widget *,void *c){auto *w=static_cast<MainWindow *>(c);auto r=w->mix_snapshot(0,false);if(r!=XTC_OK)w->report_error("Mixer recall failed",r);},this);
menu->add("Edit/Mixer comparison/Capture B",0,[](Fl_Widget *,void *c){auto *w=static_cast<MainWindow *>(c);auto r=w->mix_snapshot(1,true);if(r!=XTC_OK)w->report_error("Mixer capture failed",r);},this);
menu->add("Edit/Mixer comparison/Recall B",0,[](Fl_Widget *,void *c){auto *w=static_cast<MainWindow *>(c);auto r=w->mix_snapshot(1,false);if(r!=XTC_OK)w->report_error("Mixer recall failed",r);},this);
menu->add("View/Commands",FL_CTRL+'p',[](Fl_Widget *,void *c){static_cast<MainWindow *>(c)->show_commands();},this);
menu->add("View/Fit song",FL_CTRL+'0',[](Fl_Widget *,void *c){static_cast<MainWindow *>(c)->fit_song();},this);
menu->add("View/Piano roll", FL_CTRL + '4', piano_callback, this);
@ -1374,8 +1378,10 @@ xtc_result MainWindow::install_project(xtc_project *candidate, bool reset_histor
piano_->set_project(candidate, UINT64_MAX);
project_.reset(candidate);
mixer_->set_project(candidate);
if (reset_history)
if (reset_history) {
history_.swap(new_history);
for(auto &snapshot:mix_snapshots_)snapshot.reset();
}
graph_widget_->reset_layout();
graph_widget_->set_graph(xtc_project_graph(candidate));
sequencer_->set_project(candidate);
@ -2539,6 +2545,20 @@ void MainWindow::inspector_callback(Fl_Widget *widget, void *context)
w->inspected_track_ = UINT64_MAX;
w->refresh_status();
}
xtc_result MainWindow::mix_snapshot(unsigned int slot,bool capture)
{
if(slot>=2)return XTC_ERR_INVALID_ARGUMENT;
if(capture) {
xtc_mix_snapshot *snapshot=nullptr;xtc_result r=xtc_mix_snapshot_create(project_.get(),&snapshot);
if(r==XTC_OK)mix_snapshots_[slot].reset(snapshot);
return r;
}
if(!mix_snapshots_[slot])return XTC_ERR_NOT_FOUND;
xtc_result r=before_arrangement_edit(this);
if(r==XTC_OK)r=xtc_mix_snapshot_recall(mix_snapshots_[slot].get(),project_.get());
if(r==XTC_OK)mark_dirty();
return r;
}
void MainWindow::show_commands()
{
std::vector<std::string> commands;

View file

@ -6,6 +6,7 @@
#include <vector>
#include <string>
#include "xtc/xtc_project.h"
#include "xtc/xtc_editing.h"
#include "xtc/xtc_backend.h"
#include "xtc/xtc_mixer.h"
#include "xtc/xtc_plugin.h"
@ -35,6 +36,7 @@ class MainWindow : public Fl_Double_Window {
xtc_result create_track(bool midi);
xtc_result set_tempo(unsigned int milli_bpm);
void show_commands();
xtc_result mix_snapshot(unsigned int slot,bool capture);
/* Reparent the existing controls on the UI thread; closing a panel docks it. */
void detach_editor(unsigned int index,bool detached); /* 0 sequencer, 1 graph */
void detach_piano(bool detached);
@ -207,6 +209,8 @@ class MainWindow : public Fl_Double_Window {
xtc_result return_to_start();
private:
using MixSnapshot=std::unique_ptr<xtc_mix_snapshot,decltype(&xtc_mix_snapshot_destroy)>;
MixSnapshot mix_snapshots_[2]{{nullptr,xtc_mix_snapshot_destroy},{nullptr,xtc_mix_snapshot_destroy}};
struct EditorPanel {
MainWindow *owner=nullptr;unsigned int index=0;
Fl_Group *page=nullptr,*content=nullptr,*placeholder=nullptr;

View file

@ -147,7 +147,7 @@ xtc_result SequencerWidget::add_track()
xtc_result r = xtc_project_add_track(project_, "Track", &id);
if (r == XTC_OK) {
track_ = id;
clip_ = UINT64_MAX;
clip_ = UINT64_MAX;selection_.clear();
}
changed(r);
return r;
@ -175,8 +175,7 @@ xtc_result SequencerWidget::add_region()
}
uint64_t id;
xtc_result r = xtc_project_add_clip(project_, track_, "Region (silent)", cursor_, new_clip_ticks, &id);
if (r == XTC_OK)
clip_ = id;
if (r == XTC_OK) {clip_ = id;selection_.clear();}
changed(r);
return r;
}
@ -197,8 +196,7 @@ xtc_result SequencerWidget::add_midi_clip()
}
if (r == XTC_OK)
r = xtc_project_add_midi_clip(project_, track_, cursor_, new_clip_ticks, &id);
if (r == XTC_OK)
clip_ = id;
if (r == XTC_OK) {clip_ = id;selection_.clear();}
}
changed(r);
return r;
@ -530,13 +528,15 @@ bool SequencerWidget::toggle_clip(uint64_t id)
if(selection_.empty() && clip_!=UINT64_MAX)selection_.push_back(clip_);
auto found=std::find(selection_.begin(),selection_.end(),id);
if(found==selection_.end())selection_.push_back(id);else selection_.erase(found);
clip_=selection_.empty() ? UINT64_MAX : selection_.back();track_=c.track_id;redraw();return true;
clip_=selection_.empty() ? UINT64_MAX : selection_.back();
if(clip_!=UINT64_MAX)xtc_project_find_clip(project_,clip_,&c);
track_=c.track_id;redraw();return true;
}
void SequencerWidget::select_all_clips()
{
selection_.clear();size_t tracks=0,clips=0;xtc_project_get_counts(project_,&tracks,&clips);
for(size_t i=0;i<clips;++i){xtc_clip_info c{};xtc_project_get_clip(project_,i,&c);selection_.push_back(c.id);}
if(!selection_.empty())clip_=selection_.back();
if(!selection_.empty()){xtc_clip_info c{};clip_=selection_.back();xtc_project_find_clip(project_,clip_,&c);track_=c.track_id;}
redraw();
}
xtc_result SequencerWidget::grid(uint64_t ticks)
@ -626,7 +626,7 @@ xtc_result SequencerWidget::paste_selection()
xtc_result r=output.empty() ? XTC_ERR_INVALID_STATE : XTC_OK;
if(r==XTC_OK && before_edit)r=before_edit(context_);
if(r==XTC_OK)r=xtc_clipboard_paste(clipboard_.get(),project_,track,start,output.data());
if(r==XTC_OK){selection_=output;clip_=selection_.back();}
if(r==XTC_OK){selection_=output;clip_=selection_.back();xtc_clip_info c{};xtc_project_find_clip(project_,clip_,&c);track_=c.track_id;}
changed(r);return r;
}
xtc_result SequencerWidget::nudge_selection(int direction)
@ -662,7 +662,7 @@ xtc_result SequencerWidget::split_selection()
const uint64_t split_tick = cursor_; // Stop/status refresh may move the playhead.
xtc_result result = before_edit ? before_edit(context_) : XTC_OK;
if (result == XTC_OK) result = xtc_project_split_audio(project_, clip_, split_tick, &right);
if (result == XTC_OK) clip_ = right;
if (result == XTC_OK) {clip_ = right;selection_.clear();}
changed(result);
return result;
}

View file

@ -178,3 +178,27 @@ xtc_result xtc_project_transform_midi(xtc_project *p,const uint64_t *ids,size_t
if(r==XTC_OK)publish(p,copy);
xtc_project_destroy(copy);return r;
}
struct xtc_mix_snapshot {size_t count;xtc_track_info tracks[XTC_PROJECT_MAX_TRACKS];};
void xtc_mix_snapshot_destroy(xtc_mix_snapshot *snapshot){free(snapshot);}
xtc_result xtc_mix_snapshot_create(const xtc_project *p,xtc_mix_snapshot **out)
{
xtc_mix_snapshot *snapshot;
if(!p || !out)return XTC_ERR_INVALID_ARGUMENT;
snapshot=calloc(1,sizeof(*snapshot));if(!snapshot)return XTC_ERR_OUT_OF_MEMORY;
snapshot->count=p->track_count;memcpy(snapshot->tracks,p->tracks,p->track_count*sizeof(*p->tracks));
*out=snapshot;return XTC_OK;
}
xtc_result xtc_mix_snapshot_recall(const xtc_mix_snapshot *snapshot,xtc_project *p)
{
xtc_project *copy=NULL;size_t i;xtc_result r;
if(!snapshot || !p)return XTC_ERR_INVALID_ARGUMENT;
if(snapshot->count!=p->track_count)return XTC_ERR_INVALID_STATE;
r=xtc_project_clone(p,&copy);
for(i=0;r==XTC_OK && i<snapshot->count;++i) {
const xtc_track_info *track=snapshot->tracks+i;
r=xtc_project_set_mix(copy,track->id,track->gain,track->pan,track->mute,track->solo);
}
if(r==XTC_OK)publish(p,copy);
xtc_project_destroy(copy);return r;
}