feat: copy and paste arrangement phrases with independent clip snapshots
This commit is contained in:
parent
7379545ced
commit
b60501f317
9 changed files with 110 additions and 4 deletions
|
|
@ -322,6 +322,8 @@ MainWindow::MainWindow(bool prompt_unsaved,const char *configuration)
|
|||
Fl_Group::current(parent);
|
||||
menu->add("Edit/Nudge selection left",0,[](Fl_Widget *,void *c){static_cast<SequencerWidget *>(c)->nudge_selection(-1);},sequencer_);
|
||||
menu->add("Edit/Nudge selection right",0,[](Fl_Widget *,void *c){static_cast<SequencerWidget *>(c)->nudge_selection(1);},sequencer_);
|
||||
menu->add("Edit/Copy clips",0,[](Fl_Widget *,void *c){static_cast<SequencerWidget *>(c)->copy_selection();},sequencer_);
|
||||
menu->add("Edit/Paste clips at cursor",0,[](Fl_Widget *,void *c){static_cast<SequencerWidget *>(c)->paste_selection();},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_);
|
||||
|
|
|
|||
|
|
@ -490,6 +490,8 @@ int SequencerWidget::handle(int event)
|
|||
if (Fl::event_key() == 'a') { audio_properties_dialog(); return 1; }
|
||||
}
|
||||
if(event==FL_KEYDOWN && !Fl::event_state(FL_CTRL|FL_ALT|FL_SHIFT) && (Fl::event_key()==FL_Left || Fl::event_key()==FL_Right)) {nudge_selection(Fl::event_key()==FL_Left ? -1 : 1);return 1;}
|
||||
if(event==FL_KEYDOWN && Fl::event_state(FL_CTRL) && Fl::event_key()=='c'){copy_selection();return 1;}
|
||||
if(event==FL_KEYDOWN && Fl::event_state(FL_CTRL) && Fl::event_key()=='v'){paste_selection();return 1;}
|
||||
if (event == FL_KEYDOWN && Fl::event_state(FL_CTRL) && Fl::event_key() == 'a') {select_all_clips();return 1;}
|
||||
if (event == FL_KEYDOWN && Fl::event_state(FL_CTRL) && Fl::event_key() == 'd') { duplicate_selection(); return 1; }
|
||||
if (event == FL_KEYDOWN && Fl::event_key() == FL_F+2) {
|
||||
|
|
@ -553,6 +555,24 @@ xtc_result SequencerWidget::transform_selection(xtc_clip_operation op,int64_t am
|
|||
}
|
||||
changed(r);return r;
|
||||
}
|
||||
xtc_result SequencerWidget::copy_selection()
|
||||
{
|
||||
auto ids=selected_clips();xtc_clipboard *copy=nullptr;
|
||||
xtc_result r=xtc_clipboard_create(project_,ids.data(),ids.size(),©);
|
||||
if(r==XTC_OK)clipboard_.reset(copy);
|
||||
else fl_alert("Copy unchanged: %s",xtc_result_string(r));
|
||||
return r;
|
||||
}
|
||||
xtc_result SequencerWidget::paste_selection()
|
||||
{
|
||||
const uint64_t start=cursor_,track=track_;
|
||||
std::vector<uint64_t> output(xtc_clipboard_count(clipboard_.get()));
|
||||
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();}
|
||||
changed(r);return r;
|
||||
}
|
||||
xtc_result SequencerWidget::nudge_selection(int direction)
|
||||
{
|
||||
return transform_selection(XTC_CLIPS_MOVE,direction<0 ? -static_cast<int64_t>(grid_) : static_cast<int64_t>(grid_));
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ class SequencerWidget : public Fl_Group {
|
|||
bool clip_selected(uint64_t clip) const;
|
||||
std::vector<uint64_t> selected_clips() const;
|
||||
xtc_result transform_selection(xtc_clip_operation operation,int64_t amount);
|
||||
xtc_result copy_selection();
|
||||
xtc_result paste_selection();
|
||||
xtc_result nudge_selection(int direction);
|
||||
xtc_result duplicate_selection();
|
||||
xtc_result split_selection();
|
||||
|
|
@ -176,6 +178,7 @@ class SequencerWidget : public Fl_Group {
|
|||
};
|
||||
std::vector<Wave> waves_;
|
||||
std::vector<uint64_t> selection_;
|
||||
std::unique_ptr<xtc_clipboard,decltype(&xtc_clipboard_destroy)> clipboard_{nullptr,xtc_clipboard_destroy};
|
||||
void draw_waveform(const xtc_clip_info &clip, int left, int top);
|
||||
xtc_project *project_;
|
||||
Seek seek_;
|
||||
|
|
|
|||
|
|
@ -38,3 +38,53 @@ xtc_result xtc_project_transform_clips(xtc_project *p,const uint64_t *ids,size_t
|
|||
if(r==XTC_OK){publish(p,copy);if(out_ids)memcpy(out_ids,output,count*sizeof(*output));}
|
||||
xtc_project_destroy(copy);return r;
|
||||
}
|
||||
|
||||
struct xtc_clipboard {xtc_project *source;size_t count,first_track;uint64_t begin,ids[XTC_PROJECT_MAX_CLIPS];};
|
||||
void xtc_clipboard_destroy(xtc_clipboard *b)
|
||||
{
|
||||
if(b){xtc_project_destroy(b->source);free(b);}
|
||||
}
|
||||
size_t xtc_clipboard_count(const xtc_clipboard *b){return b ? b->count : 0;}
|
||||
xtc_result xtc_clipboard_create(const xtc_project *p,const uint64_t *ids,size_t count,xtc_clipboard **out)
|
||||
{
|
||||
xtc_clipboard *b;size_t i,j;xtc_result r;
|
||||
if(!out)return XTC_ERR_INVALID_ARGUMENT;
|
||||
r=selection_valid(p,ids,count);if(r!=XTC_OK)return r;
|
||||
b=calloc(1,sizeof(*b));if(!b)return XTC_ERR_OUT_OF_MEMORY;
|
||||
r=xtc_project_clone(p,&b->source);
|
||||
if(r!=XTC_OK){free(b);return r;}
|
||||
b->count=count;b->begin=XTC_PROJECT_MAX_TICK;b->first_track=p->track_count;
|
||||
memcpy(b->ids,ids,count*sizeof(*ids));
|
||||
for(i=0;i<count;++i){xtc_clip_info c;xtc_project_find_clip(p,ids[i],&c);
|
||||
if(c.start_tick<b->begin)b->begin=c.start_tick;
|
||||
for(j=0;j<p->track_count;++j)if(p->tracks[j].id==c.track_id && j<b->first_track)b->first_track=j;
|
||||
}
|
||||
*out=b;return XTC_OK;
|
||||
}
|
||||
xtc_result xtc_clipboard_paste(const xtc_clipboard *b,xtc_project *p,uint64_t track,uint64_t start,uint64_t *out_ids)
|
||||
{
|
||||
xtc_project *copy=NULL;size_t base,i,j,k;uint64_t output[XTC_PROJECT_MAX_CLIPS];xtc_result r;
|
||||
if(!b || !p || start>XTC_PROJECT_MAX_TICK)return XTC_ERR_INVALID_ARGUMENT;
|
||||
for(base=0;base<p->track_count;++base)if(p->tracks[base].id==track)break;
|
||||
if(base==p->track_count)return XTC_ERR_NOT_FOUND;
|
||||
r=xtc_project_clone(p,©);
|
||||
for(i=0;r==XTC_OK && i<b->count;++i) {
|
||||
xtc_clip_info c;uint64_t id,target;xtc_project_find_clip(b->source,b->ids[i],&c);
|
||||
for(j=0;j<b->source->track_count;++j)if(b->source->tracks[j].id==c.track_id)break;
|
||||
k=base+j-b->first_track;
|
||||
if(k>=copy->track_count){r=XTC_ERR_NOT_FOUND;break;}
|
||||
if(copy->tracks[k].is_bus){r=XTC_ERR_INVALID_STATE;break;}
|
||||
if(c.start_tick-b->begin>XTC_PROJECT_MAX_TICK-start){r=XTC_ERR_INVALID_ARGUMENT;break;}
|
||||
target=start+c.start_tick-b->begin;
|
||||
r=xtc_project_add_clip(copy,copy->tracks[k].id,c.name,target,c.length_tick,&id);
|
||||
if(r!=XTC_OK)break;
|
||||
c.id=id;c.track_id=copy->tracks[k].id;c.start_tick=target;copy->clips[copy->clip_count-1]=c;output[i]=id;
|
||||
if(c.midi)r=xtc_project_ensure_midi_route(copy);
|
||||
for(j=0;r==XTC_OK && j<b->source->note_count;++j)if(b->source->notes[j].clip_id==b->ids[i]) {
|
||||
xtc_note_info n=b->source->notes[j];uint64_t note;
|
||||
r=xtc_project_add_note(copy,id,n.start_tick,n.length_tick,n.pitch,n.velocity,n.channel,¬e);
|
||||
}
|
||||
}
|
||||
if(r==XTC_OK){publish(p,copy);if(out_ids)memcpy(out_ids,output,b->count*sizeof(*output));}
|
||||
xtc_project_destroy(copy);return r;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue