feat(midi): strum chords with preserved note ends and undo (phase 99)
This commit is contained in:
parent
083ac05ae6
commit
bd0a63c06d
17 changed files with 172 additions and 5 deletions
|
|
@ -344,6 +344,7 @@ MainWindow::MainWindow(bool prompt_unsaved,const char *configuration)
|
|||
menu->add("Edit/Audio tools/Remove boundary fades",0,[](Fl_Widget *,void *c){static_cast<SequencerWidget *>(c)->transform_selection(XTC_CLIPS_FADE,0);},sequencer_);
|
||||
menu->add("Edit/MIDI tools/Generate arpeggio...",0,[](Fl_Widget *,void *c){static_cast<SequencerWidget *>(c)->arpeggio_dialog();},sequencer_);
|
||||
menu->add("Edit/MIDI tools/Build chords...",0,[](Fl_Widget *,void *c){static_cast<SequencerWidget *>(c)->chord_dialog();},sequencer_);
|
||||
menu->add("Edit/MIDI tools/Strum chords...",0,[](Fl_Widget *,void *c){static_cast<SequencerWidget *>(c)->strum_dialog();},sequencer_);
|
||||
menu->add("Edit/MIDI tools/Humanize...",0,[](Fl_Widget *,void *c){static_cast<SequencerWidget *>(c)->humanize_dialog();},sequencer_);
|
||||
menu->add("Edit/MIDI tools/Shape velocities...",0,[](Fl_Widget *,void *c){static_cast<SequencerWidget *>(c)->velocity_dialog();},sequencer_);
|
||||
menu->add("Edit/MIDI tools/Correct to scale...",0,[](Fl_Widget *,void *c){static_cast<SequencerWidget *>(c)->scale_dialog();},sequencer_);
|
||||
|
|
|
|||
|
|
@ -939,3 +939,18 @@ xtc_result SequencerWidget::crossfade_selection()
|
|||
if(r==XTC_OK)r=xtc_project_crossfade(project_,ids[0],ids[1]);
|
||||
changed(r);return r;
|
||||
}
|
||||
|
||||
xtc_result SequencerWidget::strum_chords(uint64_t spacing,bool descending)
|
||||
{
|
||||
auto ids=selected_clips();xtc_result r=XTC_OK;
|
||||
if(before_edit)r=before_edit(context_);
|
||||
if(r==XTC_OK)r=xtc_project_strum(project_,ids.data(),ids.size(),spacing,descending ? 1 : 0);
|
||||
changed(r);return r;
|
||||
}
|
||||
void SequencerWidget::strum_dialog()
|
||||
{
|
||||
const char *input=fl_input("Spacing ticks (1..960), direction (0=up, 1=down)","30 0");if(!input)return;
|
||||
uint64_t spacing=0;int down=0;char extra;std::istringstream values(input);
|
||||
if(!(values>>spacing>>down) || (values>>extra) || !spacing || spacing>960 || down<0 || down>1){fl_alert("Enter a valid spacing and direction.");return;}
|
||||
strum_chords(spacing,down!=0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ class SequencerWidget : public Fl_Group {
|
|||
void scale_dialog();
|
||||
void velocity_dialog();
|
||||
void humanize_dialog();
|
||||
void strum_dialog();
|
||||
xtc_result strum_chords(uint64_t spacing,bool descending);
|
||||
xtc_result make_chord(const std::vector<int> &intervals);
|
||||
void chord_dialog();
|
||||
xtc_result arpeggiate(uint64_t step,unsigned int gate,bool descending);
|
||||
|
|
|
|||
|
|
@ -334,3 +334,32 @@ xtc_result xtc_project_arpeggiate(xtc_project *p,const uint64_t *ids,size_t coun
|
|||
if(r==XTC_OK)publish(p,copy);
|
||||
xtc_project_destroy(copy);return r;
|
||||
}
|
||||
|
||||
/* Rank against the original project so edits cannot alter later chord groups. */
|
||||
xtc_result xtc_project_strum(xtc_project *p,const uint64_t *ids,size_t count,
|
||||
uint64_t spacing,int descending)
|
||||
{
|
||||
xtc_project *copy=NULL;size_t i,j,k,changed=0;
|
||||
xtc_result r=selection_valid(p,ids,count);
|
||||
if(r!=XTC_OK)return r;
|
||||
if(!spacing || spacing>960 || (descending!=0 && descending!=1))return XTC_ERR_INVALID_ARGUMENT;
|
||||
for(i=0;i<count;++i){xtc_clip_info c;xtc_project_find_clip(p,ids[i],&c);if(!c.midi)return XTC_ERR_INVALID_STATE;}
|
||||
r=xtc_project_clone(p,©);if(r!=XTC_OK)return r;
|
||||
for(i=0;i<p->note_count;++i) {
|
||||
const xtc_note_info *n=p->notes+i;size_t rank=0;uint64_t offset;
|
||||
for(k=0;k<count;++k)if(n->clip_id==ids[k])break;
|
||||
if(k==count)continue;
|
||||
for(j=0;j<p->note_count;++j) {
|
||||
const xtc_note_info *other=p->notes+j;
|
||||
if(other->clip_id!=n->clip_id || other->start_tick!=n->start_tick || other->channel!=n->channel)continue;
|
||||
if((descending ? other->pitch>n->pitch : other->pitch<n->pitch) ||
|
||||
(other->pitch==n->pitch && other->id<n->id))++rank;
|
||||
}
|
||||
if(!rank)continue;
|
||||
offset=(uint64_t)rank*spacing;
|
||||
if(offset>=n->length_tick){xtc_project_destroy(copy);return XTC_ERR_INVALID_ARGUMENT;}
|
||||
copy->notes[i].start_tick+=offset;copy->notes[i].length_tick-=offset;++changed;
|
||||
}
|
||||
if(changed)publish(p,copy);
|
||||
xtc_project_destroy(copy);return changed ? XTC_OK : XTC_ERR_NOT_FOUND;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue