int KeyboardWidget::BtnDown(int x, int y, int ctrl, int shift)
{
    playing = 1;
    FindKey(x, y);
    form->Redraw(this);
    PlayNote(lastKey+baseKey, KEY_DOWN, lastVel);
    return 1;
}
void KeyboardWidget::PlayNote(int key, int e, int vel)
{
    if (selectInstr == NULL || theProject == NULL)
        return;

    if (e == KEY_CHANGE && changeNew)
    {
        // stop last note
        PlayNote(key, KEY_UP, vel);
        e = KEY_DOWN;
    }

    // activeInstr keeps track of which instrument started the note.
    // We need to keep playing on the same instrument until a Key up happens,
    // even if the selected instrument changes.
    if (!activeInstr)
        activeInstr = selectInstr;

    NoteEvent *evt = (NoteEvent*) theProject->mgr.ManufEvent(activeInstr);
    evt->SetChannel(curChnl);
    evt->SetStart(0);
    evt->SetDuration((bsInt32) (synthParams.sampleRate * curDur));
    evt->SetVolume(curVol);
    evt->SetPitch(key);
    evt->SetVelocity(vel);

    switch (e)
    {
    case KEY_CHANGE:
        // change current note
        evt->SetType(SEQEVT_PARAM);
        break;
    case KEY_DOWN:
        evtID = (evtID + 1) & 0x7FFFFFFF;
        evt->SetType(SEQEVT_START);
        break;
    case KEY_UP:
        evt->SetType(SEQEVT_STOP);
        activeInstr = 0;
        break;
    default:
        //OutputDebugString("Kbd event is unknown...\r\n");
        evt->Destroy();
        return;
    }
    evt->SetID(evtID);

    theProject->PlayEvent(evt);
    // NB: player will delete event. Don't touch it after calling PlayEvent!

    if (recording && e == KEY_DOWN)
    {
        RecNote *note = new RecNote(key, curRhythm, (int)(curVol*100.0));
        recTail->InsertBefore(note);
    }
}
Example #3
0
void CChannelHandler::UpdateDelay()
{
	// Delay (Gxx)
	if (m_bDelayEnabled) {
		if (!m_cDelayCounter) {
			m_bDelayEnabled = false;
			PlayNote(&m_cnDelayed, m_iDelayEffColumns);
		}
		else
			m_cDelayCounter--;
	}
}
int KeyboardWidget::MouseMove(int x, int y, int ctrl, int shift)
{
    if (playing)
    {
        if (FindKey(x, y))
        {
            PlayNote(lastKey+baseKey, KEY_CHANGE, lastVel);
            form->Redraw(this);
        }
        return 1;
    }
    return 0;
}
int KeyboardWidget::BtnUp(int x, int y, int ctrl, int shift)
{
    playing = 0;
    PlayNote(lastKey+baseKey, KEY_UP, lastVel);
    if (rcLastKey)
    {
        InvalidateLast();
        rcLastKey = 0;
        lastKey = -1;
        form->Redraw(this);
    }
    return 1;
}
Example #6
0
void SoundFX::PlaySound(void)
{
	uint32 *patternAdr;

	// Find the pattern address
	patternAdr = patterns[orders[trackPos]] + posCounter;

	// Parse the pattern data
	PlayNote(&channelInfo[0], virtChannels[0], patternAdr[0]);
	PlayNote(&channelInfo[1], virtChannels[1], patternAdr[1]);
	PlayNote(&channelInfo[2], virtChannels[2], patternAdr[2]);
	PlayNote(&channelInfo[3], virtChannels[3], patternAdr[3]);

	// Did we need to break the current pattern?
	if (breakFlag)
	{
		breakFlag  = false;
		posCounter = 4 * 63;
	}

	// Go to the next pattern line
	posCounter += 4;
	if (posCounter == 4 * 64)
	{
		// Okay, the pattern is done, go to the next pattern
		posCounter = 0;
		trackPos++;

		// Tell APlayer we have changed the position
		ChangePosition();

		if (trackPos == songLength)
		{
			// Module is done, loop it
			trackPos   = 0;
			endReached = true;
		}
	}
}
Example #7
0
static void 
NoteButtonPressed (Int16 note)
{
  NoteType n = {note, 100, 40, 20};

  /* replace (selected) or append (to end) note */
  if (notelist.selected == -1)
    notelist_append(&notelist, &n);
  else {
    notelist_updateSelected(&notelist, &n);
    if (++notelist.selected >= notelist.num)
      notelist.selected = -1;
  }

  SeekScrollBar(SCL_END);
  notelist_draw(&notelist);
  PlayNote (&n);
}
Example #8
0
int main(void) {

    init();

    Serial.begin(9600);

    SetupPort();
    SetupTimer();

    /* repeat forever */
    while (1) {

        for (int thisNote = 0; thisNote < size; thisNote++)
            PlayNote(melody[thisNote],duration[thisNote],FULL_NOTE);

        delay(2000);
    }
    return 0;
}
Example #9
0
VOID PlayTune(Note *tune, BYTE volume)
{
	do {
		PlayNote(tune, volume);
	} while ((++tune)->Value != TUNE_END_VALUE);
}
Example #10
0
MMRESULT
ProcessShortMidiMessage(
    DeviceInfo* device_info,
    DWORD message)
{
    DWORD status;

    DWORD category;
    DWORD channel;
    DWORD data1, data2;

    status = message & 0x000000FF;

    /* Deal with running status */

    if ( status < MIDI_NOTE_OFF )
    {
        status = device_info->running_status;
    }

    /* Ensure the status is sane! */

    if ( status < MIDI_NOTE_OFF )
    {
        /* It's garbage, ignore it */
        return MMSYSERR_NOERROR;
    }

    /* Figure out the message category and channel */

    category = status & 0xF0;
    channel = status & 0x0F;    /* we don't use this */

    data1 = (message & 0x0000FF00) >> 8;
    data2 = (message & 0x00FF0000) >> 16;

    DPRINT("0x%x, %d, %d\n", (int) status, (int) data1, (int) data2);

    /* Filter drums (which are *usually* on channel 10) */
    if ( channel == 10 )
    {
        return MMSYSERR_NOERROR;
    }

    /* Pass to the appropriate message handler */

    switch ( category )
    {
        case MIDI_NOTE_ON :
        {
            PlayNote(device_info, data1, data2);
            break;
        }

        case MIDI_NOTE_OFF :
        {
            StopNote(device_info, data1);
            break;
        }
    }

    return MMSYSERR_NOERROR;
}