Exemplo n.º 1
0
void Player_AD::parseSlot(Channel *channel) {
	while (true) {
		const byte *curOffset = channel->currentOffset;

		switch (*curOffset) {
		case 1:
			// INSTRUMENT DEFINITION
			++curOffset;
			channel->instrumentData[0] = *(curOffset + 0);
			channel->instrumentData[1] = *(curOffset + 2);
			channel->instrumentData[2] = *(curOffset + 9);
			channel->instrumentData[3] = *(curOffset + 8);
			channel->instrumentData[4] = *(curOffset + 4);
			channel->instrumentData[5] = *(curOffset + 3);
			channel->instrumentData[6] = 0;

			setupChannel(channel->hardwareChannel, curOffset);

			writeReg(0xA0 + channel->hardwareChannel, *(curOffset + 0));
			writeReg(0xB0 + channel->hardwareChannel, *(curOffset + 1) & 0xDF);

			channel->currentOffset += 15;
			break;

		case 2:
			// NOTE DEFINITION
			++curOffset;
			channel->state = kChannelStatePlay;
			noteOffOn(channel->hardwareChannel);
			parseNote(&channel->notes[0], *channel, curOffset + 0);
			parseNote(&channel->notes[1], *channel, curOffset + 5);
			return;

		case 0x80:
			// LOOP
			channel->currentOffset = channel->startOffset;
			break;

		default:
			// START OF CHANNEL
			// When we encounter a start of another channel while playback
			// it means that the current channel is finished. Thus, we will
			// stop it.
			clearChannel(*channel);
			channel->state = kChannelStateOff;
			return;
		}
	}
}
Exemplo n.º 2
0
 void Parser::parseSeqNotes()
 {
   qDebug() << "Parser::parseSeqNotes() value:" << qPrintable(lex.symValue());
   while (lex.symType() == GRACE || lex.symType() == NOTE || lex.symType() == TIE || lex.symType() == TRIPLET)
   {
     if (lex.symType() == GRACE) parseGraces();
     else if (lex.symType() == NOTE) parseNote();
     else if (lex.symType() == TIE)
     {
       if (lex.symValue() == "^ts")
       {
         if (inTie) errorHandler("tie start ('^ts') unexpected");
         else tieStart = true;
       }
       else
       {
         errorHandler("tie end ('^te') unexpected");
       }
       lex.getSym();
     }
     else if (lex.symType() == TRIPLET)
     {
       if (lex.symValue() == "^3s")
       {
         if (inTriplet) errorHandler("triplet start ('^3s') unexpected");
         else tripletStart = true;
       }
       else
       {
         errorHandler("triplet end ('^3e') unexpected");
       }
       lex.getSym();
     }
   }
 }
Exemplo n.º 3
0
void PaeInput::convertMeasure(MeasureObject *measure ) {
    
    if ( measure->clef != NULL ) {
        m_layer->AddLayerElement(measure->clef);
    }
    
    if ( measure->key != NULL) {
        m_layer->AddLayerElement(measure->key);
    }
    
    if ( measure->meter != NULL ) {
        m_layer->AddLayerElement(measure->meter);
    }
    
    if ( measure->wholerest > 0 ) { 
        MultiRest *mr = new MultiRest();
        mr->SetNum(measure->wholerest);
        m_layer->AddLayerElement(mr);
    }
    
    m_nested_objects.clear();

    for (unsigned int i=0; i<measure->notes.size(); i++) {
        NoteObject note = measure->notes[i];
        parseNote(note);
    }
    
    // Set barLine
    // FIXME use flags for proper barLine identification
    Barline *bline = m_measure->GetRightBarline();
    bline->SetRend( measure->barLine );

}
Exemplo n.º 4
0
int Melody::nextNote(int carretPosition)
{
  if (strlen(notePos) <2)
  {
    // nothing to play
    return 0;
  }
  
  int noteKey;
  int noteDuration;
  int byteLength;
  int isSharp;
  
  if (!parseNote(notePos, noteKey, noteLength, byteLength, isSharp))
  {
    return 0;    
  }

  int octavePosition = (noteKey - C4_KEY) % 12; 
  if (octavePosition < 0)
  {
    octavePosition += 12;
  }
    
  int octave = floor((noteKey - C4_KEY) / 12.0);
  
  if (debugFlag)
  {
    sprintf(txtBuffer, "parse %d %d %d %d", noteKey, noteLength, byteLength, isSharp);
    Serial.println(txtBuffer);    
  }
  
  int positionsForFingers[5];
  for (int i = 0; i < 5; i++)
  {
    positionsForFingers[i] = C4_LEFT_SIDE + octave * OCTAVE_SIZE + noteOffset[octavePosition] - FINGER_POSITIONS[i];
  }
  
  if (isSharp)
  {
    positionsForFingers[0] = positionsForFingers[4] = -1000; // sharp notes cannot be played with these fingers
    activeFinger = 3; // start value
  }
  else
  {
    positionsForFingers[1] = positionsForFingers[2] = positionsForFingers[3] = - 1000; // non-sharp notes cannot be played with these fingers
    activeFinger = 4; // start value    
  }
  
  int distance = 500;
  
  for (int i = 0; i < 5; i++)
  {
    // ignore negative and very small positions
    if (positionsForFingers[i] < 5)
    {
      continue;
    }
    
    int curDistance = abs(carretPosition - positionsForFingers[i]);
    if ((isSharp && curDistance < 3) || (!isSharp && curDistance < 5))
    {
      // finger is already in tolerance interval above the desired note
      activeFinger = i;
      distance = curDistance;
    }
    if (curDistance < 35)
    {
      // hand cannot be moved precisely on short distances
      continue;
    }
    else if (curDistance < distance)
    {
      distance = curDistance;
      activeFinger = i;
    }
  }
  handPosition = positionsForFingers[activeFinger];
  
  notePos+= byteLength;
  return 1;
}