struct Notes *NOTES_sort_by_pitch(struct Notes *notes){ while(NOTES_sorted_by_pitch_questionmark(notes)==false) { struct Notes *better = sort_notes_by_pitch_a_little_bit(notes); if (better==NULL) // should not be possible, but in case the impossible happens, we don't want to lose all notes return notes; notes = better; } return notes; }
void TRACK_split_into_monophonic_tracks(struct Tracker_Windows *window, struct WBlocks *wblock, struct WTracks *wtrack){ PlayStop(); // This function is too chaotic. Don't bother pausing player. vector_t notesvector = {0}; struct Tracks *track = wtrack->track; struct Notes *notes = track->notes; struct Notes *notes_nexttrack = NULL; bool have_made_undo = false; if (NOTES_sorted_by_pitch_questionmark(track->notes)==false) { ADD_UNDO(Block_CurrPos(window)); have_made_undo = true; notes = NOTES_sort_by_pitch(notes); } while(notes != NULL){ struct Notes *notes_root = notes; while(notes != NULL) { struct Notes *next = NextNote(notes); if (next==NULL) break; if (PlaceGreaterThan(¬es->end, &next->l.p)){ if (have_made_undo==false) { have_made_undo=true; } ListRemoveElement3(¬es, &next->l); ListAddElement3_a(¬es_nexttrack, &next->l); } else notes = next; } VECTOR_push_back(¬esvector, notes_root); notes = notes_nexttrack; notes_nexttrack = NULL; } if (have_made_undo==false){ GFX_Message(NULL, "Track is already monophonic"); return; } int num_tracks = notesvector.num_elements; track->notes = NULL; struct WTracks *wtrack_copy = CB_CopyTrack(wblock,wtrack); VECTOR_clean(&wtrack_copy->track->fxs); InsertTracks(window, wblock, wtrack->l.num+1, num_tracks-1); printf("Vector length: %d\n",num_tracks); int i; for(i=0;i<num_tracks;i++){ struct Notes *notes = notesvector.elements[i]; printf(" %d: %d\n", i, ListFindNumElements3(¬es->l)); while(notes != NULL){ printf(" %s\n",NotesTexts3[(int)notes->note]); notes = NextNote(notes); } struct WTracks *towtrack = ListFindElement1(&wblock->wtracks->l, wtrack->l.num+i); if (i>0) co_CB_PasteTrack(wblock, wtrack_copy, towtrack); towtrack->track->notes = notesvector.elements[i]; } window->must_redraw = true; }