feat: ripple timeline ranges with markers and automation atomically
This commit is contained in:
parent
bd39eb1345
commit
7084e660fe
9 changed files with 95 additions and 5 deletions
|
|
@ -342,6 +342,8 @@ MainWindow::MainWindow(bool prompt_unsaved,const char *configuration)
|
|||
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/Time/Insert gap...",0,[](Fl_Widget *,void *c){static_cast<SequencerWidget *>(c)->ripple_dialog(false);},sequencer_);
|
||||
menu->add("Edit/Time/Remove range...",0,[](Fl_Widget *,void *c){static_cast<SequencerWidget *>(c)->ripple_dialog(true);},sequencer_);
|
||||
menu->add("Edit/Markers/Set at cursor...",0,[](Fl_Widget *,void *c){static_cast<SequencerWidget *>(c)->marker_dialog();},sequencer_);
|
||||
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_);
|
||||
|
|
|
|||
|
|
@ -519,6 +519,19 @@ int SequencerWidget::handle(int event)
|
|||
return Fl_Group::handle(event);
|
||||
}
|
||||
|
||||
xtc_result SequencerWidget::ripple_time(uint64_t length,bool remove)
|
||||
{
|
||||
const uint64_t at=cursor_;xtc_result r=before_edit ? before_edit(context_) : XTC_OK;
|
||||
if(r==XTC_OK)r=xtc_project_ripple_time(project_,at,length,remove);
|
||||
changed(r);return r;
|
||||
}
|
||||
void SequencerWidget::ripple_dialog(bool remove)
|
||||
{
|
||||
const char *input=fl_input(remove ? "Remove time from cursor: ticks (split crossing clips first)" : "Insert time at cursor: ticks (split crossing clips first)","3840");if(!input)return;
|
||||
uint64_t length=0;char extra;std::istringstream values(input);
|
||||
if(!(values>>length) || (values>>extra) || !length || length>XTC_PROJECT_MAX_TICK){fl_alert("Enter a positive bounded tick duration.");return;}
|
||||
ripple_time(length,remove);
|
||||
}
|
||||
xtc_result SequencerWidget::marker(const char *name)
|
||||
{
|
||||
const uint64_t at=cursor_;xtc_result r=before_edit ? before_edit(context_) : XTC_OK;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ class SequencerWidget : public Fl_Group {
|
|||
Fl_Choice *instrument_choice(uint64_t track) const;
|
||||
void refresh_instruments();
|
||||
bool select(uint64_t track, uint64_t clip = UINT64_MAX);
|
||||
xtc_result ripple_time(uint64_t length,bool remove);
|
||||
void ripple_dialog(bool remove);
|
||||
xtc_result marker(const char *name); /* NULL removes at cursor. */
|
||||
void marker_dialog();
|
||||
bool toggle_clip(uint64_t clip);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
#include "project_internal.h"
|
||||
#include "../graph/graph_internal.h"
|
||||
#include "xtc/xtc_editing.h"
|
||||
#include <string.h>
|
||||
|
||||
xtc_result xtc_project_marker_count(const xtc_project *p,size_t *out)
|
||||
|
|
@ -50,3 +52,43 @@ xtc_result xtc_project_section(const xtc_project *p,uint64_t tick,uint64_t *begi
|
|||
if(finish<=p->markers[i-1].tick)return XTC_ERR_INVALID_STATE;
|
||||
*begin=p->markers[i-1].tick;*end=finish;return XTC_OK;
|
||||
}
|
||||
|
||||
static xtc_result ripple_tick(uint64_t *tick,uint64_t begin,uint64_t length,int remove,int *keep)
|
||||
{
|
||||
*keep=1;
|
||||
if(*tick<begin)return XTC_OK;
|
||||
if(remove){if(*tick<begin+length)*keep=0;else *tick-=length;}
|
||||
else {if(*tick>XTC_PROJECT_MAX_TICK-length)return XTC_ERR_INVALID_ARGUMENT;*tick+=length;}
|
||||
return XTC_OK;
|
||||
}
|
||||
static xtc_result ripple_plugin(xtc_plugin_spec *spec,uint64_t begin,uint64_t length,int remove)
|
||||
{
|
||||
unsigned int i,n=0;int keep;xtc_result r;
|
||||
for(i=0;i<spec->point_count;++i) {
|
||||
xtc_plugin_point point=spec->points[i];r=ripple_tick(&point.tick,begin,length,remove,&keep);
|
||||
if(r!=XTC_OK)return r;
|
||||
if(keep)spec->points[n++]=point;
|
||||
}
|
||||
spec->point_count=n;return XTC_OK;
|
||||
}
|
||||
xtc_result xtc_project_ripple_time(xtc_project *p,uint64_t begin,uint64_t length,int remove)
|
||||
{
|
||||
xtc_project *copy=NULL;size_t i,n;int keep;xtc_result r;
|
||||
if(!p || !length || begin>XTC_PROJECT_MAX_TICK || length>XTC_PROJECT_MAX_TICK-begin || (remove!=0 && remove!=1))return XTC_ERR_INVALID_ARGUMENT;
|
||||
r=xtc_project_clone(p,©);if(r!=XTC_OK)return r;
|
||||
for(i=copy->clip_count;r==XTC_OK && i>0;--i) {
|
||||
xtc_clip_info c=copy->clips[i-1];uint64_t end=c.start_tick+c.length_tick;
|
||||
if((c.start_tick<begin && end>begin) || (remove && c.start_tick<begin+length && end>begin+length)){r=XTC_ERR_INVALID_STATE;break;}
|
||||
r=ripple_tick(&c.start_tick,begin,length,remove,&keep);
|
||||
if(r==XTC_OK)r=keep ? xtc_project_edit_clip(copy,c.id,c.track_id,c.start_tick,c.length_tick,c.offset_tick) : xtc_project_remove_clip(copy,c.id);
|
||||
}
|
||||
n=0;
|
||||
for(i=0;r==XTC_OK && i<copy->marker_count;++i){xtc_marker m=copy->markers[i];r=ripple_tick(&m.tick,begin,length,remove,&keep);if(r==XTC_OK && keep)copy->markers[n++]=m;}
|
||||
copy->marker_count=n;n=0;
|
||||
for(i=0;r==XTC_OK && i<copy->automation_count;++i){xtc_automation_point a=copy->automation[i];r=ripple_tick(&a.tick,begin,length,remove,&keep);if(r==XTC_OK && keep)copy->automation[n++]=a;}
|
||||
copy->automation_count=n;
|
||||
for(i=0;r==XTC_OK && i<copy->track_count;++i)r=ripple_plugin(copy->instruments+i,begin,length,remove);
|
||||
for(i=0;r==XTC_OK && i<copy->graph->node_count;++i)if(copy->graph->nodes[i].type==XTC_NODE_PLUGIN)r=ripple_plugin(©->graph->nodes[i].plugin,begin,length,remove);
|
||||
if(r==XTC_OK){xtc_graph *old=p->graph;*p=*copy;copy->graph=old;}
|
||||
xtc_project_destroy(copy);return r;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue