2 #include <alsa/asoundlib.h>
10 snd_seq_t
* g_seq_ptr
;
11 lash_client_t
* g_lashc
;
12 jack_client_t
* g_jack_client
;
14 /* a flag which will be set by our signal handler when it's time to exit */
17 /* the signal handler */
25 process_lash_event(lash_event_t
* event_ptr
)
27 enum LASH_Event_Type type
;
30 type
= lash_event_get_type(event_ptr
);
31 str
= lash_event_get_string(event_ptr
);
36 printf("LASH_Quit received.\n");
41 case LASH_Restore_File
:
42 case LASH_Save_Data_Set
:
44 printf("LASH Event. Type = %u, string = \"%s\"\n",
46 (str
== NULL
)?"":str
);
51 process_lash_config(lash_config_t
* config_ptr
)
57 key
= lash_config_get_key(config_ptr
);
58 data
= lash_config_get_value(config_ptr
);
59 data_size
= lash_config_get_value_size(config_ptr
);
61 printf("LASH Config. Key = \"%s\"\n", key
);
65 main(int argc
, char *argv
[])
68 lash_event_t
* lash_event_ptr
;
69 lash_config_t
* lash_config_ptr
;
70 snd_seq_port_info_t
* seq_port_info
= NULL
;
71 snd_seq_event_t
* seq_event_ptr
;
75 /* setup our signal handler signalled() above, so we can exit cleanly (see end of main()) */
76 signal(SIGINT
, signalled
);
80 lash_extract_args(&argc
, &argv
),
83 LASH_PROTOCOL_VERSION
);
87 printf("Failed to connect to LASH. Session management will not occur.\n");
91 lash_event_ptr
= lash_event_new_with_type(LASH_Client_Name
);
92 lash_event_set_string(lash_event_ptr
, "jackctlmmc");
93 lash_send_event(g_lashc
, lash_event_ptr
);
96 /* naturally we need to become a jack client :) */
97 g_jack_client
= jack_client_new("jackctlmmc");
100 printf("couldn't connect to jack server. Either it's not running or the client name is already taken\n");
104 lash_jack_client_name(g_lashc
, "jackctlmmc");
106 /* ALSA sequencer initialisation */
114 printf("Cannot open sequncer, %s\n", snd_strerror(ret
));
118 snd_seq_set_client_name(g_seq_ptr
, "jackctlmmc");
120 lash_alsa_client_id(g_lashc
, snd_seq_client_id(g_seq_ptr
));
122 snd_seq_port_info_alloca(&seq_port_info
);
124 snd_seq_port_info_set_capability(
126 SND_SEQ_PORT_CAP_WRITE
|
127 SND_SEQ_PORT_CAP_SUBS_WRITE
);
128 snd_seq_port_info_set_type(
130 SND_SEQ_PORT_TYPE_APPLICATION
);
131 snd_seq_port_info_set_midi_channels(seq_port_info
, 16);
132 snd_seq_port_info_set_port_specified(seq_port_info
, 1);
134 snd_seq_port_info_set_name(seq_port_info
, "midi in");
135 snd_seq_port_info_set_port(seq_port_info
, 0);
137 ret
= snd_seq_create_port(g_seq_ptr
, seq_port_info
);
140 printf("Error creating ALSA sequencer port, %s\n", snd_strerror(ret
));
144 /* tell jack that we are ready to do our thing */
145 jack_activate(g_jack_client
);
147 npfd
= snd_seq_poll_descriptors_count(g_seq_ptr
, POLLIN
);
148 pfd
= (struct pollfd
*)alloca(npfd
* sizeof(struct pollfd
));
149 snd_seq_poll_descriptors(g_seq_ptr
, pfd
, npfd
, POLLIN
);
151 /* wait until this app receives a SIGINT (i.e. press ctrl-c in the terminal) see signalled() above */
154 if (poll(pfd
, npfd
, 250) > 0 && snd_seq_event_input(g_seq_ptr
, &seq_event_ptr
) >= 0)
156 if (seq_event_ptr
->type
== SND_SEQ_EVENT_SYSEX
&&
157 seq_event_ptr
->data
.ext
.len
== 6 &&
158 ((unsigned char *)seq_event_ptr
->data
.ext
.ptr
)[0] == 0xF0 &&
159 ((unsigned char *)seq_event_ptr
->data
.ext
.ptr
)[1] == 0x7F &&
160 ((unsigned char *)seq_event_ptr
->data
.ext
.ptr
)[2] == 0x7F && /* All devices */
161 ((unsigned char *)seq_event_ptr
->data
.ext
.ptr
)[3] == 0x06 &&
162 ((unsigned char *)seq_event_ptr
->data
.ext
.ptr
)[5] == 0xF7)
164 switch (((char *)seq_event_ptr
->data
.ext
.ptr
)[4])
167 printf("MMC Stop -> JACK transport stop\n");
168 jack_transport_stop(g_jack_client
);
171 printf("MMC Play -> JACK transport start\n");
172 jack_transport_start(g_jack_client
);
175 printf("MMC Play -> JACK transport locate to 0\n");
176 jack_transport_locate(g_jack_client
, 0);
182 /* Process LASH events */
183 while ((lash_event_ptr
= lash_get_event(g_lashc
)) != NULL
)
185 process_lash_event(lash_event_ptr
);
186 lash_event_destroy(lash_event_ptr
);
189 /* Process LASH configs */
190 while ((lash_config_ptr
= lash_get_config(g_lashc
)) != NULL
)
192 process_lash_config(lash_config_ptr
);
193 lash_config_destroy(lash_config_ptr
);
197 /* so we shall quit, eh? ok, cleanup time. otherwise jack would probably produce an xrun
199 jack_deactivate(g_jack_client
);
202 ret
= snd_seq_close(g_seq_ptr
);
205 printf("Cannot close sequncer, %s\n", snd_strerror(ret
));
210 jack_client_close(g_jack_client
);