feat: repeat arrangement phrases with bounded atomic pattern copies

This commit is contained in:
Johannes Findeisen 2026-11-06 00:15:42 +01:00
commit ea9789b188
10 changed files with 70 additions and 4 deletions

View file

@ -322,6 +322,7 @@ 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/Repeat selected phrase...",0,[](Fl_Widget *,void *c){static_cast<SequencerWidget *>(c)->repeat_dialog();},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_);

View file

@ -555,6 +555,19 @@ xtc_result SequencerWidget::transform_selection(xtc_clip_operation op,int64_t am
}
changed(r);return r;
}
xtc_result SequencerWidget::repeat_selection(unsigned int copies)
{
auto ids=selected_clips();xtc_result r=before_edit ? before_edit(context_) : XTC_OK;
if(r==XTC_OK)r=xtc_project_repeat_clips(project_,ids.data(),ids.size(),copies);
changed(r);return r;
}
void SequencerWidget::repeat_dialog()
{
const char *input=fl_input("Additional phrase copies (1..1024)","3");if(!input)return;
char *end=nullptr;unsigned long copies=std::strtoul(input,&end,10);
if(end==input || *end || copies<1 || copies>1024){fl_alert("Enter a whole number from 1 to 1024.");return;}
repeat_selection(static_cast<unsigned int>(copies));
}
xtc_result SequencerWidget::copy_selection()
{
auto ids=selected_clips();xtc_clipboard *copy=nullptr;

View file

@ -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 repeat_selection(unsigned int copies);
void repeat_dialog();
xtc_result copy_selection();
xtc_result paste_selection();
xtc_result nudge_selection(int direction);

View file

@ -88,3 +88,24 @@ xtc_result xtc_clipboard_paste(const xtc_clipboard *b,xtc_project *p,uint64_t tr
if(r==XTC_OK){publish(p,copy);if(out_ids)memcpy(out_ids,output,b->count*sizeof(*output));}
xtc_project_destroy(copy);return r;
}
xtc_result xtc_project_repeat_clips(xtc_project *p,const uint64_t *ids,size_t count,unsigned int copies)
{
xtc_project *copy=NULL;size_t i;unsigned int k;uint64_t begin=XTC_PROJECT_MAX_TICK,end=0,span;
xtc_result r=selection_valid(p,ids,count);if(r!=XTC_OK)return r;
if(!copies || copies>XTC_PROJECT_MAX_CLIPS)return XTC_ERR_INVALID_ARGUMENT;
if(count>(XTC_PROJECT_MAX_CLIPS-p->clip_count)/copies)return XTC_ERR_CAPACITY;
for(i=0;i<count;++i){xtc_clip_info c;xtc_project_find_clip(p,ids[i],&c);
if(c.start_tick<begin)begin=c.start_tick;
if(c.start_tick+c.length_tick>end)end=c.start_tick+c.length_tick;
}
span=end-begin;
if(span>(XTC_PROJECT_MAX_TICK-end)/copies)return XTC_ERR_INVALID_ARGUMENT;
r=xtc_project_clone(p,&copy);
for(k=1;r==XTC_OK && k<=copies;++k)for(i=0;r==XTC_OK && i<count;++i) {
xtc_clip_info c;uint64_t id;xtc_project_find_clip(p,ids[i],&c);
r=xtc_project_duplicate_clip(copy,ids[i],c.track_id,c.start_tick+span*k,&id);
}
if(r==XTC_OK)publish(p,copy);
xtc_project_destroy(copy);return r;
}