Example #1
0
static void set_new_position(struct Tracks *track, struct Notes *note, Place *start, Place *end){

  bool has_lock = PLAYER_current_thread_has_lock();

  if (track==NULL && has_lock)
    RError("track==NULL && has_lock");
  
  if (track!=NULL) {
    if (has_lock==false)
      PLAYER_lock();
    ListRemoveElement3(&track->notes, &note->l);
  }

  if (start!=NULL && start!=&note->l.p)
    note->l.p = *start;

  if (end!=NULL && end!=&note->end)
    note->end = *end;

  if (track!=NULL){
    ListAddElement3(&track->notes, &note->l);
    if (has_lock==false)
      PLAYER_unlock();
  }
}
Example #2
0
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);

}
Example #3
0
void RA_addNote_FloatPlace(
			   int blocknum,
			   int tracknum,
			   float start,
			   int notenum,
			   float volume,
			   float end)
{
  struct Blocks *block=SWIG_getBlock(blocknum);
  struct Tracks *track=SWIG_getTrack(blocknum,tracknum);
  struct Notes *note;
  Place p2;
  if(track==NULL) return;

  note=NewNote();

  Float2Placement(start,&note->l.p);
  Float2Placement(end,&note->end);
  PlaceSetLastPos(block,&p2);

  if(PlaceGreaterOrEqual(&note->l.p,&p2)) return;
  if(PlaceGreaterOrEqual(&note->end,&p2)){
    PlaceCopy(&note->end,&p2);
  }

  note->note=notenum;
  note->velocity=boundaries(
			    volume*(*track->instrument->getMaxVelocity)(track),
			    0,
			    (*track->instrument->getMaxVelocity)(track)
			    );

  ListAddElement3(&track->notes,&note->l);
}
Example #4
0
static void add_fxnodeline(
                           struct FXNodeLines **tofxnodeline,
                           struct FXNodeLines *fromfxnodeline,
                           Place subtract
){               
  struct FXNodeLines *fxnodeline=talloc(sizeof(struct FXNodeLines));
  memcpy(fxnodeline, fromfxnodeline, sizeof(struct FXNodeLines));
  
  fxnodeline->l.p = p_Sub(fxnodeline->l.p, subtract);
  
  ListAddElement3(tofxnodeline,&fxnodeline->l);
}
Example #5
0
static void AddNewTypeOfFxNodeLine(const struct WBlocks *wblock, struct WTracks *wtrack, struct FX *fx, const Place *p2, int val){
  printf("new, fxnum: %d, wtrack->fxs->l.num:%d\n",fx->num,wtrack->track->fxs==NULL?-1000:wtrack->track->fxs->l.num);
  
  struct FXs *fxs=talloc(sizeof(struct FXs));
  fxs->l.num=fx->num;
  fxs->fx=fx;
  ListAddElement1(&wtrack->track->fxs,&fxs->l);
  
  struct FXNodeLines *fxnodeline=talloc(sizeof(struct FXNodeLines));
  fxnodeline->val=val;
  PlaceCopy(&fxnodeline->l.p,p2);
  ListAddElement3(&fxs->fxnodelines,&fxnodeline->l);
}
Example #6
0
void LoadLocalZooms(struct LocalZooms **to){
	int num_lines=DC_LoadI();
	struct LocalZooms *localzoom;
	struct LocalZooms *uplevel;
	Place place;
	int lokke;
	int ret;

	place.counter=0;
	place.dividor=1;

	for(lokke=0;lokke<num_lines;lokke++){
		localzoom=DC_alloc(sizeof(struct LocalZooms));
		localzoom->Tline=lokke;
		localzoom->Tdividor=1;
		localzoom->zoomline=lokke;
		ListAddElement3(to,&localzoom->l);
	}

	for(;;){
		ret=DC_Next();
		switch(ret){
			case LS_OBJECT:

				localzoom=DC_alloc(sizeof(struct LocalZooms));
				LoadPlace(&localzoom->l.p);
				localzoom->zoomline=DC_LoadI();
				localzoom->level=DC_LoadI();
                                if(disk_load_version>0.725)
                                  localzoom->autogenerated=DC_LoadB();

				place.line=localzoom->Tline;
				uplevel=ListFindElement3(&((*to)->l),&place);
				DC_ListAdd3(&uplevel->uplevel,localzoom);

				LoadLocalZooms_Uplevel(&localzoom->uplevel);
				break;

			case LS_ENDOBJECT:
			case LS_ERROR:
				return;
		}
	}

error:
	return;
}
Example #7
0
/*****************************************************************************
  FUNCTION
    Adds an element only if the list doesn't allready contain an element
    with the same placement attributes.
******************************************************************************/
int ListAddElement3_ns(
	void *voidlistroot,
	struct ListHeader3 *element
){
	if(element==NULL) return -1;

        struct ListHeaderPointer3 *listroot=voidlistroot;

	ListAddElement3(listroot,element);
	if(element->next!=NULL)
		if(PlaceEqual(&element->p,&element->next->p)){
			ListRemoveElement3(listroot,element);
			return -1;
		}

        struct ListHeader3 *list=listroot->root;
	return ListPosition3(list,element);
}
Example #8
0
struct Notes *InsertNote(
	struct WBlocks *wblock,
	struct WTracks *wtrack,
	Place *placement,
        Place *end_placement,
	float notenum,
	int velocity,
	bool polyphonic
){
	struct Blocks *block=wblock->block;
	struct Tracks *track=wtrack->track;

	struct Notes *note=NewNote();

        //((char*)note)[-5] = 'b'; // test memory validator
        
	PlaceCopy(&note->l.p,placement);

	note->note=notenum;
	note->velocity=velocity;
//	note->velocity=(*wtrack->track->instrument->getStandardVelocity)(wtrack->track);
	note->velocity_end=note->velocity;
        
        PLAYER_lock();
        {
          ListAddElement3(&track->notes,&note->l);

          if(polyphonic==false)
            StopAllNotesAtPlace(block,track,placement);

          if (end_placement==NULL)
            SetEndAttributes(block,track,note);
          else
            PlaceCopy(&note->end, end_placement);

          track->notes = NOTES_sort_by_pitch(track->notes);
        }
        PLAYER_unlock();

        NOTE_validate(block, NULL, note);

        return note;
}
Example #9
0
void CopyRange_pitches(
	struct Pitches **topitch,
	struct Pitches *frompitch,
	Place *p1,
	Place *p2
){
	struct Pitches *pitch;

	if(frompitch==NULL) return;

	if(PlaceGreaterOrEqual(&frompitch->l.p,p2)) return;

	pitch=tcopy(frompitch, sizeof(struct Pitches));

	PlaceSub(&pitch->l.p,p1);

	ListAddElement3(topitch,&pitch->l);

	CopyRange_pitches(topitch,NextPitch(frompitch),p1,p2);
}
Example #10
0
struct Signatures *SetSignature(
	struct Blocks *block,
	const Place *place,
        Ratio ratio
){
        struct Signatures *signature=(struct Signatures *)ListFindElement3(&block->signatures->l,place);

	if(signature!=NULL && PlaceEqual(&signature->l.p,place)){
               signature->signature=ratio;
	}else{
                signature=(struct Signatures*)talloc(sizeof(struct Signatures));
		PlaceCopy(&signature->l.p,place);
		signature->signature=ratio;
		ListAddElement3(&block->signatures,&signature->l);
	}
        
	//UpdateSTimes(block);
        UpdateBeats(block);

        return signature;
}
Example #11
0
void CopyRange_velocities(
	struct Velocities **tovelocity,
	struct Velocities *fromvelocity,
	Place *p1,
	Place *p2
){
	struct Velocities *velocity;

	if(fromvelocity==NULL) return;

	if(PlaceGreaterOrEqual(&fromvelocity->l.p,p2)) return;

	velocity=talloc(sizeof(struct Velocities));
        memcpy(velocity, fromvelocity, sizeof(struct Velocities));

	PlaceSub(&velocity->l.p,p1);

	ListAddElement3(tovelocity,&velocity->l);

	CopyRange_velocities(tovelocity,NextVelocity(fromvelocity),p1,p2);
}
Example #12
0
static void SetNum_Vel_rec(
	struct WTracks *wtrack,
	struct FindNum_Velstruct **velroot,
	struct Notes *note
){
	struct FindNum_Velstruct temp_start;
	struct FindNum_Velstruct temp_end;

	if(note==NULL){
		SetNum_Vel_set(wtrack,velroot);
		return;
	}

	PlaceCopy(&temp_start.l.p,&note->l.p);
	temp_start.startstop=1;
	ListAddElement3_a(velroot,&temp_start.l);

	PlaceCopy(&temp_end.l.p,&note->end);
	temp_end.startstop= -1;
	ListAddElement3(velroot,&temp_end.l);

	SetNum_Vel_rec(wtrack,velroot,NextNote(note));
}
Example #13
0
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(&note->l.p,p1);
	PlaceSub(&note->end,p1);

	ListAddElement3(tonote,&note->l);

	CopyRange_velocities(&note->velocities,fromnote->velocities,p1,p2);
	CopyRange_pitches(&note->pitches,fromnote->pitches,p1,p2);

	CopyRange_notes(tonote,NextNote(fromnote),p1,p2);
}
Example #14
0
/* Argh. This one was difficult, I don`t think it works correctly
   in all situations yet either.
*/
void InsertLines(
	struct Blocks *block,
	int line,
	int toinsert
){
	int lokke;
	struct LocalZooms *localzoom;
	struct Tracker_Windows *window=root->song->tracker_windows;
	struct WBlocks *wblock;
	struct Tracks *track=block->tracks;

	int num_lines=block->num_lines;

	if(line>num_lines+toinsert){
		toinsert=line-num_lines;
	}

        if (line==num_lines-1) { // special case
          Block_Properties(block, block->num_tracks, block->num_lines + toinsert);
          return;
        }
        
	if( line<0 || line>=num_lines) return;

	if(toinsert==0 || num_lines+toinsert<2 || num_lines+toinsert>=MAX_UINT32) return;

        
        PC_Pause();{
        
          blocktobelongtoforinsertlines_notes_a_terrible_hack=block;
          
          block->num_lines=num_lines+toinsert;
          
          List_InsertLines3(&block->temponodes,block->temponodes->l.next,line,toinsert,NULL);
          LegalizeTempoNodes(block);
          List_InsertLines3(&block->signatures,&block->signatures->l,line,toinsert,NULL);
          List_InsertLines3(&block->lpbs,&block->lpbs->l,line,toinsert,NULL);
          List_InsertLines3(&block->tempos,&block->tempos->l,line,toinsert,NULL);
          
          UpdateSTimes(block);
          UpdateBeats(block);

          while(track!=NULL){
            List_InsertLines3(&track->notes,&track->notes->l,line,toinsert,InsertLines_notes);
            LegalizeNotes(block,track);
            List_InsertLines3(&track->stops,&track->stops->l,line,toinsert,NULL);
            VECTOR_FOR_EACH(struct FXs *fxs, &track->fxs){
              List_InsertLines3(&fxs->fxnodelines,&fxs->fxnodelines->l,line,toinsert,NULL);
            }END_VECTOR_FOR_EACH;
            LegalizeFXlines(block,track);
            track=NextTrack(track);
          }

          while(window!=NULL){
            wblock=ListFindElement1(&window->wblocks->l,block->l.num);
            List_InsertLines3(
                              &wblock->localzooms,
                              &wblock->localzooms->l,
                              line,
                              toinsert,
                              InsertLines_localzooms
                              //			NULL
                              );
            for(lokke=line;lokke<line+toinsert;lokke++){
              localzoom=talloc(sizeof(struct LocalZooms));
              localzoom->Tline=lokke;
              localzoom->Tdividor=1;
              localzoom->zoomline=lokke;
              ListAddElement3(&wblock->localzooms,&localzoom->l);
            }
            UpdateWBlockWidths(window,wblock);
            wblock->reallines = NULL; // We changed the localzooms, which is used to set new curr_realline. We don't need to set new curr_realline, so just set reallines to NULL.
            UpdateRealLines(window,wblock);
            UpdateReallinesDependens(window,wblock);
            if(wblock->curr_realline>=wblock->num_reallines){
              wblock->curr_realline=wblock->num_reallines-1;
            }
            window=NextWindow(window);
          }
          
          blocktobelongtoforinsertlines_notes_a_terrible_hack=NULL;

        }PC_StopPause(window);
}
Example #15
0
static void STP_fillinSTimes2(
	STimePlace *stp,
	Place *p1,
	Place *p2
){
	bool tchange=false;
	bool rchange=false;

	double tfp1,tfp2;
	double reltempo1=stp->reltempo1;
	double reltempo2=stp->reltempo2;

	struct STimeChanges *timechange=NULL;

	if(PlaceEqual(p1,p2)){
		return;
	}
	if(reltempo1!=reltempo2) rchange=true;
	if(rchange || p1->counter>0) tchange=true;

	if(tchange){
		timechange=talloc(sizeof(struct STimeChanges));
		timechange->time=stp->nexttime;
		timechange->tempo1=0.0f;
	}

	if(0==p1->counter){
          stp->times[p1->line].time = stp->nexttime;
	}

	tfp1=GetDoubleFromPlace(p1);
	tfp2=GetDoubleFromPlace(p2);

	if(rchange){

		timechange->rel=
			reltempo1 + (
				(reltempo2-reltempo1)*(tfp1-stp->relp1)/(stp->relp2-stp->relp1)
			)
		;

		timechange->deltarel = (
			reltempo1 + (
				(reltempo2-reltempo1)*(tfp2-stp->relp1)/(stp->relp2-stp->relp1)
			)
		) - timechange->rel;


		timechange->tempo1 = stp->lpb * stp->tempo;


		stp->nexttime = (
			stp->nexttime + (
				pc->pfreq*60*(tfp2-tfp1)/(
					(timechange->tempo1*FindAverageRealRelTempo(timechange->rel,(double)(timechange->rel+timechange->deltarel)))
				)
			)
		);

	}else{
		stp->nexttime = (
			stp->nexttime + (
				pc->pfreq*60*(tfp2-tfp1)/(stp->tempo*stp->lpb*RelTempo2RealRelTempo(stp->reltempo1))
			)
		);
	}

	if(tchange){
		PlaceCopy(&timechange->l.p,p1);
		ListAddElement3(&stp->times[p1->line].timechanges,&timechange->l);
	}
}
Example #16
0
void Block_Set_num_lines(
	struct Blocks *block,
	int num_lines
){
	Place lastplace1,lastplace;
	struct Tracker_Windows *window=root->song->tracker_windows;
	struct WBlocks *wblock;
	struct LocalZooms *localzoom;
	struct Tracks *track=block->tracks;
	struct Notes *note;
	struct FXs *fxs;
	int org_num_lines=block->num_lines;
	int lokke;

	if(org_num_lines==num_lines || num_lines<2) return;

	PlaceSetLastPos(block,&lastplace1);

	block->num_lines=num_lines;

	PlaceSetLastPos(block,&lastplace);

	if(num_lines<org_num_lines){

		CutListAt_a(&block->lpbs,&lastplace);
		CutListAt_a(&block->tempos,&lastplace);
		CutListAt_a(&block->temponodes,&lastplace);
		PlaceSetLastPos(block,&block->lasttemponode->l.p);
		ListAddElement3(&block->temponodes,&block->lasttemponode->l);

		while(track!=NULL){
			CutListAt_a(&track->notes,&lastplace);
			note=track->notes;
			while(note!=NULL){
				CutListAt(&note->velocities,&lastplace);
				CutListAt(&note->pitches,&lastplace);
				if(PlaceEqual(&note->end,&lastplace1) && note->noend==1){
					PlaceCopy(&note->end,&lastplace);
				}
				note=NextNote(note);
			}
			LegalizeNotes(block,track);

			CutListAt_a(&track->stops,&lastplace);

			fxs=track->fxs;
			while(fxs!=NULL){
				CutListAt_a(&fxs->fxnodelines,&lastplace);
				fxs=NextFX(fxs);
			}
			LegalizeFXlines(block,track);
			track=NextTrack(track);
		}
		while(window!=NULL){
			wblock=ListFindElement1(&window->wblocks->l,block->l.num);
			CutListAt_a(&wblock->localzooms,&lastplace);
			window=NextWindow(window);
		}
	}else{

		PlaceSetLastPos(block,&block->lasttemponode->l.p);

		while(track!=NULL){
			note=track->notes;
			while(note!=NULL){
				if(PlaceEqual(&note->end,&lastplace1) && note->noend==1){
					PlaceSetLastPos(block,&note->end);
				}
				note=NextNote(note);
			}
			LegalizeNotes(block,track);
			track=NextTrack(track);
		}
		while(window!=NULL){
			wblock=ListFindElement1(&window->wblocks->l,block->l.num);
			for(lokke=org_num_lines;lokke<num_lines;lokke++){
				localzoom=talloc(sizeof(struct LocalZooms));
				localzoom->Tline=lokke;
				localzoom->Tdividor=1;
				localzoom->zoomline=lokke;
				ListAddElement3(&wblock->localzooms,&localzoom->l);
			}
			window=NextWindow(window);
		}

	}


	window=root->song->tracker_windows;

	while(window!=NULL){
		wblock=ListFindElement1(&window->wblocks->l,block->l.num);
                UpdateWBlockWidths(window,wblock);
		UpdateRealLines(window,wblock);
		window=NextWindow(window);
	}

	UpdateSTimes(block);
        UpdateBeats(block);
}