Example #1
0
void MidiDevice::SendEvent(int Device,const MidiEvent &Event)
{
#ifdef ALSA_MIDI
	snd_seq_event_t ev;
	snd_seq_ev_clear      (&ev);
  	snd_seq_ev_set_direct (&ev);
	snd_seq_ev_set_subs   (&ev);
    snd_seq_ev_set_source (&ev, 0);
  	
	switch (Event.GetType())
	{
		case MidiEvent::ON : ev.type = SND_SEQ_EVENT_NOTEON; break;
		case MidiEvent::OFF : ev.type = SND_SEQ_EVENT_NOTEOFF; break;
		case MidiEvent::AFTERTOUCH : break;
		case MidiEvent::PARAMETER : break;
		case MidiEvent::CHANNELPRESSURE : break;
		case MidiEvent::PITCHBEND : break;
		case MidiEvent::NONE : break;
	}
	
	ev.data.note.velocity = (char)(Event.GetVolume()*127.0f);
	ev.data.control.channel = Device;
	ev.data.note.note=Event.GetNote();
	
	int ret=snd_seq_event_output(seq_handle, &ev);
	snd_seq_drain_output(seq_handle);
#else
	if (Device<0 || Device>15)
	{
		cerr<<"SendEvent: Invalid Midi device "<<Device<<endl;		
	}

	char message[3];
	
	message[1]=Event.GetNote()+MIDI_KEYOFFSET;
	message[2]=(char)Event.GetVolume();
	
	if (Event.GetType()==MidiEvent::ON)
	{
		message[0]=STATUS_NOTE_ON+Device;
		write(m_MidiWrFd,message,3);
		//cerr<<"sending "<<message<<endl;
	}
	
	if (Event.GetType()==MidiEvent::OFF)
	{
		message[0]=STATUS_NOTE_OFF+Device;
		write(m_MidiWrFd,message,3);	
		//cerr<<"sending "<<message<<endl;
	}
#endif
}