Beispiel #1
0
/*****************************************************************************
  FUNCTION
    Moves the element to new place 'p', or closest legal position.
    A "legal position" means that it can not be positioned before the
    previous element, or after the next element. In addition, it can not be
    position at the same position as the previous element or next element
    ("ns" means "not same").

    The value for 'firstlegalpos' is only used if prev element is NULL.
    The value for 'lastlegalpos' is only used if next element is NULL.
******************************************************************************/
void ListMoveElement3_ns(
                         const void *voidlistroot,
                         struct ListHeader3 *element,
                         Place *newplace,
                         const Place *firstlegalpos,
                         const Place *lastlegalpos
){
  const struct ListHeaderPointer3 *listroot=voidlistroot;
  struct ListHeader3 *prev=NULL;
  struct ListHeader3 *next = element->next;
  struct ListHeader3 *l=listroot->root;

  while(l!=element){    
    prev = l;
    R_ASSERT_RETURN_IF_FALSE(l!=NULL);
    l=l->next;
  }

  Place firstlegalpos2;
  if (prev!=NULL)
    PlaceFromLimit(&firstlegalpos2, &prev->p);
  else
    PlaceCopy(&firstlegalpos2, firstlegalpos);

  Place lastlegalpos2;
  if (next!=NULL)
    PlaceTilLimit(&lastlegalpos2, &next->p);
  else
    PlaceCopy(&lastlegalpos2, lastlegalpos);

  element->p = *PlaceBetween(&firstlegalpos2, newplace, &lastlegalpos2);
}
Beispiel #2
0
static struct Velocities *add_velocity(
                                int velocityvelocity,
                                const Place *placement,
                                struct Notes *note,
                                int *pos
                                )
{
  *pos = -1;
  
  if(PlaceLessOrEqual(placement, &note->l.p)) return NULL;
  if(PlaceGreaterOrEqual(placement, &note->end)) return NULL;
  struct Velocities *velocity=(struct Velocities*)talloc(sizeof(struct Velocities));
  PlaceCopy(&velocity->l.p,placement);
  velocity->velocity=R_BOUNDARIES(0,velocityvelocity,MAX_VELOCITY);
  
  /* ListAddElement3_ns returns -1 (and doesnt do anything else)
     if there allready is an element with the same placement. */

  PLAYER_lock();{
    *pos = ListAddElement3_ns(&note->velocities,&velocity->l);
  }PLAYER_unlock();

  if (*pos==-1)
    return NULL;
  else
    return velocity;
}
Beispiel #3
0
static void AddFXNodeLineCurrPosInternal(struct Tracker_Windows *window, struct WBlocks *wblock, struct WTracks *wtrack, struct FX *fx, const Place *place, float val){

	Undo_FXs_CurrPos(window);

        struct FXs *fxs=ListFindElement1_r0(&wtrack->track->fxs->l,fx->num);
        if (fxs==NULL){
          Place p2;

          int realline=FindRealLineFor(wblock,0,place);
          if(realline>=wblock->num_reallines-5){
            PlaceSetLastPos(wblock->block,&p2);
          }else{
            PlaceCopy(&p2,&wblock->reallines[wblock->curr_realline+3]->l.p);
          }

          AddNewTypeOfFxNodeLine(wblock, wtrack, fx, &p2, val);
        }

	AddFXNodeLine(
                      window,wblock,wtrack,
                      fx->num,
                      val,
                      place
                      );

#if !USE_OPENGL
	UpdateFXNodeLines(window,wblock,wtrack);

	ClearTrack(window,wblock,wtrack,wblock->top_realline,wblock->bot_realline);
	UpdateWTrack(window,wblock,wtrack,wblock->top_realline,wblock->bot_realline);
#endif
}
Beispiel #4
0
void InsertLines_notes(
	void *tonote,
	struct ListHeader3 *l,
	int line,
	int toinsert
){
	struct Notes *note=(struct Notes *)l;
	struct Blocks *block=blocktobelongtoforinsertlines_notes_a_terrible_hack;
	Place p2;

	PlaceSetLastPos(block,&p2);
//	p2.line-=toinsert;

	//	printf("toinsert: %d, note->end.line: %d, p2->line: %d\n",toinsert,note->end.line,p2.line);
	if(note->end.line>=line){
//		printf("block: %d, note->end.line: %d, p2->line: %d\n",block->l.num,note->end.line,p2.line);

		if(PlaceGreaterOrEqual(&note->end,&p2) && note->l.p.line<line){

			PlaceSetLastPos(block,&p2);
			PlaceCopy(&note->end,&p2);
			note->noend=1;
		}else{
			note->end.line+=toinsert;
                        note->end.line=R_MAX(note->end.line,line);
		}

		List_InsertLines3(&note->velocities,&note->velocities->l,line,toinsert,NULL);
		List_InsertLines3(&note->pitches,&note->pitches->l,line,toinsert,NULL);
	}
}
Beispiel #5
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);
}
Beispiel #6
0
void setNoteEndPlace(int line,int counter,int dividor,int windownum,int blocknum,int tracknum,int notenum){
  struct Tracker_Windows *window=getWindowFromNum(windownum);
  struct Notes *note=getNoteFromNum(windownum,blocknum,tracknum,notenum);

  if(window==NULL) return;
  if(note==NULL) return;

  PlaceCopy(&note->end, PlaceCreate(line,counter,dividor));
}
Beispiel #7
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;
}
Beispiel #8
0
void TRACK_make_monophonic_destructively(struct Tracks *track){
  struct Tracker_Windows *window = root->song->tracker_windows;
  struct WBlocks *wblock = window->wblock;

  struct Notes *note = track->notes;

  bool have_made_undo = false;
  
  while(note!=NULL){
    struct Notes *next = NextNote(note);
    if (next==NULL)
      break;

    if (PlaceGreaterThan(&note->end, &next->l.p)){

      PLAYER_lock();{

        if (PlaceEqual(&note->l.p, &next->l.p)) {

          ListRemoveElement3(&track->notes, &next->l);                           

        } else {

          PlaceCopy(&note->end, &next->l.p);
          note = next;

        }

      }PLAYER_unlock();

      if (have_made_undo==false){      
        ADD_UNDO(Notes(window,
                       wblock->block,
                       track,
                       wblock->curr_realline
                       )
                 );

        have_made_undo = true;
      }

    } else {

      note = next;

    }

  }

  if (have_made_undo==false)
    GFX_Message(NULL, "Track is already monophonic");
  else
    window->must_redraw = true;
}
Beispiel #9
0
void AddFXNodeLineCurrPos(struct Tracker_Windows *window, struct WBlocks *wblock, struct WTracks *wtrack){
  PlayStop();
  
  struct FX *fx=selectFX(window,wblock,wtrack);
  if(fx==NULL) return;

  Place place;
  PlaceCopy(&place, &wblock->reallines[wblock->curr_realline]->l.p);

  int val = (fx->max + fx->min)/2;

  AddFXNodeLineCurrPosInternal(window, wblock, wtrack, fx, &place, val);
}
Beispiel #10
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);
}
Beispiel #11
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));
}
Beispiel #12
0
static void InsertStop(
                       struct Tracker_Windows *window,
                       struct WBlocks *wblock,
                       struct WTracks *wtrack,
                       Place *placement
){
	struct Stops *stop;

        stop = (struct Stops*)talloc(sizeof(struct Stops));
	PlaceCopy(&stop->l.p,placement);

        PLAYER_lock();{
          StopAllNotesAtPlace(wblock->block,wtrack->track,placement);
  	  ListAddElement3_ns(&wtrack->track->stops,&stop->l);
        }PLAYER_unlock();
}
Beispiel #13
0
void setNoteEndPlace(int line,int counter,int dividor,int windownum,int blocknum,int tracknum,int notenum){
  struct Tracker_Windows *window;
  struct WBlocks *wblock;
  struct WTracks *wtrack;
  struct Notes *note = getNoteFromNumA(windownum, &window, blocknum, &wblock, tracknum, &wtrack, notenum);
  if (note==NULL)
    return;

  Place *place = PlaceCreate(line,counter,dividor);

  if (!PlaceLegal(wblock->block, place)) {
    GFX_Message(NULL, "Place %d + %d/%d is not legal", line, counter, dividor);
    return;
  }

  PlaceCopy(&note->end, place);
}
Beispiel #14
0
void CutNoteAt(struct Blocks *block, struct Tracks *track,struct Notes *note, Place *place){

  R_ASSERT(PLAYER_current_thread_has_lock() || is_playing()==false);
          
  if (PlaceGreaterOrEqual(place, &note->end)){
    RError("Illegal argument for CutNoteAt 1. %f >= %f\n",GetfloatFromPlacement(place),GetfloatFromPlacement(&note->end));
    return;
  }
  
  if (PlaceLessOrEqual(place, &note->l.p)){
    RError("Illegal argument for CutNoteAt 2. %f <= %f\n",GetfloatFromPlacement(place),GetfloatFromPlacement(&note->l.p));
    return;
  }
  
  CutListAt(&note->velocities,place);
  CutListAt(&note->pitches,place);
  PlaceCopy(&note->end,place);

}
Beispiel #15
0
struct Pitches *AddPitch(struct Tracker_Windows *window, struct WBlocks *wblock, struct WTracks *wtrack, struct Notes *note, Place *place, float notenum){
  struct Pitches *pitch = talloc(sizeof(struct Pitches));
  PlaceCopy(&pitch->l.p,place);
  pitch->note = notenum;
  //pitch->note_note = note;

  int pos;
  PC_Pause(); {
    pos=ListAddElement3_ns(&note->pitches, &pitch->l);
  }PC_StopPause();

  if(pos==-1)
    return NULL;
  
#if !USE_OPENGL
  ClearTrack(window,wblock,wtrack,wblock->top_realline,wblock->bot_realline);
  UpdateWTrack(window,wblock,wtrack,wblock->top_realline,wblock->bot_realline);
#endif
  return pitch;
}
Beispiel #16
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;
}
Beispiel #17
0
int AddFXNodeLine(
                  struct Tracker_Windows *window,
                  struct WBlocks *wblock,
                  struct WTracks *wtrack,
                  int fxnum,
                  int val,
                  const Place *p1
){
	struct FXs *fxs=ListFindElement1_r0(&wtrack->track->fxs->l,fxnum);
	struct FXNodeLines *fxnodeline=talloc(sizeof(struct FXNodeLines));

        int ret;
        
        PLAYER_lock();{
          fxnodeline->val=R_BOUNDARIES(fxs->fx->min, val, fxs->fx->max);
          PlaceCopy(&fxnodeline->l.p,p1);
          ret = ListAddElement3_ns(&fxs->fxnodelines,&fxnodeline->l);
        }PLAYER_unlock();

        return ret;
}
Beispiel #18
0
struct TempoNodes *AddTempoNode(
	struct Tracker_Windows *window,
	struct WBlocks *wblock,
	Place *p,
	float reltempo
){
	struct Blocks *block=wblock->block;
	struct TempoNodes *temponode;

	temponode=talloc(sizeof(struct TempoNodes));
	temponode->reltempo=reltempo;

	PlaceCopy(&temponode->l.p,p);

        Undo_TempoNodes_CurrPos(window);

	if(ListAddElement3_ns(&block->temponodes,&temponode->l)==-1) {
          Undo_CancelLastUndo();
          return NULL;
        } else
          return temponode;
}
Beispiel #19
0
/**************************************************************
  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);
	}
}
Beispiel #20
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);
}
Beispiel #21
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);
	}
}