1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
5 * gmidimonitor main code.
8 * GNU GENERAL PUBLIC LICENSE version 2
10 *****************************************************************************/
13 #include <alsa/asoundlib.h>
16 #include <lash/lash.h>
21 GtkWidget
* g_main_window_ptr
;
23 snd_seq_t
* g_seq_ptr
;
25 gboolean g_midi_ignore
= FALSE
;
29 lash_client_t
* g_lashc
;
31 static const char * g_note_names
[12] =
47 static const char * g_gm_instrument_names
[] =
49 "Acoustic Grand Piano", /* 1 */
50 "Bright Acoustic Piano", /* 2 */
51 "Electric Grand Piano", /* 3 */
52 "Honky-tonk Piano", /* 4 */
53 "Electric Piano 1", /* 5 */
54 "Electric Piano 2", /* 6 */
55 "Harpsichord", /* 7 */
58 "Glockenspiel", /* 10 */
60 "Vibraphone", /* 12 */
63 "Tubular Bells", /* 15 */
65 "Drawbar Organ", /* 17 */
66 "Percussive Organ", /* 18 */
67 "Rock Organ", /* 19 */
68 "Church Organ", /* 20 */
69 "Reed Organ", /* 21 */
72 "Tango Accordion", /* 24 */
73 "Acoustic Guitar (nylon)", /* 25 */
74 "Acoustic Guitar (steel)", /* 26 */
75 "Electric Guitar (jazz)", /* 27 */
76 "Electric Guitar (clean)", /* 28 */
77 "Electric Guitar (muted)", /* 29 */
78 "Overdriven Guitar", /* 30 */
79 "Distortion Guitar", /* 31 */
80 "Guitar harmonics", /* 32 */
81 "Acoustic Bass", /* 33 */
82 "Electric Bass (finger)", /* 34 */
83 "Electric Bass (pick)", /* 35 */
84 "Fretless Bass", /* 36 */
85 "Slap Bass 1", /* 37 */
86 "Slap Bass 2", /* 38 */
87 "Synth Bass 1", /* 39 */
88 "Synth Bass 2", /* 40 */
92 "Contrabass", /* 44 */
93 "Tremolo Strings", /* 45 */
94 "Pizzicato Strings", /* 46 */
95 "Orchestral Harp", /* 47 */
97 "String Ensemble 1", /* 49 */
98 "String Ensemble 2", /* 50 */
99 "SynthStrings 1", /* 51 */
100 "SynthStrings 2", /* 52 */
101 "Choir Aahs", /* 53 */
102 "Voice Oohs", /* 54 */
103 "Synth Voice", /* 55 */
104 "Orchestra Hit", /* 56 */
108 "Muted Trumpet", /* 60 */
109 "French Horn", /* 61 */
110 "Brass Section", /* 62 */
111 "SynthBrass 1", /* 63 */
112 "SynthBrass 2", /* 64 */
113 "Soprano Sax", /* 65 */
115 "Tenor Sax", /* 67 */
116 "Baritone Sax", /* 68 */
118 "English Horn", /* 70 */
124 "Pan Flute", /* 76 */
125 "Blown Bottle", /* 77 */
126 "Shakuhachi", /* 78 */
129 "Lead 1 (square)", /* 81 */
130 "Lead 2 (sawtooth)", /* 82 */
131 "Lead 3 (calliope)", /* 83 */
132 "Lead 4 (chiff)", /* 84 */
133 "Lead 5 (charang)", /* 85 */
134 "Lead 6 (voice)", /* 86 */
135 "Lead 7 (fifths)", /* 87 */
136 "Lead 8 (bass + lead)", /* 88 */
137 "Pad 1 (new age)", /* 89 */
138 "Pad 2 (warm)", /* 90 */
139 "Pad 3 (polysynth)", /* 91 */
140 "Pad 4 (choir)", /* 92 */
141 "Pad 5 (bowed)", /* 93 */
142 "Pad 6 (metallic)", /* 94 */
143 "Pad 7 (halo)", /* 95 */
144 "Pad 8 (sweep)", /* 96 */
145 "FX 1 (rain)", /* 97 */
146 "FX 2 (soundtrack)", /* 98 */
147 "FX 3 (crystal)", /* 99 */
148 "FX 4 (atmosphere)", /* 100 */
149 "FX 5 (brightness)", /* 101 */
150 "FX 6 (goblins)", /* 102 */
151 "FX 7 (echoes)", /* 103 */
152 "FX 8 (sci-fi)", /* 104 */
155 "Shamisen", /* 107 */
158 "Bag pipe", /* 110 */
161 "Tinkle Bell", /* 113 */
163 "Steel Drums", /* 115 */
164 "Woodblock", /* 116 */
165 "Taiko Drum", /* 117 */
166 "Melodic Tom", /* 118 */
167 "Synth Drum", /* 119 */
168 "Reverse Cymbal", /* 120 */
169 "Guitar Fret Noise", /* 121 */
170 "Breath Noise", /* 122 */
171 "Seashore", /* 123 */
172 "Bird Tweet", /* 124 */
173 "Telephone Ring", /* 125 */
174 "Helicopter", /* 126 */
175 "Applause", /* 127 */
179 static const char * g_gm_drum_names
[] =
181 "Acoustic Bass Drum", /* 35 */
182 "Bass Drum 1", /* 36 */
183 "Side Stick", /* 37 */
184 "Acoustic Snare", /* 38 */
185 "Hand Clap", /* 39 */
186 "Electric Snare", /* 40 */
187 "Low Floor Tom", /* 41 */
188 "Closed Hi-Hat", /* 42 */
189 "High Floor Tom", /* 43 */
190 "Pedal Hi-Hat", /* 44 */
192 "Open Hi-Hat", /* 46 */
193 "Low-Mid Tom", /* 47 */
194 "Hi-Mid Tom", /* 48 */
195 "Crash Cymbal 1", /* 49 */
197 "Ride Cymbal 1", /* 51 */
198 "Chinese Cymbal", /* 52 */
199 "Ride Bell", /* 53 */
200 "Tambourine", /* 54 */
201 "Splash Cymbal", /* 55 */
203 "Crash Cymbal 2", /* 57 */
204 "Vibraslap", /* 58 */
205 "Ride Cymbal 2", /* 59 */
207 "Low Bongo", /* 61 */
208 "Mute Hi Conga", /* 62 */
209 "Open Hi Conga", /* 63 */
210 "Low Conga", /* 64 */
211 "High Timbale", /* 65 */
212 "Low Timbale", /* 66 */
213 "High Agogo", /* 67 */
214 "Low Agogo", /* 68 */
217 "Short Whistle", /* 71 */
218 "Long Whistle", /* 72 */
219 "Short Guiro", /* 73 */
220 "Long Guiro", /* 74 */
222 "Hi Wood Block", /* 76 */
223 "Low Wood Block", /* 77 */
224 "Mute Cuica", /* 78 */
225 "Open Cuica", /* 79 */
226 "Mute Triangle", /* 80 */
227 "Open Triangle", /* 81 */
238 #define MAX_LIST_SIZE 2000
243 GtkWidget
* child_ptr
;
244 GtkListStore
* list_store_ptr
;
245 GtkTreeViewColumn
* column_ptr
;
246 GtkCellRenderer
* text_renderer_ptr
;
248 g_main_window_ptr
= construct_glade_widget("main_window");
250 child_ptr
= get_glade_widget_child(g_main_window_ptr
, "list");
252 text_renderer_ptr
= gtk_cell_renderer_text_new();
255 G_OBJECT(text_renderer_ptr
),
260 /* column_ptr = gtk_tree_view_column_new_with_attributes( */
262 /* text_renderer_ptr, */
263 /* "text", COL_TIME, */
266 /* gtk_tree_view_append_column( */
267 /* GTK_TREE_VIEW(child_ptr), */
270 column_ptr
= gtk_tree_view_column_new_with_attributes(
276 gtk_tree_view_append_column(
277 GTK_TREE_VIEW(child_ptr
),
280 column_ptr
= gtk_tree_view_column_new_with_attributes(
286 gtk_tree_view_append_column(
287 GTK_TREE_VIEW(child_ptr
),
290 gtk_widget_show_all(g_main_window_ptr
);
292 list_store_ptr
= gtk_list_store_new(
298 gtk_tree_view_set_model(GTK_TREE_VIEW(child_ptr
), GTK_TREE_MODEL(list_store_ptr
));
301 /* stop button toggle */
302 void on_button_stop_toggled(
303 GtkAction
* action_ptr
,
304 GtkWidget
* widget_ptr
)
306 GtkWidget
* child_ptr
;
308 child_ptr
= get_glade_widget_child(widget_ptr
, "button_stop");
310 if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(child_ptr
)))
312 g_midi_ignore
= TRUE
;
316 g_midi_ignore
= FALSE
;
320 void on_clear_clicked
321 (GtkButton
*button
, gpointer user_data
)
323 gtk_list_store_clear(
325 gtk_tree_view_get_model(
327 get_glade_widget_child(
333 /* The midi input handling thread */
335 midi_thread(void * context_ptr
)
338 snd_seq_event_t
* event_ptr
;
339 GtkListStore
* list_store_ptr
;
340 GtkWidget
* child_ptr
;
341 GString
* time_str_ptr
;
342 GString
* msg_str_ptr
;
343 GString
* channel_str_ptr
;
344 const char * note_name
;
346 const char * drum_name
;
347 const char * cc_name
;
349 const char * mmc_command_name
;
351 child_ptr
= get_glade_widget_child(g_main_window_ptr
, "list");
353 list_store_ptr
= GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(child_ptr
)));
357 while (snd_seq_event_input(g_seq_ptr
, &event_ptr
) >= 0)
362 time_str_ptr
= g_string_new("");
366 (unsigned int)event_ptr
->time
.time
.tv_sec
,
367 (unsigned int)event_ptr
->time
.time
.tv_nsec
);
368 channel_str_ptr
= g_string_new("");
370 if (event_ptr
->type
== SND_SEQ_EVENT_NOTE
||
371 event_ptr
->type
== SND_SEQ_EVENT_NOTEON
||
372 event_ptr
->type
== SND_SEQ_EVENT_NOTEOFF
||
373 event_ptr
->type
== SND_SEQ_EVENT_KEYPRESS
)
378 (unsigned int)event_ptr
->data
.note
.channel
+1);
379 if (event_ptr
->data
.note
.channel
+1 == 10 &&
380 event_ptr
->data
.note
.note
>= 35 &&
381 event_ptr
->data
.note
.note
< 35 + sizeof(g_gm_drum_names
)/sizeof(g_gm_drum_names
[0]))
383 drum_name
= g_gm_drum_names
[event_ptr
->data
.note
.note
- 35];
390 note_name
= g_note_names
[event_ptr
->data
.note
.note
% 12];
391 octave
= event_ptr
->data
.note
.note
/ 12 - 1;
394 if (event_ptr
->type
== SND_SEQ_EVENT_CONTROLLER
||
395 event_ptr
->type
== SND_SEQ_EVENT_PGMCHANGE
||
396 event_ptr
->type
== SND_SEQ_EVENT_PITCHBEND
)
401 (unsigned int)event_ptr
->data
.control
.channel
+1);
404 msg_str_ptr
= g_string_new("unknown event");
406 switch (event_ptr
->type
)
408 case SND_SEQ_EVENT_SYSTEM
:
409 g_string_sprintf(msg_str_ptr
, "System event");
411 case SND_SEQ_EVENT_RESULT
:
412 g_string_sprintf(msg_str_ptr
, "Result status event");
414 case SND_SEQ_EVENT_NOTE
:
415 g_string_sprintf(msg_str_ptr
, "Note");
417 case SND_SEQ_EVENT_NOTEON
:
418 if (event_ptr
->data
.note
.velocity
!= 0)
420 if (drum_name
!= NULL
)
424 "Drum: %s (%s, octave %d, velocity %u)",
428 event_ptr
->data
.note
.velocity
);
434 "Note on , %s, octave %d, velocity %u",
437 event_ptr
->data
.note
.velocity
);
441 case SND_SEQ_EVENT_NOTEOFF
:
442 if (drum_name
!= NULL
) /* ignore note off for drums */
447 "Note off, %s, octave %d",
452 case SND_SEQ_EVENT_KEYPRESS
:
453 g_string_sprintf(msg_str_ptr
, "Key pressure change (aftertouch)");
455 case SND_SEQ_EVENT_CONTROLLER
:
457 switch (event_ptr
->data
.control
.param
)
459 case MIDI_CTL_MSB_BANK
:
460 cc_name
= "Bank selection";
462 case MIDI_CTL_MSB_MODWHEEL
:
463 cc_name
= "Modulation";
465 case MIDI_CTL_MSB_BREATH
:
468 case MIDI_CTL_MSB_FOOT
:
471 case MIDI_CTL_MSB_PORTAMENTO_TIME
:
472 cc_name
= "Portamento time";
474 case MIDI_CTL_MSB_DATA_ENTRY
:
475 cc_name
= "Data entry";
477 case MIDI_CTL_MSB_MAIN_VOLUME
:
478 cc_name
= "Main volume";
480 case MIDI_CTL_MSB_BALANCE
:
483 case MIDI_CTL_MSB_PAN
:
486 case MIDI_CTL_MSB_EXPRESSION
:
487 cc_name
= "Expression";
489 case MIDI_CTL_MSB_EFFECT1
:
492 case MIDI_CTL_MSB_EFFECT2
:
495 case MIDI_CTL_MSB_GENERAL_PURPOSE1
:
496 cc_name
= "General purpose 1";
498 case MIDI_CTL_MSB_GENERAL_PURPOSE2
:
499 cc_name
= "General purpose 2";
501 case MIDI_CTL_MSB_GENERAL_PURPOSE3
:
502 cc_name
= "General purpose 3";
504 case MIDI_CTL_MSB_GENERAL_PURPOSE4
:
505 cc_name
= "General purpose 4";
507 case MIDI_CTL_LSB_BANK
:
508 cc_name
= "Bank selection";
510 case MIDI_CTL_LSB_MODWHEEL
:
511 cc_name
= "Modulation";
513 case MIDI_CTL_LSB_BREATH
:
516 case MIDI_CTL_LSB_FOOT
:
519 case MIDI_CTL_LSB_PORTAMENTO_TIME
:
520 cc_name
= "Portamento time";
522 case MIDI_CTL_LSB_DATA_ENTRY
:
523 cc_name
= "Data entry";
525 case MIDI_CTL_LSB_MAIN_VOLUME
:
526 cc_name
= "Main volume";
528 case MIDI_CTL_LSB_BALANCE
:
531 case MIDI_CTL_LSB_PAN
:
534 case MIDI_CTL_LSB_EXPRESSION
:
535 cc_name
= "Expression";
537 case MIDI_CTL_LSB_EFFECT1
:
540 case MIDI_CTL_LSB_EFFECT2
:
543 case MIDI_CTL_LSB_GENERAL_PURPOSE1
:
544 cc_name
= "General purpose 1";
546 case MIDI_CTL_LSB_GENERAL_PURPOSE2
:
547 cc_name
= "General purpose 2";
549 case MIDI_CTL_LSB_GENERAL_PURPOSE3
:
550 cc_name
= "General purpose 3";
552 case MIDI_CTL_LSB_GENERAL_PURPOSE4
:
553 cc_name
= "General purpose 4";
555 case MIDI_CTL_SUSTAIN
:
556 cc_name
= "Sustain pedal";
558 case MIDI_CTL_PORTAMENTO
:
559 cc_name
= "Portamento";
561 case MIDI_CTL_SOSTENUTO
:
562 cc_name
= "Sostenuto";
564 case MIDI_CTL_SOFT_PEDAL
:
565 cc_name
= "Soft pedal";
567 case MIDI_CTL_LEGATO_FOOTSWITCH
:
568 cc_name
= "Legato foot switch";
573 case MIDI_CTL_SC1_SOUND_VARIATION
:
574 cc_name
= "SC1 Sound Variation";
576 case MIDI_CTL_SC2_TIMBRE
:
577 cc_name
= "SC2 Timbre";
579 case MIDI_CTL_SC3_RELEASE_TIME
:
580 cc_name
= "SC3 Release Time";
582 case MIDI_CTL_SC4_ATTACK_TIME
:
583 cc_name
= "SC4 Attack Time";
585 case MIDI_CTL_SC5_BRIGHTNESS
:
586 cc_name
= "SC5 Brightness";
603 case MIDI_CTL_GENERAL_PURPOSE5
:
604 cc_name
= "General purpose 5";
606 case MIDI_CTL_GENERAL_PURPOSE6
:
607 cc_name
= "General purpose 6";
609 case MIDI_CTL_GENERAL_PURPOSE7
:
610 cc_name
= "General purpose 7";
612 case MIDI_CTL_GENERAL_PURPOSE8
:
613 cc_name
= "General purpose 8";
615 case MIDI_CTL_PORTAMENTO_CONTROL
:
616 cc_name
= "Portamento control";
618 case MIDI_CTL_E1_REVERB_DEPTH
:
619 cc_name
= "E1 Reverb Depth";
621 case MIDI_CTL_E2_TREMOLO_DEPTH
:
622 cc_name
= "E2 Tremolo Depth";
624 case MIDI_CTL_E3_CHORUS_DEPTH
:
625 cc_name
= "E3 Chorus Depth";
627 case MIDI_CTL_E4_DETUNE_DEPTH
:
628 cc_name
= "E4 Detune Depth";
630 case MIDI_CTL_E5_PHASER_DEPTH
:
631 cc_name
= "E5 Phaser Depth";
633 case MIDI_CTL_DATA_INCREMENT
:
634 cc_name
= "Data Increment";
636 case MIDI_CTL_DATA_DECREMENT
:
637 cc_name
= "Data Decrement";
639 case MIDI_CTL_NONREG_PARM_NUM_LSB
:
640 cc_name
= "Non-registered parameter number";
642 case MIDI_CTL_NONREG_PARM_NUM_MSB
:
643 cc_name
= "Non-registered parameter number";
645 case MIDI_CTL_REGIST_PARM_NUM_LSB
:
646 cc_name
= "Registered parameter number";
648 case MIDI_CTL_REGIST_PARM_NUM_MSB
:
649 cc_name
= "Registered parameter number";
651 case MIDI_CTL_ALL_SOUNDS_OFF
:
652 cc_name
= "All sounds off";
654 case MIDI_CTL_RESET_CONTROLLERS
:
655 cc_name
= "Reset Controllers";
657 case MIDI_CTL_LOCAL_CONTROL_SWITCH
:
658 cc_name
= "Local control switch";
660 case MIDI_CTL_ALL_NOTES_OFF
:
661 cc_name
= "All notes off";
663 case MIDI_CTL_OMNI_OFF
:
664 cc_name
= "Omni off";
666 case MIDI_CTL_OMNI_ON
:
681 "CC %s (%u), value %u",
683 (unsigned int)event_ptr
->data
.control
.param
,
684 (unsigned int)event_ptr
->data
.control
.value
);
691 (unsigned int)event_ptr
->data
.control
.param
,
692 (unsigned int)event_ptr
->data
.control
.value
);
695 case SND_SEQ_EVENT_PGMCHANGE
:
698 "Program change, %d (%s)",
699 (unsigned int)event_ptr
->data
.control
.value
,
700 event_ptr
->data
.control
.value
>= sizeof(g_gm_instrument_names
)/sizeof(g_gm_instrument_names
[0])?
702 g_gm_instrument_names
[event_ptr
->data
.control
.value
]);
704 case SND_SEQ_EVENT_CHANPRESS
:
705 g_string_sprintf(msg_str_ptr
, "Channel pressure");
707 case SND_SEQ_EVENT_PITCHBEND
:
711 (unsigned int)event_ptr
->data
.control
.value
);
713 case SND_SEQ_EVENT_CONTROL14
:
714 g_string_sprintf(msg_str_ptr
, "14 bit controller value");
716 case SND_SEQ_EVENT_NONREGPARAM
:
717 g_string_sprintf(msg_str_ptr
, "NRPN");
719 case SND_SEQ_EVENT_REGPARAM
:
720 g_string_sprintf(msg_str_ptr
, "RPN");
722 case SND_SEQ_EVENT_SONGPOS
:
723 g_string_sprintf(msg_str_ptr
, "Song position");
725 case SND_SEQ_EVENT_SONGSEL
:
726 g_string_sprintf(msg_str_ptr
, "Song select");
728 case SND_SEQ_EVENT_QFRAME
:
729 g_string_sprintf(msg_str_ptr
, "midi time code quarter frame");
731 case SND_SEQ_EVENT_TIMESIGN
:
732 g_string_sprintf(msg_str_ptr
, "SMF Time Signature event");
734 case SND_SEQ_EVENT_KEYSIGN
:
735 g_string_sprintf(msg_str_ptr
, "SMF Key Signature event");
737 case SND_SEQ_EVENT_START
:
738 g_string_sprintf(msg_str_ptr
, "MIDI Real Time Start message");
740 case SND_SEQ_EVENT_CONTINUE
:
741 g_string_sprintf(msg_str_ptr
, "MIDI Real Time Continue message");
743 case SND_SEQ_EVENT_STOP
:
744 g_string_sprintf(msg_str_ptr
, "MIDI Real Time Stop message");
746 case SND_SEQ_EVENT_SETPOS_TICK
:
747 g_string_sprintf(msg_str_ptr
, "Set tick queue position");
749 case SND_SEQ_EVENT_SETPOS_TIME
:
750 g_string_sprintf(msg_str_ptr
, "Set real-time queue position");
752 case SND_SEQ_EVENT_TEMPO
:
753 g_string_sprintf(msg_str_ptr
, "(SMF) Tempo event");
755 case SND_SEQ_EVENT_CLOCK
:
756 g_string_sprintf(msg_str_ptr
, "MIDI Real Time Clock message");
758 case SND_SEQ_EVENT_TICK
:
759 g_string_sprintf(msg_str_ptr
, "MIDI Real Time Tick message");
761 case SND_SEQ_EVENT_QUEUE_SKEW
:
762 g_string_sprintf(msg_str_ptr
, "Queue timer skew");
764 case SND_SEQ_EVENT_SYNC_POS
:
765 g_string_sprintf(msg_str_ptr
, "Sync position changed");
767 case SND_SEQ_EVENT_TUNE_REQUEST
:
768 g_string_sprintf(msg_str_ptr
, "Tune request");
770 case SND_SEQ_EVENT_RESET
:
771 g_string_sprintf(msg_str_ptr
, "Reset");
773 case SND_SEQ_EVENT_SENSING
:
774 continue; /* disable */
775 g_string_sprintf(msg_str_ptr
, "Active sensing");
777 case SND_SEQ_EVENT_ECHO
:
778 g_string_sprintf(msg_str_ptr
, "Echo-back event");
780 case SND_SEQ_EVENT_OSS
:
781 g_string_sprintf(msg_str_ptr
, "OSS emulation raw event");
783 case SND_SEQ_EVENT_CLIENT_START
:
784 g_string_sprintf(msg_str_ptr
, "New client has connected");
786 case SND_SEQ_EVENT_CLIENT_EXIT
:
787 g_string_sprintf(msg_str_ptr
, "Client has left the system");
789 case SND_SEQ_EVENT_CLIENT_CHANGE
:
790 g_string_sprintf(msg_str_ptr
, "Client status/info has changed");
792 case SND_SEQ_EVENT_PORT_START
:
793 g_string_sprintf(msg_str_ptr
, "New port was created");
795 case SND_SEQ_EVENT_PORT_EXIT
:
796 g_string_sprintf(msg_str_ptr
, "Port was deleted from system");
798 case SND_SEQ_EVENT_PORT_CHANGE
:
799 g_string_sprintf(msg_str_ptr
, "Port status/info has changed");
801 case SND_SEQ_EVENT_PORT_SUBSCRIBED
:
802 g_string_sprintf(msg_str_ptr
, "Port connected");
804 case SND_SEQ_EVENT_PORT_UNSUBSCRIBED
:
805 g_string_sprintf(msg_str_ptr
, "Port disconnected");
807 case SND_SEQ_EVENT_SAMPLE
:
808 g_string_sprintf(msg_str_ptr
, "Sample select");
810 case SND_SEQ_EVENT_SAMPLE_CLUSTER
:
811 g_string_sprintf(msg_str_ptr
, "Sample cluster select");
813 case SND_SEQ_EVENT_SAMPLE_START
:
814 g_string_sprintf(msg_str_ptr
, "voice start");
816 case SND_SEQ_EVENT_SAMPLE_STOP
:
817 g_string_sprintf(msg_str_ptr
, "voice stop");
819 case SND_SEQ_EVENT_SAMPLE_FREQ
:
820 g_string_sprintf(msg_str_ptr
, "playback frequency");
822 case SND_SEQ_EVENT_SAMPLE_VOLUME
:
823 g_string_sprintf(msg_str_ptr
, "volume and balance");
825 case SND_SEQ_EVENT_SAMPLE_LOOP
:
826 g_string_sprintf(msg_str_ptr
, "sample loop");
828 case SND_SEQ_EVENT_SAMPLE_POSITION
:
829 g_string_sprintf(msg_str_ptr
, "sample position");
831 case SND_SEQ_EVENT_SAMPLE_PRIVATE1
:
832 g_string_sprintf(msg_str_ptr
, "private (hardware dependent) event");
834 case SND_SEQ_EVENT_USR0
:
835 g_string_sprintf(msg_str_ptr
, "user-defined event");
837 case SND_SEQ_EVENT_USR1
:
838 g_string_sprintf(msg_str_ptr
, "user-defined event");
840 case SND_SEQ_EVENT_USR2
:
841 g_string_sprintf(msg_str_ptr
, "user-defined event");
843 case SND_SEQ_EVENT_USR3
:
844 g_string_sprintf(msg_str_ptr
, "user-defined event");
846 case SND_SEQ_EVENT_USR4
:
847 g_string_sprintf(msg_str_ptr
, "user-defined event");
849 case SND_SEQ_EVENT_USR5
:
850 g_string_sprintf(msg_str_ptr
, "user-defined event");
852 case SND_SEQ_EVENT_USR6
:
853 g_string_sprintf(msg_str_ptr
, "user-defined event");
855 case SND_SEQ_EVENT_USR7
:
856 g_string_sprintf(msg_str_ptr
, "user-defined event");
858 case SND_SEQ_EVENT_USR8
:
859 g_string_sprintf(msg_str_ptr
, "user-defined event");
861 case SND_SEQ_EVENT_USR9
:
862 g_string_sprintf(msg_str_ptr
, "user-defined event");
864 case SND_SEQ_EVENT_INSTR_BEGIN
:
865 g_string_sprintf(msg_str_ptr
, "begin of instrument management");
867 case SND_SEQ_EVENT_INSTR_END
:
868 g_string_sprintf(msg_str_ptr
, "end of instrument management");
870 case SND_SEQ_EVENT_INSTR_INFO
:
871 g_string_sprintf(msg_str_ptr
, "query instrument interface info");
873 case SND_SEQ_EVENT_INSTR_INFO_RESULT
:
874 g_string_sprintf(msg_str_ptr
, "result of instrument interface info");
876 case SND_SEQ_EVENT_INSTR_FINFO
:
877 g_string_sprintf(msg_str_ptr
, "query instrument format info");
879 case SND_SEQ_EVENT_INSTR_FINFO_RESULT
:
880 g_string_sprintf(msg_str_ptr
, "result of instrument format info");
882 case SND_SEQ_EVENT_INSTR_RESET
:
883 g_string_sprintf(msg_str_ptr
, "reset instrument instrument memory");
885 case SND_SEQ_EVENT_INSTR_STATUS
:
886 g_string_sprintf(msg_str_ptr
, "get instrument interface status");
888 case SND_SEQ_EVENT_INSTR_STATUS_RESULT
:
889 g_string_sprintf(msg_str_ptr
, "result of instrument interface status");
891 case SND_SEQ_EVENT_INSTR_PUT
:
892 g_string_sprintf(msg_str_ptr
, "put an instrument to port");
894 case SND_SEQ_EVENT_INSTR_GET
:
895 g_string_sprintf(msg_str_ptr
, "get an instrument from port");
897 case SND_SEQ_EVENT_INSTR_GET_RESULT
:
898 g_string_sprintf(msg_str_ptr
, "result of instrument query");
900 case SND_SEQ_EVENT_INSTR_FREE
:
901 g_string_sprintf(msg_str_ptr
, "free instrument(s)");
903 case SND_SEQ_EVENT_INSTR_LIST
:
904 g_string_sprintf(msg_str_ptr
, "get instrument list");
906 case SND_SEQ_EVENT_INSTR_LIST_RESULT
:
907 g_string_sprintf(msg_str_ptr
, "result of instrument list");
909 case SND_SEQ_EVENT_INSTR_CLUSTER
:
910 g_string_sprintf(msg_str_ptr
, "set cluster parameters");
912 case SND_SEQ_EVENT_INSTR_CLUSTER_GET
:
913 g_string_sprintf(msg_str_ptr
, "get cluster parameters");
915 case SND_SEQ_EVENT_INSTR_CLUSTER_RESULT
:
916 g_string_sprintf(msg_str_ptr
, "result of cluster parameters");
918 case SND_SEQ_EVENT_INSTR_CHANGE
:
919 g_string_sprintf(msg_str_ptr
, "instrument change");
921 case SND_SEQ_EVENT_SYSEX
:
922 /* General MMC decoding, as seen at http://www.borg.com/~jglatt/tech/mmc.htm and
923 extended from "Advanced User Guide for MK-449C MIDI keyboard" info */
924 if (event_ptr
->data
.ext
.len
== 6 &&
925 ((guint8
*)event_ptr
->data
.ext
.ptr
)[0] == 0xF0 &&
926 ((guint8
*)event_ptr
->data
.ext
.ptr
)[1] == 0x7F &&
927 ((guint8
*)event_ptr
->data
.ext
.ptr
)[3] == 0x06 &&
928 ((guint8
*)event_ptr
->data
.ext
.ptr
)[5] == 0xF7)
930 switch (((guint8
*)event_ptr
->data
.ext
.ptr
)[4])
933 mmc_command_name
= "Stop";
936 mmc_command_name
= "Play";
939 mmc_command_name
= "Deferred Play";
942 mmc_command_name
= "Fast Forward";
945 mmc_command_name
= "Rewind";
948 mmc_command_name
= "Record Strobe (Punch In)";
951 mmc_command_name
= "Record Exit (Punch Out)";
954 mmc_command_name
= "Record Pause";
957 mmc_command_name
= "Pause";
960 mmc_command_name
= "Eject";
963 mmc_command_name
= "Chase";
966 mmc_command_name
= "Command Error Reset";
969 mmc_command_name
= "Reset";
979 if (((guint8
*)event_ptr
->data
.ext
.ptr
)[2] == 127)
987 g_string_append_printf(
990 (unsigned int)(((guint8
*)event_ptr
->data
.ext
.ptr
)[2]));
993 /* The goto MMC message, as seen at http://www.borg.com/~jglatt/tech/mmc.htm*/
994 else if (event_ptr
->data
.ext
.len
== 13 &&
995 ((guint8
*)event_ptr
->data
.ext
.ptr
)[0] == 0xF0 &&
996 ((guint8
*)event_ptr
->data
.ext
.ptr
)[1] == 0x7F &&
997 ((guint8
*)event_ptr
->data
.ext
.ptr
)[3] == 0x06 &&
998 ((guint8
*)event_ptr
->data
.ext
.ptr
)[4] == 0x44 &&
999 ((guint8
*)event_ptr
->data
.ext
.ptr
)[5] == 0x06 &&
1000 ((guint8
*)event_ptr
->data
.ext
.ptr
)[6] == 0x01 &&
1001 ((guint8
*)event_ptr
->data
.ext
.ptr
)[12] == 0xF7)
1005 "MMC goto %u:%u:%u/%u:%u",
1006 (unsigned int)(((guint8
*)event_ptr
->data
.ext
.ptr
)[7] & 0x1F),
1007 (unsigned int)(((guint8
*)event_ptr
->data
.ext
.ptr
)[8]),
1008 (unsigned int)(((guint8
*)event_ptr
->data
.ext
.ptr
)[9]),
1009 (unsigned int)(((guint8
*)event_ptr
->data
.ext
.ptr
)[10]),
1010 (unsigned int)(((guint8
*)event_ptr
->data
.ext
.ptr
)[11]));
1012 switch (((guint8
*)event_ptr
->data
.ext
.ptr
)[7] & 0x60)
1036 if (((guint8
*)event_ptr
->data
.ext
.ptr
)[2] == 127)
1040 ", for all devices");
1044 g_string_append_printf(
1047 (unsigned int)(((guint8
*)event_ptr
->data
.ext
.ptr
)[2]));
1055 "SYSEX with size %u:",
1056 (unsigned int)event_ptr
->data
.ext
.len
);
1057 for (i
= 0 ; i
< event_ptr
->data
.ext
.len
; i
++)
1059 g_string_append_printf(
1062 (unsigned int)(((guint8
*)event_ptr
->data
.ext
.ptr
)[i
]));
1066 case SND_SEQ_EVENT_BOUNCE
:
1067 g_string_sprintf(msg_str_ptr
, "error event");
1069 case SND_SEQ_EVENT_USR_VAR0
:
1070 g_string_sprintf(msg_str_ptr
, "reserved for user apps");
1072 case SND_SEQ_EVENT_USR_VAR1
:
1073 g_string_sprintf(msg_str_ptr
, "reserved for user apps");
1075 case SND_SEQ_EVENT_USR_VAR2
:
1076 g_string_sprintf(msg_str_ptr
, "reserved for user apps");
1078 case SND_SEQ_EVENT_USR_VAR3
:
1079 g_string_sprintf(msg_str_ptr
, "reserved for user apps");
1081 case SND_SEQ_EVENT_USR_VAR4
:
1082 g_string_sprintf(msg_str_ptr
, "reserved for user apps");
1086 /* get GTK thread lock */
1087 gdk_threads_enter();
1089 if (g_row_count
>= MAX_LIST_SIZE
)
1091 gtk_tree_model_get_iter_first(
1092 GTK_TREE_MODEL(list_store_ptr
),
1095 gtk_list_store_remove(
1100 /* Append an empty row to the list store. Iter will point to the new row */
1101 gtk_list_store_append(list_store_ptr
, &iter
);
1106 COL_TIME
, time_str_ptr
->str
,
1107 COL_CHANNEL
, channel_str_ptr
->str
,
1108 COL_MESSAGE
, msg_str_ptr
->str
,
1111 g_string_free(channel_str_ptr
, TRUE
);
1112 g_string_free(msg_str_ptr
, TRUE
);
1114 gtk_tree_view_scroll_to_cell(
1115 GTK_TREE_VIEW(child_ptr
),
1116 gtk_tree_model_get_path(
1117 gtk_tree_view_get_model(GTK_TREE_VIEW(child_ptr
)),
1124 /* Force update of scroll position. */
1125 /* Is it a bug that it does not update automagically ? */
1126 gtk_container_check_resize(GTK_CONTAINER(child_ptr
));
1128 /* release GTK thread lock */
1129 gdk_threads_leave();
1138 process_lash_event(lash_event_t
* event_ptr
)
1140 enum LASH_Event_Type type
;
1143 type
= lash_event_get_type(event_ptr
);
1144 str
= lash_event_get_string(event_ptr
);
1149 g_warning("LASH_Quit received.\n");
1153 case LASH_Save_File
:
1154 case LASH_Restore_File
:
1155 case LASH_Save_Data_Set
:
1157 g_warning("LASH Event. Type = %u, string = \"%s\"\n",
1159 (str
== NULL
)?"":str
);
1164 process_lash_config(lash_config_t
* config_ptr
)
1170 key
= lash_config_get_key(config_ptr
);
1171 data
= lash_config_get_value(config_ptr
);
1172 data_size
= lash_config_get_value_size(config_ptr
);
1174 g_warning("LASH Config. Key = \"%s\"\n", key
);
1177 /* process lash events callback */
1179 process_lash_events(gpointer data
)
1181 lash_event_t
* event_ptr
;
1182 lash_config_t
* config_ptr
;
1184 /* Process events */
1185 while ((event_ptr
= lash_get_event(g_lashc
)) != NULL
)
1187 process_lash_event(event_ptr
);
1188 lash_event_destroy(event_ptr
);
1191 /* Process configs */
1192 while ((config_ptr
= lash_get_config(g_lashc
)) != NULL
)
1194 process_lash_config(config_ptr
);
1195 lash_config_destroy(config_ptr
);
1202 main(int argc
, char *argv
[])
1205 snd_seq_port_info_t
* port_info
= NULL
;
1207 lash_event_t
* lash_event_ptr
;
1208 GString
* seq_client_name_str_ptr
;
1211 g_thread_init(NULL
);
1213 gdk_threads_enter();
1215 gtk_init(&argc
, &argv
);
1219 g_lashc
= lash_init(
1220 lash_extract_args(&argc
, &argv
),
1223 LASH_PROTOCOL_VERSION
);
1225 if (g_lashc
== NULL
)
1227 g_warning("Failed to connect to LASH. Session management will not occur.\n");
1231 lash_event_ptr
= lash_event_new_with_type(LASH_Client_Name
);
1232 lash_event_set_string(lash_event_ptr
, "GMIDImonitor");
1233 lash_send_event(g_lashc
, lash_event_ptr
);
1234 g_timeout_add(250, process_lash_events
, NULL
);
1237 /* interface creation */
1238 create_mainwindow();
1240 /* initialisation */
1248 g_warning("Cannot open sequncer, %s\n", snd_strerror(ret
));
1252 seq_client_name_str_ptr
= g_string_new("");
1253 g_string_sprintf(seq_client_name_str_ptr
, "MIDI monitor (%u)", (unsigned int)getpid());
1254 snd_seq_set_client_name(g_seq_ptr
, seq_client_name_str_ptr
->str
);
1256 lash_alsa_client_id(g_lashc
, snd_seq_client_id(g_seq_ptr
));
1258 snd_seq_port_info_alloca(&port_info
);
1260 snd_seq_port_info_set_capability(
1262 SND_SEQ_PORT_CAP_WRITE
|
1263 SND_SEQ_PORT_CAP_SUBS_WRITE
);
1264 snd_seq_port_info_set_type(
1266 SND_SEQ_PORT_TYPE_APPLICATION
);
1267 snd_seq_port_info_set_midi_channels(port_info
, 16);
1268 snd_seq_port_info_set_port_specified(port_info
, 1);
1270 snd_seq_port_info_set_name(port_info
, "midi in");
1271 snd_seq_port_info_set_port(port_info
, 0);
1273 ret
= snd_seq_create_port(g_seq_ptr
, port_info
);
1276 g_warning("Error creating ALSA sequencer port, %s\n", snd_strerror(ret
));
1280 /* Start midi thread */
1281 ret
= pthread_create(&midi_tid
, NULL
, midi_thread
, NULL
);
1286 /* Cancel the thread. Don't know better way.
1287 Poll or unblock mechanisms seem to not be
1288 available for alsa sequencer */
1289 pthread_cancel(midi_tid
);
1291 /* Wait midi thread to finish */
1292 ret
= pthread_join(midi_tid
, NULL
);
1294 gdk_threads_leave();
1297 ret
= snd_seq_close(g_seq_ptr
);
1300 g_warning("Cannot close sequncer, %s\n", snd_strerror(ret
));