void CopyRange_stops( struct Stops **tostop, struct Stops *fromstop, Place *p1, Place *p2 ){ struct Stops *stop; if(fromstop==NULL) return; if(PlaceLessThan(&fromstop->l.p,p1)){ CopyRange_stops(tostop,NextStop(fromstop),p1,p2); return; } if(PlaceGreaterOrEqual(&fromstop->l.p,p2)) return; stop=talloc(sizeof(struct Stops)); memcpy(stop, fromstop, sizeof(struct Stops)); PlaceSub(&stop->l.p,p1); ListAddElement3(tostop,&stop->l); CopyRange_stops(tostop,NextStop(fromstop),p1,p2); }
Place STime2Place( const struct Blocks *block, STime time ) { Place place; Place *firstplace = PlaceGetFirstPos(); Place lastplace; PlaceSetLastPos(block, &lastplace); if (time < 0) { return *firstplace; } if (time >= getBlockSTimeLength(block)){ PlaceTilLimit(&place,&lastplace); return place; } double place_f = STime2Place_f(block,time); Double2Placement(place_f, &place); if (PlaceGreaterOrEqual(&place, &lastplace)) PlaceTilLimit(&place,&lastplace); else if (PlaceLessThan(&place,firstplace)) place = *firstplace; //if (place.line==64) // abort(); return place; }
void VECTOR_insert_place(vector_t *v, const Place *p){ int i; for(i=0 ; i<v->num_elements ; i++){ // could be optimized by using binary search, but binary search is hard to get correct. That speedup is not needed for now anyway. Place *element = v->elements[i]; if (PlaceLessThan(p, element)) { VECTOR_insert(v, p, i); return; } } VECTOR_push_back(v, p); }
void VECTOR_insert_list3(vector_t *v, const struct ListHeader3 *element){ const Place *p = &element->p; int i; for(i=0 ; i<v->num_elements ; i++){ // could be optimized by using binary search, but binary search is hard to get correct. That speedup is not needed for now anyway. struct ListHeader3 *l3 = (struct ListHeader3*)v->elements[i]; if (PlaceLessThan(p, &l3->p)) { VECTOR_insert(v, element, i); return; } } VECTOR_push_back(v, element); }
void CutRange_stops( struct Stops **tostop, struct Stops *fromstop, Place *p1, Place *p2 ){ struct Stops *next; if(fromstop==NULL) return; next=NextStop(fromstop); if(PlaceLessThan(&fromstop->l.p,p1)){ CutRange_stops(tostop,next,p1,p2); return; } if(PlaceGreaterOrEqual(&fromstop->l.p,p2)) return; ListRemoveElement3(tostop,&fromstop->l); CutRange_stops(tostop,next,p1,p2); }
void CutRange_notes( struct Notes **tonote, struct Notes *fromnote, Place *p1, Place *p2 ){ struct Notes *next; if(fromnote==NULL) return; next=NextNote(fromnote); if(PlaceLessThan(&fromnote->l.p,p1)){ CutRange_notes(tonote,next,p1,p2); return; } if(PlaceGreaterOrEqual(&fromnote->l.p,p2)) return; ListRemoveElement3(tonote,&fromnote->l); CutRange_notes(tonote,next,p1,p2); }
static void InitPEQnotesBlock( PEQ_UsedTracks **UsedTracks, const struct Blocks *block, const Place *p, int playlistaddpos ){ PEQ_UsedTracks *peq_usedtrack; struct Notes *note; struct Tracks *track=block->tracks; while(track!=NULL){ if( ListFindElement1_r0(*UsedTracks,track->l.num) == NULL ){ note=track->notes; if(note!=NULL){ while(PlaceLessThan(¬e->l.p,p)){ note=NextNote(note); if(note==NULL) break; } if(note!=NULL){ peq_usedtrack=talloc(sizeof(PEQ_UsedTracks)); peq_usedtrack->num=track->l.num; ListAddElement1(UsedTracks,peq_usedtrack); InitPEQnote(block,track,note,playlistaddpos); } else{ //PEQ_FindNextNoteAddPlayPos(peq); } } } track=NextTrack(track); } }
/************************************************************** FUNCTION Stops all notes before line+(counter/dividor) at line+(counter/dividor, if they last that long. **************************************************************/ void StopAllNotesAtPlace( struct Blocks *block, struct Tracks *track, Place *placement ){ if (PLAYER_current_thread_has_lock()==false && is_playing()==true){ RError("StopAllNotesAtPlace. PLAYER_current_thread_has_lock(): %d, is_playing(): %d", PLAYER_current_thread_has_lock()==false, is_playing()==true); } struct Notes *temp; temp=track->notes; while(temp!=NULL && PlaceLessThan(&temp->l.p,placement)){ if(PlaceGreaterThan(&temp->end,placement)){ CutListAt(&temp->velocities,placement); CutListAt(&temp->pitches,placement); PlaceCopy(&temp->end,placement); NOTE_validate(block, track, temp); } temp=NextNote(temp); } }
void CopyRange_notes( struct Notes **tonote, struct Notes *fromnote, Place *p1, Place *p2 ){ struct Notes *note; if(fromnote==NULL){ return; } if(PlaceLessThan(&fromnote->l.p,p1)){ CopyRange_notes(tonote,NextNote(fromnote),p1,p2); return; } if(PlaceGreaterOrEqual(&fromnote->l.p,p2)){ return; } note=CopyNote(fromnote); note->pitches = NULL; note->velocities = NULL; NOTE_init(note); PlaceSub(¬e->l.p,p1); PlaceSub(¬e->end,p1); ListAddElement3(tonote,¬e->l); CopyRange_velocities(¬e->velocities,fromnote->velocities,p1,p2); CopyRange_pitches(¬e->pitches,fromnote->pitches,p1,p2); CopyRange_notes(tonote,NextNote(fromnote),p1,p2); }
static void set_legal_start_and_end_pos(const struct Blocks *block, struct Tracks *track, struct Notes *note){ Place *start = ¬e->l.p; Place *end = ¬e->end; Place endplace; PlaceSetLastPos(block,&endplace); if(PlaceGreaterOrEqual(start,&endplace)) { RError("note is placed after block end. start: %f, end: %f", GetfloatFromPlace(¬e->l.p), GetfloatFromPlace(¬e->end)); set_new_position(track, note, PlaceCreate(block->num_lines - 2, 0, 1), NULL); start = ¬e->l.p; } if (start->line < 0) { RError("note is placed before block start. start: %f, end: %f", GetfloatFromPlace(¬e->l.p), GetfloatFromPlace(¬e->end)); set_new_position(track, note, PlaceCreate(0,1,1), NULL); start = ¬e->l.p; } if(PlaceGreaterThan(end,&endplace)) { RError("note end is placed after block end. start: %f, end: %f. block end: %f", GetfloatFromPlace(¬e->l.p), GetfloatFromPlace(¬e->end), GetfloatFromPlace(&endplace)); set_new_position(track, note, NULL, &endplace); end = ¬e->end; } if (note->velocities != NULL) { { struct Velocities *first_velocity = note->velocities; if(PlaceGreaterThan(start, &first_velocity->l.p)){ RError("note start is placed after first velocity. start: %f, first: %f, end: %f", GetfloatFromPlace(¬e->l.p), GetfloatFromPlace(&first_velocity->l.p), GetfloatFromPlace(¬e->end)); float e = p_float(first_velocity->l.p); e -= 0.01; e = R_MAX(0.0, e); Place new_start; Float2Placement(e, &new_start); set_new_position(track, note, &new_start, NULL); start = ¬e->l.p; } } struct Velocities *last_velocity = (struct Velocities*)ListLast3(¬e->velocities->l); if(PlaceLessThan(end, &last_velocity->l.p)){ RError("note end is placed before last velocity. start: %f, last: %f, end: %f", GetfloatFromPlace(¬e->l.p), GetfloatFromPlace(&last_velocity->l.p), GetfloatFromPlace(¬e->end)); float e = p_float(last_velocity->l.p); e += 0.01; Place new_end; Float2Placement(e, &new_end); set_new_position(track, note, NULL, &new_end); end = ¬e->end; } } if (note->pitches != NULL) { { struct Pitches *first_pitch = note->pitches; if(PlaceGreaterThan(start, &first_pitch->l.p)){ RError("note start is placed after first pitch. start: %f, first: %f, end: %f", GetfloatFromPlace(¬e->l.p), GetfloatFromPlace(&first_pitch->l.p), GetfloatFromPlace(¬e->end)); float e = p_float(first_pitch->l.p); e -= 0.01; e = R_MAX(0.0, e); Place new_start; Float2Placement(e, &new_start); set_new_position(track, note, &new_start, NULL); start = ¬e->l.p; } } struct Pitches *last_pitch = (struct Pitches*)ListLast3(¬e->pitches->l); if(PlaceLessThan(end, &last_pitch->l.p)){ RError("note end is placed before last pitch. start: %f, last: %f, end: %f", GetfloatFromPlace(¬e->l.p), GetfloatFromPlace(&last_pitch->l.p), GetfloatFromPlace(¬e->end)); float e = p_float(last_pitch->l.p); e += 0.01; Place new_end; Float2Placement(e, &new_end); set_new_position(track, note, NULL, &new_end); end = ¬e->end; } } if(PlaceLessOrEqual(end,start)) { RError("note end is placed before (or on) note start. start: %f, end: %f", GetfloatFromPlace(¬e->l.p), GetfloatFromPlace(¬e->end)); float e = p_float(*start); e += 0.01; Place new_end; Float2Placement(e, &new_end); set_new_position(track, note, NULL, &new_end); } }