Reputation: 1100
I'm using a raspberry pi, so it is sort of Debian (Raspbian)
I have a synthesizer running (Zynaddsubfx) and I want to send him midi messages from code and have it playing the music for me. I will use ALSA for that.
I managed to create a "emitting port" in my program by doing:
snd_seq_create_simple_port(seq_handle, "My own sequencer",
SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_SUBS_READ,
SND_SEQ_PORT_TYPE_APPLICATION)
now I can see ZynSubAddFX in aconnect -ol
and my own sequencer in aconnect -il
. And I'm able to connect them:
pi@cacharro:~/projects/tests$ aconnect 129:0 128:0
pi@cacharro:~/projects/tests$ Info, alsa midi port connected
for doing that, as sugested by CL I used opened snd_seq_open, stored the sequence and then used snd_seq_create_simple_port.. BUT :
As commented before I just wanna send commands to zynsubaddfx under user interaction so creating queues, adding tempo and so on is not the way to go.
Is there a way to send simple midi comands like note on/note off through my opened port ???
Upvotes: 1
Views: 2150
Reputation: 180060
To send some events at a specific time:
To open the sequencer, call snd_seq_open
.
(You can get your client number with snd_seq_client_id
.)
snd_seq_t seq;
snd_seq_open(&seq, "default", SND_SEQ_OPEN_DUPLEX, 0);
To create a port, allocate a port info object with
snd_seq_port_info_alloca
, set port parameters with
snd_seq_port_info_set_
xxx, and call snd_seq_create_port
.
Or simply call snd_seq_create_simple_port
.
int port;
port = snd_seq_create_simple_port(seq, "my port",
SND_SEQ_PORT_CAP_READ | SND_SEQ_POR_CAP_WRITE,
SND_SEQ_PORT_TYPE_APPLICATION);
To send an event, allocate an event structure (just
for a change, you can use a local snd_seq_event_t
variable),
and call various snd_seq_ev_
xxx functions to set its properties.
Then call snd_seq_event_output
, and snd_seq_drain_output
after you've sent all
events.
snd_seq_event_t ev;
snd_seq_ev_clear(&ev);
snd_seq_ev_set_direct(&ev);
/* either */
snd_seq_ev_set_dest(&ev, 64, 0); /* send to 64:0 */
/* or */
snd_seq_ev_set_subs(&ev); /* send to subscribers of source port */
snd_seq_ev_set_noteon(&ev, 0, 60, 127);
snd_seq_event_output(seq, &ev);
snd_seq_ev_set_noteon(&ev, 0, 67, 127);
snd_seq_event_output(seq, &ev);
snd_seq_drain_output(seq);
Upvotes: 3