32 |
} |
} |
33 |
|
|
34 |
int MidiIn::open_alsa_midi_seq(void) { |
int MidiIn::open_alsa_midi_seq(void) { |
|
int portid; |
|
35 |
if (snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_INPUT, 0) < 0) { |
if (snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_INPUT, 0) < 0) { |
36 |
fprintf(stderr, "Error opening ALSA sequencer.\n"); |
fprintf(stderr, "Error opening ALSA sequencer.\n"); |
37 |
exit(1); |
exit(1); |
38 |
} |
} |
39 |
|
this->AlsaID = snd_seq_client_id(seq_handle); |
40 |
snd_seq_set_client_name(seq_handle, "LinuxSampler"); |
snd_seq_set_client_name(seq_handle, "LinuxSampler"); |
41 |
if ((portid = snd_seq_create_simple_port(seq_handle, "LinuxSampler", |
if ((this->AlsaPort = snd_seq_create_simple_port(seq_handle, "LinuxSampler", |
42 |
SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE, |
SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE, |
43 |
SND_SEQ_PORT_TYPE_APPLICATION)) < 0) { |
SND_SEQ_PORT_TYPE_APPLICATION)) < 0) { |
44 |
fprintf(stderr, "Error creating sequencer port.\n"); |
fprintf(stderr, "Error creating sequencer port.\n"); |
45 |
exit(1); |
exit(1); |
46 |
} |
} |
50 |
void MidiIn::close_alsa_midi_seq(void) { |
void MidiIn::close_alsa_midi_seq(void) { |
51 |
} |
} |
52 |
|
|
53 |
|
/** |
54 |
|
* Makes a connection to another Alsa sequencer client, so that all MIDI |
55 |
|
* events from e.g. a keyboard are always delivered to us. |
56 |
|
* |
57 |
|
* @param Client - Alsa sequencer client ID and port string to connect to |
58 |
|
* (e.g. "64:0") |
59 |
|
*/ |
60 |
|
void MidiIn::SubscribeToClient(const char* Client) { |
61 |
|
snd_seq_addr_t sender, dest; |
62 |
|
snd_seq_port_subscribe_t* subs; |
63 |
|
sscanf(Client, "%d:%d", sender.client, sender.port); |
64 |
|
dest.client = this->AlsaID; |
65 |
|
dest.port = this->AlsaPort; |
66 |
|
snd_seq_port_subscribe_alloca(&subs); |
67 |
|
snd_seq_port_subscribe_set_sender(subs, &sender); |
68 |
|
snd_seq_port_subscribe_set_dest(subs, &dest); |
69 |
|
snd_seq_port_subscribe_set_queue(subs, 1); |
70 |
|
snd_seq_port_subscribe_set_time_update(subs, 1); |
71 |
|
snd_seq_port_subscribe_set_time_real(subs, 1); |
72 |
|
int res = snd_seq_subscribe_port(this->seq_handle, subs); |
73 |
|
if (!res) { |
74 |
|
fprintf(stderr, "Unable to subscribe to client \'%s\'\n", Client); |
75 |
|
} |
76 |
|
} |
77 |
|
|
78 |
int MidiIn::Main() { |
int MidiIn::Main() { |
79 |
int res = open_alsa_midi_seq(); |
int res = open_alsa_midi_seq(); |
80 |
if (res < 0) { |
if (res < 0) { |