Ejemplo n.º 1
0
static void schedule_next_LPB(struct SeqTrack *seqtrack, const struct SeqBlock *seqblock, const struct LPBs *next_lpb){
  R_ASSERT_RETURN_IF_FALSE(next_lpb != NULL);
  R_ASSERT_RETURN_IF_FALSE(seqblock!=NULL);
  
  const int num_args = 1;
        
  union SuperType args[num_args];
  args[0].const_pointer = seqblock;

  LPB_Iterator *iterator = &seqtrack->lpb_iterator;
    
  iterator->next_lpb = next_lpb;

  int64_t time = get_seqblock_place_time(seqblock, next_lpb->l.p);
  
  SCHEDULER_add_event(seqtrack, time, RT_scheduled_LPB, &args[0], num_args, SCHEDULER_LPB_PRIORITY);
}
Ejemplo n.º 2
0
static int64_t RT_scheduled_Signature(struct SeqTrack *seqtrack, int64_t time, union SuperType *args){

  const struct SeqBlock *seqblock = args[0].const_pointer;

  Signature_Iterator *iterator = &seqtrack->signature_iterator;

  const struct Signatures *signature = iterator->next_signature;
  
  iterator->signature_value = signature->signature;
  iterator->next_signature  = NextSignature(signature);

  //printf("   SIG %d/%d\n",iterator->signature_value.numerator, iterator->signature_value.denominator);
  
  // Schedule next signature
  if (iterator->next_signature != NULL)
    return get_seqblock_place_time(seqblock, iterator->next_signature->l.p);
  else
    return DONT_RESCHEDULE;
}
Ejemplo n.º 3
0
static void RT_schedule_reallines_in_block2(struct SeqTrack *seqtrack, struct SeqBlock *seqblock, struct WBlocks *wblock, int realline){
  R_ASSERT_RETURN_IF_FALSE(seqblock->block != NULL);

  if(realline>=wblock->num_reallines)
    return;

  const int num_args = 4;
    
  union SuperType args[num_args];

  args[0].const_pointer = seqblock;
  args[1].pointer = wblock;
  args[2].int32_num = realline;
  args[3].int_num = ++seqblock->curr_scheduled_realline_counter;

  Place realline_place = wblock->reallines[realline]->l.p;
  int64_t time = get_seqblock_place_time(seqblock, realline_place);

  SCHEDULER_add_event(seqtrack, time, RT_scheduled_realline, &args[0], num_args, SCHEDULER_INIT_PRIORITY);
}
Ejemplo n.º 4
0
void RT_schedule_Signature_newblock(struct SeqTrack *seqtrack,
                                    const struct SeqBlock *seqblock,
                                    const Place start_place)
{

  Signature_Iterator *iterator = &seqtrack->signature_iterator;
  memset(iterator, 0, sizeof(Signature_Iterator));
  iterator->signature_value = root->signature;
  //printf("   SIG Init %d/%d\n",iterator->signature_value.numerator, iterator->signature_value.denominator);
  
  const struct Blocks *block = seqblock->block;
    
  const struct Signatures *next_signature = block->signatures;

  if(next_signature==NULL)
    return;

  // spool forward to the 'signature' that is used by 'start_place'
  //
  while(PlaceGreaterThan(&start_place, &next_signature->l.p)){
    iterator->signature_value = next_signature->signature;
    //printf("   SIG Init %d/%d\n",iterator->signature_value.numerator, iterator->signature_value.denominator);
    next_signature = NextSignature(next_signature);
    if (next_signature==NULL)
      return;
  }

  iterator->next_signature = next_signature;
  
  {
    int num_args = 1;
    union SuperType args[num_args];
    args[0].const_pointer = seqblock;
    
    int64_t time = get_seqblock_place_time(seqblock, next_signature->l.p);
    
    SCHEDULER_add_event(seqtrack, time, RT_scheduled_Signature, &args[0], num_args, SCHEDULER_SIGNATURE_PRIORITY);
  }
}
Ejemplo n.º 5
0
static int64_t RT_scheduled_realline(struct SeqTrack *seqtrack, int64_t time, union SuperType *args){
  const struct SeqBlock *seqblock = args[0].const_pointer;
  struct WBlocks *wblock = args[1].pointer;
  int realline = args[2].int32_num;

  int64_t counter = args[3].int_num;

  //printf("%d. counter: %d / seqblock->counter: %d. Num reallines: %d\n", realline, (int)counter, (int)seqblock->curr_scheduled_realline_counter, wblock->num_reallines);


  if (seqblock->curr_scheduled_realline_counter > counter){ // I.e. this event have been replaced because the number of reallines was changed while playing.
    //printf("      stop1: %d / %d\n", (int)counter, (int)seqblock->curr_scheduled_realline_counter);
    return DONT_RESCHEDULE;
  }

  const int num_reallines = wblock->num_reallines;

  /*
  if (num_reallines != wblock->num_reallines){ // Happens when changing LZ value.
    realline = get_curr_realline_for_seqtrack(seqtrack);

    num_reallines = wblock->num_reallines;
    args[3].int32_num = num_reallines;
  }
  */
  
#ifdef WITH_PD
  bool inserted_pd_realline = false;
  int64_t org_time = time;
  const Place *org_pos = NULL;

  if (realline < num_reallines) // number of reallines can change while playing.
    org_pos = &wblock->reallines[realline]->l.p;
#endif

  // Do thing with the current realline
  setit(wblock, realline);

  
  // Schedule next realline
  //

  const int next_realline = realline+1;

  if(pc->playtype==PLAYRANGE){ // This never happens. Instead playtype is PLAYBLOCK, and pc->is_playing_range is true;
    R_ASSERT(false);
    /*
    if(next_realline>=wblock->rangey2){
      next_realline=wblock->rangey1;
    }

    // sanity checks to avoid crash. May happen if editing next_reallines while playing.
    if (next_realline>=wblock->num_next_reallines) // If outside range, first try to set next_realline to rangey1
      next_realline = wblock->rangey1;

    if (next_realline>=wblock->num_next_reallines) // that didn't work, set next_realline to 0
      next_realline = 0;
    */
  } else if (pc->playtype==PLAYBLOCK && pc->is_playing_range == true){

    if (next_realline>=num_reallines || p_Greater_Than(wblock->reallines[next_realline]->l.p, wblock->rangey2)){

      ATOMIC_SET(pc->player_state, PLAYER_STATE_STOPPING);
      
      //PC_ReturnElements();

      return DONT_RESCHEDULE;
    }
          
  }else if(next_realline>=num_reallines) {

    return DONT_RESCHEDULE;
    
  }

    
#ifdef WITH_PD
  if (org_pos != NULL)
    if(inserted_pd_realline==false)
      RT_PD_set_realline(org_time, time, org_pos);
#endif

  {
    args[2].int32_num = next_realline;
    Place next_place = wblock->reallines[next_realline]->l.p;

    //printf("       next_place: %d + %d/%d\n", next_place.line, next_place.counter, next_place.dividor);
    return get_seqblock_place_time(seqblock, next_place);
  }
}
Ejemplo n.º 6
0
static void RT_schedule_pitch(struct SeqTrack *seqtrack,
                              int64_t current_time,
                              const struct SeqBlock *seqblock,
                              const struct Tracks *track,
                              const struct Notes *note,
                              const struct Pitches *pitch1,
                              bool first_val_has_been_sent
                              )
{

  if(note->pitches==NULL && note->pitch_end == 0.0) // In case note is changed while playing
    return;

  const struct Pitches *pitch2 = pitch1==NULL ? note->pitches : NextPitch(pitch1);

  Place p1 = pitch1==NULL ? note->l.p : pitch1->l.p;
  Place p2 = pitch2==NULL ? note->end : pitch2->l.p;
  
  int64_t time1 = get_seqblock_place_time(seqblock, p1);
  int64_t time2 = get_seqblock_place_time(seqblock, p2);

  if (pitch2==NULL)
    time2--; // Can not send out pitch at the same time as note_end, since note_end events has higher priority than pitch events.
#if !defined(RELEASE)
  else
    R_ASSERT(time2 >= time1);
#endif
    
  if (time2 < time1)
    return;

  int logtype1 = pitch1==NULL ? note->pitch_first_logtype : pitch1->logtype;

  if (logtype1 == LOGTYPE_HOLD){

    if (current_time == time1) {
      
      RT_scheduled_hold_pitch_do(seqtrack, current_time, seqblock, track, note, pitch1, !first_val_has_been_sent);
                                    
    } else {
        
      const int num_args = 4;
    
      union SuperType args[num_args];
      args[0].const_pointer = seqblock;
      args[1].const_pointer = track;
      args[2].const_pointer = note;
      args[3].const_pointer = pitch1;
      
      SCHEDULER_add_event(seqtrack, time1, RT_scheduled_hold_pitch, &args[0], num_args, SCHEDULER_PITCH_PRIORITY);
    }
      
  } else {

    //int64_t time = R_MIN(time2, time1 + RADIUM_BLOCKSIZE);

    bool doit;

    if (pitch1==NULL)
      doit = true;
    else
      doit = pitch1->chance==0x100 || pitch1->chance > rnd(0x100);

    union SuperType args[g_num_pitches_args];
    args[0].const_pointer = seqblock;
    args[1].const_pointer = track;
    args[2].const_pointer = note;
    args[3].const_pointer = pitch1;
    args[4].int_num       = time1;
    args[5].int_num       = time2;
    args[6].bool_num      = doit;

#if DO_DEBUG
    float val1 = pitch1==NULL ? note->note      : pitch1->note;
    float val2 = pitch2==NULL ? note->pitch_end : pitch2->note;
    
    printf(" Scheduling Pitch. %f -> %f, %d -> %d\n", val1, val2, (int)time1, (int)time2);
#endif
  
    SCHEDULER_add_event(seqtrack, time1, RT_scheduled_glide_pitch, &args[0], g_num_pitches_args, SCHEDULER_PITCH_PRIORITY);

  }
}