feat: split MIDI clips nondestructively with source-relative note slices
This commit is contained in:
parent
4c855ee5d7
commit
3c202cbfdc
8 changed files with 51 additions and 9 deletions
|
|
@ -349,7 +349,7 @@ MainWindow::MainWindow(bool prompt_unsaved,const char *configuration)
|
|||
menu->add("Edit/Markers/Remove at cursor",0,[](Fl_Widget *,void *c){static_cast<SequencerWidget *>(c)->marker(nullptr);},sequencer_);
|
||||
menu->add("Edit/Select all clips",0,[](Fl_Widget *,void *c){static_cast<SequencerWidget *>(c)->select_all_clips();},sequencer_);
|
||||
menu->add("Edit/Duplicate clip",FL_CTRL+'d',[](Fl_Widget *, void *c) { (void)static_cast<SequencerWidget *>(c)->duplicate_selection(); },sequencer_);
|
||||
menu->add("Edit/Split audio at cursor", 0, [](Fl_Widget *, void *c) { (void)static_cast<SequencerWidget *>(c)->split_selection(); }, sequencer_);
|
||||
menu->add("Edit/Split clip at cursor", 0, [](Fl_Widget *, void *c) { (void)static_cast<SequencerWidget *>(c)->split_selection(); }, sequencer_);
|
||||
menu->add("Edit/Audio clip gain and fades", 0, [](Fl_Widget *, void *c) { static_cast<SequencerWidget *>(c)->audio_properties_dialog(); }, sequencer_);
|
||||
menu->add("Edit/Rename clip or track",FL_F+2,[](Fl_Widget *, void *c) {
|
||||
const char *name = fl_input("Name (1..63 UTF-8 bytes)",""); if (name) (void)static_cast<SequencerWidget *>(c)->rename_selection(name);
|
||||
|
|
|
|||
|
|
@ -435,7 +435,7 @@ int SequencerWidget::handle(int event)
|
|||
mode_ = 0;
|
||||
Fl_Menu_Item items[6]{};
|
||||
items[0].text = "Duplicate clip (Ctrl+D)"; items[1].text = "Rename (F2)"; items[2].text = "Delete (undoable)";
|
||||
items[3].text = "Split audio at cursor (S)"; items[4].text = "Audio gain and fades (A)";
|
||||
items[3].text = "Split clip at cursor (S)"; items[4].text = "Audio gain and fades (A)";
|
||||
const Fl_Menu_Item *picked = items->popup(Fl::event_x(),Fl::event_y());
|
||||
if (picked == items) duplicate_selection();
|
||||
else if (picked == items+1) { const char *name = fl_input("Name (1..63 UTF-8 bytes)",""); if (name) rename_selection(name); }
|
||||
|
|
@ -703,7 +703,10 @@ xtc_result SequencerWidget::split_selection()
|
|||
uint64_t right;
|
||||
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) {
|
||||
xtc_clip_info c{};result=xtc_project_find_clip(project_,clip_,&c);
|
||||
if(result==XTC_OK)result=c.midi ? xtc_project_split_midi(project_,clip_,split_tick,&right) : xtc_project_split_audio(project_,clip_,split_tick,&right);
|
||||
}
|
||||
if (result == XTC_OK) {clip_ = right;selection_.clear();}
|
||||
changed(result);
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -219,3 +219,17 @@ xtc_result xtc_project_duplicate_track(xtc_project *p,uint64_t track,const char
|
|||
if(r==XTC_OK){publish(p,copy);*out=id;}
|
||||
xtc_project_destroy(copy);return r;
|
||||
}
|
||||
|
||||
xtc_result xtc_project_split_midi(xtc_project *p,uint64_t clip,uint64_t tick,uint64_t *out)
|
||||
{
|
||||
xtc_clip_info c;xtc_project *copy=NULL;uint64_t id=0,left;xtc_result r;
|
||||
if(!p || !out)return XTC_ERR_INVALID_ARGUMENT;
|
||||
r=xtc_project_find_clip(p,clip,&c);if(r!=XTC_OK)return r;
|
||||
if(!c.midi || tick<=c.start_tick || tick>=c.start_tick+c.length_tick)return XTC_ERR_INVALID_ARGUMENT;
|
||||
left=tick-c.start_tick;r=xtc_project_clone(p,©);if(r!=XTC_OK)return r;
|
||||
r=xtc_project_duplicate_clip(copy,clip,c.track_id,c.start_tick,&id);
|
||||
if(r==XTC_OK)r=xtc_project_edit_clip(copy,id,c.track_id,tick,c.length_tick-left,c.offset_tick+left);
|
||||
if(r==XTC_OK)r=xtc_project_edit_clip(copy,clip,c.track_id,c.start_tick,left,c.offset_tick);
|
||||
if(r==XTC_OK){publish(p,copy);*out=id;}
|
||||
xtc_project_destroy(copy);return r;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue