Debian Codegraph @

examples/midikbd

raw
1 #! /usr/bin/perl
2 #########################################################################
3 # This Perl script is Copyright (c) 2010, Peter J Billam #
4 # www.pjb.com.au #
5 # #
6 # This script is free software; you can redistribute it and/or #
7 # modify it under the same terms as Perl itself. #
8 #########################################################################
9 # 20150529 a UI change to include the other pedals ?
10 # F1,F2=Una-corda F3,F4=Tre-corde F5,F6=Sos-pedal F7,F8=Sos-pedal-off
11 # F9,F10=Pedal F11,F12=Pedal-off ?
12 # ^[[15~^[OP^[OQ^[OR^[OS ^[[15~^[[17~^[[18~^[[19~ ^[[20~^[[21~^[[23~^[[24~
13 # F1,F2=Una F3,F4=Tre F5,F6=Sos F7,F8=*Sos F9,F10=Ped F11,F12=*Ped
14
15 use Term::ReadKey;
16 use bytes;
17 #use Term::Size(); my ($Xmax, $Ymax) = Term::Size::chars;
18 my ($Xmax, $Ymax) = Term::ReadKey::GetTerminalSize;
19 # warn "Xmax=$Xmax Ymax=$Ymax\n";
20 eval 'require MIDI::ALSA'; if ($@) { die
21 "you'll need to install the MIDI::ALSA module from www.cpan.org\n";
22 }
23 eval 'require Term::Clui'; if ($@) { die
24 "you'll need to install the Term::Clui module from www.cpan.org\n";
25 }
26 my $CurrentX; my $CurrentY;
27 my $Version = '5.8'; # X and Y mouse-control of pitchwheel displayed
28 my $VersionDate = '03jun2015';
29 my $Channel = 0;
30 my $Volume = 100;
31 my $Pan = 64;
32 my $Transpose = 0;
33 my $Quiet = 0;
34 my $PedalIsOn = 0;
35 my $SosPedIsOn = 0;
36 my $UnaPedIsOn = 0;
37 my $PedalLineNum;
38 my $KeyMap = 'augmented';
39 my %KeyMaps = ( # 4.0
40 a=>'augmented', d=>'drumkit', h=>'harmonic', p=>'piano', w=>'wholetone',
41 );
42 my %Cha2patch;
43 my %Cha2pan;
44 my $LastTra; # the last (transposed) note that's been played.
45 my $OutputPort;
46 my @Synopsis; my %Keystrokes;
47 my $CursorRow = 6;
48 # vt100 globals
49 my $Irow = 1;
50 my $Icol = 1;
51 my $MidCol = 32;
52 # mouse-related stuff, version 3.6
53 my %Cha2Xcontroller = ();
54 my %Cha2Ycontroller = ();
55 # remember the Controllers that have been set
56 my @Cha2cc = (); # list of hashes
57
58 # http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
59 # use bytes;
60 # print STDERR "\e[?1003h"; # sets SET_ANY_EVENT_MOUSE mode
61 # ^[[M#XY where X is (chr(32+x)) and Y is (chr(32+y)), top-left is !!=1,1
62 # and LeftButtonPress = ^[[M XY Mid = ^[[M!XY Right = ^[[M"XY
63 # print STDERR "\e[?1003l"; # resets SET_ANY_EVENT_MOUSE mode
64
65 while ($ARGV[$[] =~ /^-([CPa-z])([adhpw]?)/) {
66 my $opt = $1;
67 if ($opt eq 'v') { shift;
68 my $n = $0; $n =~ s{^.*/([^/]+)$}{$1};
69 print "$n version $Version $VersionDate\n";
70 exit 0;
71 } elsif ($opt eq 'd' or $opt eq 'o') { shift; $OutputPort = shift;
72 } elsif ($opt eq 'p') { shift; $OutputPort = shift;
73 } elsif ($opt eq 'C') { shift;
74 warn "warning: -C option is now deprecated; see perldoc midikbd\n";
75 while (my $next_arg = shift) { process_channel_spec($next_arg); }
76 } elsif ($opt eq 'P') { shift; $Cha2patch{$Channel} = 0+shift;
77 } elsif ($opt eq 'k') {
78 shift;
79 if ($KeyMaps{$2}) { $KeyMap = $KeyMaps{$2};
80 } else { $KeyMap = shift;
81 }
82 } elsif ($opt eq 'q') { shift; $Quiet = 1;
83 } else { print "usage:\n"; my $synopsis = 0;
84 while (<DATA>) {
85 if (/^=head1 SYNOPSIS/) { push @Synopsis,$_; $synopsis=1; next; }
86 if ($synopsis && /^=head1/) { last; }
87 if ($synopsis) { print $_; next; }
88 }
89 exit 1;
90 }
91 }
92 foreach my $channel_spec (@ARGV) { process_channel_spec($channel_spec); }
93
94 sub debug {
95 open (T, '>>', '/tmp/debug');
96 print T $_[$[],"\n";
97 close T;
98 }
99
100 my $in_syn; my $in_keys;
101 while (<DATA>) {
102 if (/^ +Q = Quit/) {
103 if ($KeyMap eq 'drumkit') { push @Synopsis, " Q = Quit\n";
104 } else { push @Synopsis, $_;
105 }
106 $in_syn = 1; next;
107 }
108 if ($in_syn && /^$/) { last; }
109 if ($in_syn) {
110 if (/octave|semitone/ && ($KeyMap eq 'drumkit')) { next; }
111 push @Synopsis, $_;
112 }
113 }
114 while (<DATA>) {
115 if (/^ the "$KeyMap" keymap/) {
116 $in_keys = 1; push @{$Keystrokes{$KeyMap}}, $_; next;
117 }
118 if ($in_keys && /^$/) { last; }
119 if ($in_keys) { push @{$Keystrokes{$KeyMap}}, $_; }
120 }
121 my %Char2note = char2note($KeyMap);
122
123 # MIDI::ALSA::client( "midikbd pid=$$", 0, 1, 0 );
124 MIDI::ALSA::client( "midikbd", 0, 1, 0 ); # workaraound for alsa-lib 1.0.24
125
126 if ($OutputPort ne '0') { # 5.4
127 if (!$OutputPort) { $OutputPort = $ENV{'ALSA_OUTPUT_PORTS'}; }
128 if (!$OutputPort) {
129 warn "OutputPort not specified and ALSA_OUTPUT_PORTS not set\n";
130 }
131 foreach my $cl_po (split /,/, $OutputPort) { # 5.0
132 if (! MIDI::ALSA::connectto( 0, $cl_po )) {
133 die "can't connect to ALSA client $cl_po\n";
134 }
135 }
136 }
137
138 $SIG{'INT'} = sub { exit 0; }; # so that after ^C the END-blocks run
139
140 # In this ALSA version, we don't need to be able to write to stdout...
141
142 ReadMode(4, STDIN);
143 # should do this for all keys of %Cha2patch, e.g. for feeding into midiecho
144 # if (defined $Cha2patch{$Channel}) { new_patch($Cha2patch{$Channel}); }
145 foreach my $c (keys %Cha2patch) { set_patch($c, $Cha2patch{$c}); }
146 foreach my $c (keys %Cha2pan) { set_pan( $c, $Cha2pan{$c}); }
147 display_alsa();
148 if ($KeyMap ne 'drumkit') {
149 display_channel(); display_patch(); display_transpose();
150 }
151 display_note(); display_volume(); display_pan();
152 display_midi_controllers(); # 4.9
153 if (!$Quiet) { display_keystrokes(); }
154
155 if (%Cha2Xcontroller or %Cha2Ycontroller) { set_mouse_mode(); } # 3.6
156
157 while (1) {
158 my $c = ReadKey(0, STDIN);
159 # reserve S=SustainPed B=Bank G=GeneralMidi M=Monophonic K=KeyMap
160 if ($c eq "Q") { note_off(); last;
161 } elsif ($c eq "P") { new_patch(); next;
162 } elsif ($c eq "C") { new_channel(); next;
163 } elsif ($c eq "U") { # 3.2
164 if ($KeyMap ne 'drumkit') { $Transpose += 1; display_transpose(); }
165 next;
166 } elsif ($c eq "D") { # 3.2
167 if ($KeyMap ne 'drumkit') { $Transpose -= 1; display_transpose(); }
168 next;
169 } elsif ($c eq 'M') { new_midi_controller(); next; # 4.2
170 } elsif ($c eq 'X') { new_Xcontroller(); next; # 4.3
171 } elsif ($c eq 'Y') { new_Ycontroller(); next; # 4.3
172 } elsif ($c eq "\e") { escape_seq(); next;
173 } elsif ($c eq "A") { new_alsa(); next; # 4.6
174 }
175 my $note = $Char2note{$c};
176 my $tra = $note + $Transpose ;
177 if ($tra > 127 ) { $tra = 127;
178 } elsif ($tra < 0) { $tra = 0;
179 }
180 # my $b = chr($tra);
181 note_off();
182 if (defined $note) {
183 MIDI::ALSA::output(MIDI::ALSA::noteonevent($Channel,$tra,$Volume));
184 $LastTra = $tra;
185 }
186 display_note($note, $tra);
187 # else { warn "c is ".ord($c)."\n"; }
188 }
189 if (!$Quiet) { clean_screen(); }
190 if ($PedalIsOn) {
191 # my $b = chr(0xB0 + $Channel); print $OFH "$b\x40\x00";
192 MIDI::ALSA::output(MIDI::ALSA::controllerevent($Channel,64,0));
193 }
194 close $OFH;
195 ReadMode(0, STDIN);
196
197 # ------------------- infrastructure -------------------
198 sub display_alsa {
199 my @ConnectedTo = ();
200 my $id = MIDI::ALSA::id();
201 foreach (MIDI::ALSA::listconnectedto()) {
202 my @cl = @$_;
203 push @ConnectedTo, "$cl[1]:$cl[2]"
204 }
205 gotoxy(1,1);
206 my $s = "ALSA client $id, midikbd pid=$$";
207 if (@ConnectedTo) {
208 puts_clr("$s, connected to ".join(',',@ConnectedTo));
209 } else {
210 puts_clr("$s, not connected to anything");
211 }
212 gotoxy(1,$CursorRow);
213 }
214 sub display_channel {
215 gotoxy(1,2); puts_30c("Channel is $Channel"); gotoxy(1,$CursorRow);
216 }
217 sub display_patch {
218 gotoxy($MidCol,2);
219 if (defined $Cha2patch{$Channel}) {
220 puts_clr("Patch is $Cha2patch{$Channel}");
221 } else {
222 puts_clr("Patch hasn't been reset yet");
223 }
224 gotoxy(1,$CursorRow);
225 }
226 sub display_transpose {
227 if ($Transpose < -48) { $Transpose = -48;
228 } elsif ($Transpose >48) { $Transpose = 48;
229 }
230 gotoxy(1,3);
231 if ($Transpose > 0) { puts_30c("Transpose is +$Transpose");
232 } else { puts_30c("Transpose is $Transpose");
233 }
234 gotoxy(1,$CursorRow);
235 }
236 sub display_note { my ($note, $transposed) = @_;
237 if ($KeyMap eq 'drumkit') {gotoxy($MidCol,2);} else {gotoxy($MidCol,3);}
238 if (! defined $note) { puts_clr("Note is off");
239 } elsif ($transposed == $note) { puts_clr("Note is $note");
240 } else { puts_clr("Note is $note transposed to $transposed");
241 }
242 gotoxy(1,$CursorRow);
243 }
244 sub display_volume {
245 if ($KeyMap eq 'drumkit') { gotoxy(1,3); } else { gotoxy(1,4); }
246 puts_30c("Volume is $Volume");
247 gotoxy(1,$CursorRow);
248 }
249 sub display_pan {
250 if ($KeyMap eq 'drumkit') {gotoxy($MidCol,3);} else {gotoxy($MidCol,4);}
251 # if ($AutoPan{$Channel}) { puts_clr("$AutoPan{$Channel} AutoPan");
252 if ($Cha2Xcontroller{$Channel} == 10) { # 4.9
253 puts_clr("Pan is controlled by X-mouse");
254 } elsif ($Cha2Ycontroller{$Channel} == 10) { # 4.9
255 puts_clr("Pan is controlled by Y-mouse");
256 } elsif (defined $Cha2pan{$Channel}){
257 puts_clr("Pan is $Cha2pan{$Channel}");
258 } else { puts_clr("Pan hasn't been reset yet");
259 }
260 gotoxy(1,$CursorRow);
261 }
262 sub display_midi_controllers {
263 gotoxy(1,5);
264 my @items= ();
265 foreach $controller (sort keys %{$Cha2cc[$Channel]}) {
266 my $v = $Cha2cc[$Channel]{$controller};
267 if ($controller == 1000) { push @items, "pitchwheel=$v"; # 5.8
268 } else { push @items, "cc$controller=$v";
269 }
270 }
271 #my $x = $Cha2Xcontroller{$Channel}; if ($x) { push @items, "X=$x"; }
272 #my $y = $Cha2Ycontroller{$Channel}; if ($y) { push @items, "Y=$y"; }
273 puts_clr(join(q{ }, @items));
274 gotoxy(1,$CursorRow);
275 }
276 sub display_keystrokes {
277 my @s = (@{$Keystrokes{$KeyMap}},"\n",@Synopsis);
278 $PedalLineNum = $CursorRow-1; # ??
279 foreach (@{$Keystrokes{$KeyMap}},@Synopsis) {
280 if (/F1,F2/) { break; }
281 $PedalLineNum += 1;
282 }
283 gotoxy(1,$CursorRow+1); puts(@s);
284 gotoxy(1,$PedalLineNum);
285 puts_clr(" F1,F2=Una F5,F6=Sos F9,F10=Ped");
286 gotoxy(1,$CursorRow);
287 }
288 sub clean_screen {
289 my @s = (@{$Keystrokes{$KeyMap}},"\n",@Synopsis);
290 if ($KeyMap eq 'drumkit') {
291 for my $y (2 .. ($CursorRow+1+@s)) {
292 gotoxy(1,$y); print STDERR "\e[K";
293 }
294 gotoxy(1,2);
295 } else {
296 for my $y ($CursorRow+1 .. ($CursorRow+1+@s)) {
297 gotoxy(1,$y); print STDERR "\e[K";
298 }
299 gotoxy(1,$CursorRow);
300 }
301 }
302 sub set_mouse_mode {
303 print STDERR "\e[?1003h"; # sets SET_ANY_EVENT_MOUSE mode
304 eval 'sub END { print STDERR "\e[?1003l"; }'; # reset on exit
305 if ($@) { warn "can't eval: $@\n"; }
306 }
307
308 sub set_pan { my ($c,$p) = @_;
309 if ($p >112) { $p = 112; } else { $p -= 16; }
310 if ($p < 1) { $p = 1; }
311 # my $b = chr(0xB0 + $c); $p = chr($p); print $OFH "$b\x0A$p";
312 MIDI::ALSA::output(MIDI::ALSA::controllerevent($c,10,$p));
313 }
314 sub set_patch { my ($c,$p) = @_;
315 if (! defined $p) { return; }
316 # my $b1 = chr(0xC0 + $c); my $b2 = chr(0+$p); print $OFH "$b1$b2";
317 MIDI::ALSA::output(MIDI::ALSA::pgmchangeevent($c,$p));
318 }
319 sub new_patch {
320 if ($KeyMap eq 'drumkit') { return; }
321 my $p;
322 if (defined $_[$[]) { $p = $_[$[]; } else { $p = get_int('Patch'); }
323 if (! defined $p) { display_patch(); return; }
324 # my $b1 = chr(0xC0 + $Channel); my $b2 = chr($p); print $OFH "$b1$b2";
325 MIDI::ALSA::output(MIDI::ALSA::pgmchangeevent($Channel,$p));
326 $Cha2patch{$Channel} = $p;
327 display_patch();
328 }
329 sub new_channel {
330 if ($KeyMap eq 'drumkit') { return; }
331 my $c = get_int('Channel');
332 if (! defined $c) { display_channel(); return; }
333 $Channel = $c;
334 note_off();
335 display_channel(); display_note();
336 display_patch(); display_pan(); display_midi_controllers();
337 }
338 sub new_midi_controller {
339 my $c = get_int('MIDI-Controller');
340 if (! defined $c) { display_midi_controllers(); return; }
341 my $v = get_int("MIDI-Controller $c = ");
342 if (! defined $v) { display_midi_controllers(); return; }
343 $Cha2cc[$Channel]{$c} = $v;
344 if ($Cha2Xcontroller{$Channel}==$c) { delete $Cha2Xcontroller{$Channel}; }
345 if ($Cha2Ycontroller{$Channel}==$c) { delete $Cha2Ycontroller{$Channel}; }
346 if ($c == 10) { $Cha2pan{$Channel} = $v; display_pan(); }
347 # my $b=chr(0xB0+$Channel); $c=chr($c); $v=chr($v); print $OFH "$b$c$v";
348 MIDI::ALSA::output(MIDI::ALSA::controllerevent($Channel,$c,$v));
349 display_midi_controllers();
350 }
351 sub new_alsa {
352 my %id2client = MIDI::ALSA::listclients();
353 my %client2id = reverse %id2client;
354
355 foreach my $cl1 (keys %client2id) {
356 my $cl = $cl1;
357 if ($cl =~ /^System/i or $cl =~ /^midikbd/) {
358 delete $id2client{$client2id{$cl}};
359 delete $client2id{$cl};
360 }
361 }
362 # OK. clear the doc, use choose listclients, up 1,
363 # dipslay_alsa(), display_keystrokes(),
364 my @keystroke_rows = @{$Keystrokes{$KeyMap}};
365 gotoxy(1,$CursorRow+@keystroke_rows+2);
366 print STDERR "\e[J";
367 my @new_to = Term::Clui::choose(
368 'Connect to which ALSA clients ?', sort keys %client2id
369 );
370 if (@new_to) {
371 print STDERR "\e[A\e[K"; # up, clrtoeos
372 my %new_ids = ();
373 foreach my $cl (@new_to) {
374 $new_ids{0+$client2id{$cl}} = 1;
375 }
376 my @old_clients = MIDI::ALSA::listconnectedto();
377 foreach my $old_client_ref (@old_clients) {
378 my @old_client = @$old_client_ref;
379 if ($new_ids{0+$old_client[1]}) {
380 delete $new_ids{0+$old_client[1]};
381 } else {
382 MIDI::ALSA::disconnectto(@old_client); # or warn "FAIL\r\n";
383 }
384 }
385 foreach my $new_id (keys %new_ids) {
386 MIDI::ALSA::connectto(0,$new_id,0);
387 }
388 }
389 display_alsa(); display_keystrokes();
390 }
391 sub new_Xcontroller {
392 my $cc = get_int('MIDI-Controller for X-mouse');
393 if (! defined $cc) { display_midi_controllers(); return; }
394 if ($cc == 0) { $cc = 1000; } # 5.8 but '-0' ?
395 if (!%Cha2Xcontroller and !%Cha2Ycontroller) { set_mouse_mode(); }
396 delete $Cha2cc[$Channel]{$Cha2Xcontroller{$Channel}}; # 5.2
397 $Cha2Xcontroller{$Channel} = 0+$cc;
398 $Cha2cc[$Channel]{$cc} = 'X';
399 if ($cc == 10) { display_pan(); }
400 #foreach (sort keys %Cha2Xcontroller) {
401 # warn "Cha2Xcontroller{$_} = $Cha2Xcontroller{$_}\n";
402 #}
403 display_midi_controllers(); return;
404 }
405 sub new_Ycontroller {
406 my $cc = get_int('MIDI-Controller for Y-mouse');
407 if (! defined $cc) { display_midi_controllers(); return; }
408 if ($cc == 0) { $cc = 1000; } # 5.8 but '-0' ?
409 if (!%Cha2Xcontroller and !%Cha2Ycontroller) { set_mouse_mode(); }
410 delete $Cha2cc[$Channel]{$Cha2Ycontroller{$Channel}}; # 5.2
411 $Cha2Ycontroller{$Channel} = 0+$cc;
412 $Cha2cc[$Channel]{$cc} = 'Y';
413 if ($cc == 10) { display_pan(); }
414 #foreach (sort keys %Cha2Ycontroller) {
415 # warn "Cha2Ycontroller{$_} = $Cha2Ycontroller{$_}\n";
416 #}
417 display_midi_controllers(); return;
418 }
419
420 sub escape_seq {
421 my $c = ReadKey(0, STDIN);
422 if ($c eq 'O') { # a FunctionKey F1..F4, 5.6 now UnaCorda/TreCorde
423 $c = ReadKey(0, STDIN); # P,Q,R,S
424 if ($c eq 'P' or $c eq 'Q') { # take or renew pedal 3.5
425 if ($UnaPedIsOn) {
426 MIDI::ALSA::output(MIDI::ALSA::controllerevent($Channel,67,0));
427 } else {
428 $UnaPedIsOn = 1;
429 if (!$Quiet) { gotoxy(12,$PedalLineNum); puts('F3,F4=Tre'); }
430 }
431 MIDI::ALSA::output(MIDI::ALSA::controllerevent($Channel,67,127));
432 } else { # pedal off
433 if ($UnaPedIsOn) {
434 MIDI::ALSA::output(MIDI::ALSA::controllerevent($Channel,67,0));
435 $UnaPedIsOn = 0;
436 if (!$Quiet) { gotoxy(12,$PedalLineNum); puts(' '); }
437 }
438 }
439 gotoxy(1,$CursorRow); return;
440 }
441 if ($c ne '[') { return; }
442 $c = ReadKey(0, STDIN);
443 if ($c eq '5') { # PageUp,
444 if ($KeyMap ne 'drumkit') {
445 $Transpose += 12; display_transpose(); return;
446 }
447 } elsif ($c eq '6') { # PageDown
448 if ($KeyMap ne 'drumkit') {
449 $Transpose -= 12; display_transpose(); return;
450 }
451 } elsif ($c eq 'A') { # 3.2 ArrowUp, ArrowDown are now volume
452 if ($Volume < 10) { $Volume = 10; } else { $Volume += 10; }
453 if ($Volume > 127) { $Volume = 127; }
454 display_volume();
455 } elsif ($c eq 'B') {
456 if ($Volume >120) { $Volume = 120; } else { $Volume -= 10; }
457 if ($Volume < 1) { $Volume = 1; }
458 display_volume();
459 } elsif ($c eq 'C') { # 3.2 ArrowRight is now Pan
460 my $Pan = $Cha2pan{$Channel} || 64;
461 if ($Pan < 16) { $Pan = 16; } else { $Pan += 16; }
462 if ($Pan > 127) { $Pan = 127; }
463 $Cha2pan{$Channel} = $Pan;
464 MIDI::ALSA::output(MIDI::ALSA::controllerevent($Channel,10,$Pan));
465 display_pan();
466 } elsif ($c eq 'D') { # 3.2 ArrowLeft is now Pan
467 my $Pan = $Cha2pan{$Channel} || 64;
468 if ($Pan >112) { $Pan = 112; } else { $Pan -= 16; }
469 if ($Pan < 1) { $Pan = 1; }
470 $Cha2pan{$Channel} = $Pan;
471 MIDI::ALSA::output(MIDI::ALSA::controllerevent($Channel,10,$Pan));
472 display_pan();
473 } elsif ($c eq 'F') { all_sounds_off();
474 } elsif ($c eq 'H') { reset_all_controllers();
475 } elsif ($c eq '1') { # 5.6
476 $c = ReadKey(0, STDIN); # 5,7,8,9
477 if ($c eq '5' or $c eq '7') { # Sos
478 if ($SosPedIsOn) {
479 MIDI::ALSA::output(MIDI::ALSA::controllerevent($Channel,66,0));
480 } else {
481 $SosPedIsOn = 1;
482 if (!$Quiet) { gotoxy(34,$PedalLineNum); puts('F7,F8=*Sos'); }
483 }
484 MIDI::ALSA::output(MIDI::ALSA::controllerevent($Channel,66,127));
485 } elsif ($c eq '8' or $c eq '9') { # *Sos
486 MIDI::ALSA::output(MIDI::ALSA::controllerevent($Channel,66,0));
487 $SosPedIsOn = 0;
488 if (!$Quiet) { gotoxy(34,$PedalLineNum); puts(' '); }
489 }
490 $c = ReadKey(0, STDIN); # throw away trailing tilde
491 gotoxy(1,$CursorRow); return;
492 } elsif ($c eq '2') { # 5.6
493 $c = ReadKey(0, STDIN); # 0,1,3,4
494 if ($c eq '0' or $c eq '1') { # Ped
495 if ($PedalIsOn) {
496 MIDI::ALSA::output(MIDI::ALSA::controllerevent($Channel,64,0));
497 } else {
498 $PedalIsOn = 1;
499 if (!$Quiet) {gotoxy(58,$PedalLineNum); puts('F11,F12=*Ped');}
500 }
501 MIDI::ALSA::output(MIDI::ALSA::controllerevent($Channel,64,127));
502 } elsif ($c eq '3' or $c eq '4') { # *Ped
503 MIDI::ALSA::output(MIDI::ALSA::controllerevent($Channel,64,0));
504 $PedalIsOn = 0;
505 if (!$Quiet) { gotoxy(58,$PedalLineNum); puts(' '); }
506 }
507 $c = ReadKey(0, STDIN); # throw away trailing tilde
508 gotoxy(1,$CursorRow); return;
509 } elsif ($c eq 'M') { # 3.6
510 # ^[[M#XY where X is (chr(32+x)), Y is (chr(32+y)), top-left is !!=1,1
511 # and LeftButtonPress = ^[[M XY Mid = ^[[M!XY Right = ^[[M"XY
512 my $c = ReadKey(0, STDIN);
513 my $x = ReadKey(0, STDIN);
514 my $y = ReadKey(0, STDIN);
515 next unless $c eq '#' or $c eq 'C'; # 5.7 20150531 but c is now 'C'!?
516 $x = round ((ord($x)-32) * 127.8 / $Xmax);
517 if ($x >127) { $x = 127; }
518 $y = 126 - round ((ord($y)-33) * 127.8 / $Ymax);
519 if ($y >127) { $y = 127; } #warn "x=$x y=$y\n";
520 if ($x != $CurrentX) { x_controllers($x); $CurrentX = $x; }
521 if ($y != $CurrentY) { y_controllers($y); $CurrentY = $y; }
522 } else { gotoxy(1,$CursorRow); return;
523 }
524 }
525 sub get_int { my $s = $_[$[];
526 my $max_int = 127;
527 my $row = 1;
528 my $col = 1;
529 if ($s =~ /channel/i) { $max_int = 15; $row = 2;
530 } elsif ($s =~ /controller/i) { $row = 5;
531 } elsif ($s =~ /patch/i) { $col = $MidCol; $row = 2;
532 }
533 ReadMode(0, STDIN);
534 my $int;
535 while (1) {
536 gotoxy($col,$row);
537 if ($s =~ /channel/i) {
538 puts_30c("new $s (0..$max_int) ? ");
539 } else {
540 puts_clr("new $s (0..$max_int) ? ");
541 }
542 $int = <STDIN>; print STDERR "\e[A";
543 if ($int =~ /^[0-9]+$/ and $int <= $max_int) {
544 ReadMode(4, STDIN); gotoxy(1,$row); return 0+$int;
545 }
546 if ($int =~ /^\s*$/) {
547 ReadMode(4, STDIN); gotoxy(1,$row); return undef;
548 }
549 }
550 }
551 sub note_off { # 1.9
552 if (defined $LastTra) {
553 MIDI::ALSA::output(MIDI::ALSA::noteoffevent($Channel,$LastTra,$Volume));
554 undef $LastTra; # XXX
555 }
556 }
557 sub all_sounds_off {
558 foreach my $c (0..15) {
559 MIDI::ALSA::output(MIDI::ALSA::controllerevent($c,120,0));
560 }
561 }
562 sub reset_all_controllers {
563 foreach my $c (0..15) {
564 MIDI::ALSA::output(MIDI::ALSA::controllerevent($c,121,0));
565 }
566 @Cha2cc = (); # a blunt instrument
567 # must rescue the mouse-movement, which will still get generated..
568 foreach (keys %Cha2Xcontroller) {
569 $Cha2cc[$_]{$Cha2Xcontroller{$_}} = 'X';
570 }
571 foreach (keys %Cha2Ycontroller) {
572 $Cha2cc[$_]{$Cha2Ycontroller{$_}} = 'Y';
573 }
574 display_midi_controllers();
575 }
576
577 sub char2note { my $keymap = $_[$[];
578 if ($keymap eq 'piano' or !defined $keymap) { return (
579 a=>47,z=>48,s=>49,x=>50,d=>51,c=>52,v=>53,g=>54,b=>55,
580 h=>56,n=>57,j=>58,m=>59,','=>60,l=>61,'.'=>62,';'=>63,"/"=>64,
581 "'"=>65,'`'=>64,
582 "\t"=>65,'1'=>66,q=>67,'2'=>68,w=>69,'3'=>70,e=>71,
583 r=>72,'5'=>73,t=>74,'6'=>75,y=>76,u=>77,'8'=>78,i=>79,
584 '9'=>80,o=>81,'0'=>82,p=>83,'['=>84,'='=>85,']'=>86,
585 "\cH"=>87,"\x7F"=>87,'\\'=>88,);
586 } elsif ($keymap eq 'wholetone') { return (
587 '`'=>55,'1'=>57,'2'=>,59,'3'=>,61,'4'=>,63,'5'=>65,'6'=>67,'7'=>69,
588 '8'=>71,'9'=>73,'0'=>75,"-"=>77,'='=>79,"\cH"=>81,"\x7F"=>81,
589 "\t"=>56,q=>58,w=>60,e=>62,r=>64,t=>66,y=>68,u=>70,
590 i=>72,o=>74,p=>76,"["=>78,']'=>80,'\\'=>82,
591 a=>35,s=>37,d=>39,f=>41,g=>43,h=>45,j=>47,k=>49,l=>51,';'=>53,"'"=>55,
592 z=>36,x=>38,c=>40,v=>42,b=>44,n=>46,m=>48,','=>50,'.'=>52,'/'=>54,);
593 } elsif ($keymap eq 'augmented') { return (
594 '`'=>34,'1'=>36,'2'=>,40,'3'=>,44,'4'=>,48,'5'=>52,'6'=>56,'7'=>60,
595 '8'=>64,'9'=>68,'0'=>72,"-"=>76,'='=>79,"\cH"=>81,"\x7F"=>81,
596 "\t"=>35,q=>37,w=>41,e=>45,r=>49,t=>53,y=>57,u=>61,
597 i=>65,o=>69,p=>73,"["=>77,']'=>80,'\\'=>82,
598 a=>38,s=>42,d=>46,f=>50,g=>54,h=>58,j=>62,k=>66,l=>70,';'=>74,"'"=>78,
599 z=>39,x=>43,c=>47,v=>51,b=>55,n=>59,m=>63,','=>67,'.'=>71,'/'=>75,);
600 } elsif ($keymap eq 'harmonic') { return (
601 '1'=>63,'2'=>67,'3'=>,70,'4'=>,74,'5'=>77,'6'=>81,'7'=>84,
602 '8'=>88,'9'=>91,'0'=>95,'-'=>98,"="=>102,"\cH"=>105,"\x7F"=>105,
603 q=>58,w=>62,e=>65,r=>69,t=>72,y=>76,u=>79,i=>83,o=>86,p=>90,"["=>93,']'=>97,
604 a=>53,s=>57,d=>60,f=>64,g=>67,h=>71,j=>74,k=>78,l=>81,';'=>85,"'"=>88,
605 z=>48,x=>52,c=>55,v=>59,b=>62,n=>66,m=>69,','=>73,'.'=>76,'/'=>80,);
606 } elsif ($keymap eq 'drumkit') { $Channel = 9; $CursorRow = 4; return (
607 # 35 bassdrum, 40 snare, 44 hihat, 49 57 splash, 51 59 ride, 43 45 47 48 toms
608 '1'=>39,'2'=>56,'3'=>,67,'4'=>,68,'5'=>74,'6'=>75,'7'=>77,
609 '8'=>60,'9'=>61,'0'=>62,'-'=>63,"="=>64,"\cH"=>81,"\x7F"=>81,
610 q=>42,w=>42,e=>44,r=>44,t=>46,y=>46,u=>51,i=>59,o=>49,p=>57,'['=>55,']'=>53,
611 a=>37,s=>37,d=>40,f=>40,g=>38,h=>38,j=>41,k=>43,l=>45,';'=>47,';'=>48,"'"=>50,
612 z=>33,x=>34,c=>35,v=>35,b=>35,n=>35,m=>36,','=>36,'.'=>36,'//'=>36,
613 );
614 } else {
615 die "unrecognised KeyMap: $keymap\n"
616 . " must be: piano, wholetone, harmonic, augmented or drumkit.\n";
617 }
618 }
619
620 # ---------------------- infrastructure for 3.6 ---------------------
621 sub process_channel_spec { my $arg = $_[$[];
622 # warn "process_channel_spec arg=$arg\n";
623 if ($arg !~ /^[-xy:,\d]+$/) { unshift @ARGV, $arg; last; }
624 my ($cha,@a) = split(':', $arg);
625 if (!length $cha) { next; }
626 $Channel = 0+$cha;
627 if ($Channel<0 or $Channel>15) {
628 die "channel must be between 0 and 15, but was $Channel\n";
629 }
630 my $i = 1; foreach my $a (@a) {
631 if ($a =~ /^x(-?\d+)/) { # 3.6
632 my $con = $1; # controller-number
633 if($con<-127 or $con>127){
634 die "-x channel $Channel controller must be "
635 . "between 0 and 127, but was $con\n";
636 }
637 if ($con eq '-0') {
638 $Cha2Xcontroller{$Channel} = -1000;
639 $Cha2cc[$Channel]{-1000} = 'X'; # 5.8 XXX
640 } elsif ($con eq '0') {
641 $Cha2Xcontroller{$Channel} = 1000;
642 $Cha2cc[$Channel]{1000} = 'X'; # 5.8
643 } else {
644 $Cha2Xcontroller{$Channel} = 0+$con;
645 $Cha2cc[$Channel]{$con} = 'X'; # 4.9
646 }
647 } elsif ($a =~ /^y(-?\d+)/) { # 3.6
648 my $con = $1; # controller-number
649 if($con<-127 or $con>127){
650 die "-y channel $Channel controller must be "
651 . "between 0 and 127, but was $con\n";
652 }
653 if ($con eq '-0') {
654 $Cha2Ycontroller{$Channel} = -1000;
655 $Cha2cc[$Channel]{-1000} = 'Y'; # 5.8
656 } elsif ($con eq '0'){
657 $Cha2Ycontroller{$Channel} = 1000;
658 $Cha2cc[$Channel]{1000} = 'Y'; # 5.8
659 } else {
660 $Cha2Ycontroller{$Channel} = 0+$con;
661 $Cha2cc[$Channel]{$con} = 'Y'; # 4.9
662 }
663 } elsif ($i == 1 and length $a) { $Cha2patch{$Channel} = 0+$a;
664 } elsif ($i == 2 and length $a) { $Cha2pan{$Channel} = 0+$a;
665 }
666 $i += 1;
667 }
668 }
669 sub round { my $x = $_[$[];
670 if ($x > 0.0) { return int ($x + 0.5); }
671 if ($x < 0.0) { return int ($x - 0.5); }
672 return 0;
673 }
674 sub x_controllers { my $x = $_[$[];
675 if ($x > 127) { $x = 127; } elsif ($x < 0) { $x = 0; }
676 while (my ($cha, $con) = each %Cha2Xcontroller) {
677 if ($con < 0) { $con = 0-$con; $x = 127-$x; }
678 if ($con == 1000) { # special-cased for Pitch-Bend
679 $x = 128*$x + $x - 8192 ; # two bytes full, -8192..+8191
680 # my $b = chr(0xE0 + $cha); print $OFH "$b$xc$xc";
681 MIDI::ALSA::output(MIDI::ALSA::pitchbendevent($cha,$x));
682 } else {
683 # my $b = chr(0xB0+$cha); my $c = chr($con); print $OFH "$b$c$xc";
684 MIDI::ALSA::output(MIDI::ALSA::controllerevent($cha,$con,$x));
685 }
686 }
687 }
688 sub y_controllers { my $y = $_[$[];
689 if ($y > 127) { $y = 127; } elsif ($y < 0) { $y = 0; }
690 while (my ($cha, $con) = each %Cha2Ycontroller) {
691 if ($con < 0) { $con = 0-$con; $y = 127-$y; }
692 if ($con == 1000) { # special-cased for Pitch-Bend
693 $y = 128*$y + $y - 8192; # two bytes full, -8192..+8191
694 # my $b = chr(0xE0 + $cha); print $OFH "$b$yc$yc";
695 MIDI::ALSA::output(MIDI::ALSA::pitchbendevent($cha,$y));
696 } else {
697 # my $b = chr(0xB0+$cha); my $c = chr($con); print $OFH "$b$c$yc";
698 MIDI::ALSA::output(MIDI::ALSA::controllerevent($cha,$con,$y));
699 }
700 }
701 }
702
703 # --------------- vt100 stuff, evolved from Term::Clui ---------------
704 sub puts { my $s = join q{}, @_;
705 $Irow += ($s =~ tr/\n/\n/);
706 if ($s =~ /\r\n?$/) { $Icol = 0;
707 } else { $Icol += length($s); # BUG, wrong on multiline strings!
708 }
709 print STDERR $s;
710 }
711 sub puts_30c { my $s = $_[$[]; # assumes no newlines
712 my $rest = 30-length($s);
713 print STDERR $s, " "x$rest, "\e[D"x$rest;
714 $Icol += length($s);
715 }
716 sub puts_clr { my $s = $_[$[]; # assumes no newlines
717 print STDERR "$s\e[K";
718 $Icol += length($s);
719 }
720 sub clrtoeol {
721 print STDERR "\e[K";
722 }
723 sub up {
724 # if ($_[$[] < 0) { down(0 - $_[$[]); return; }
725 print STDERR "\e[A" x $_[$[]; $Irow -= $_[$[];
726 }
727 sub down {
728 # if ($_[$[] < 0) { up(0 - $_[$[]); return; }
729 print STDERR "\n" x $_[$[]; $Irow += $_[$[];
730 }
731 sub right {
732 # if ($_[$[] < 0) { left(0 - $_[$[]); return; }
733 print STDERR "\e[C" x $_[$[]; $Icol += $_[$[];
734 }
735 sub left {
736 # if ($_[$[] < 0) { right(0 - $_[$[]); return; }
737 print STDERR "\e[D" x $_[$[]; $Icol -= $_[$[];
738 }
739 sub gotoxy { my $newcol = shift; my $newrow = shift;
740 if ($newrow > $Irow) { down($newrow-$Irow);
741 } elsif ($newrow < $Irow) { up($Irow-$newrow);
742 }
743 if ($newcol == 0) { print STDERR "\r" ; $Icol = 0;
744 } elsif ($newcol > $Icol) { right($newcol-$Icol);
745 } elsif ($newcol < $Icol) { left($Icol-$newcol);
746 }
747 }
748
749
750 __END__
751 formerly:
752 F1,F2 = take new pedal F3,F4 = remove pedal
753
754 =pod
755
756 =head1 NAME
757
758 midikbd - a simple monophonic ascii-midi-keyboard
759
760 =head1 SYNOPSIS
761
762 midikbd [-o output] [-ka|-kd|-kh|-kp|-kw] [-q] <ChannelSpec>...
763 midikbd -o 128:0 # plays to ALSA-port 128:0
764 midikbd 3 # plays to MIDI-Channel 3 (out of 0..15)
765 midikbd 3:0:80 0:73:20 # sets Channel:Patch:Pan, and plays to 0
766 midikbd 3:92:x10:y1 # mouse X-motion controls pan, Y modulation
767 midikbd -ka # selects the "augmented" keymapping
768 midikbd -q # Quiet mode: doesn't display keystroke help
769 xterm -geometry 72x18-1-1 -exec 'midikbd -kd' &
770 xterm -geometry 72x24-1-1 -exec 'midikbd -ka' &
771
772 perldoc midikbd
773
774 the "piano" keymap (bottom 2 rows round middleC, top 2 treble clef):
775 1 2 3 5 6 8 9 0 = Back
776 F F# G G# A Bb B C C# D Eb E F F# G G# A Bb B c c# d eb e
777 Tab q w e r t y u i o p [ ] \
778 s d g h j l ;
779 C C# D Eb E F F# G G# A Bb B C C# D Eb E
780 z x c v b n m , . /
781
782 Q = Quit C = new Channel P = new Patch A = ALSA
783 U/D = Up/Down a semitone PageUp/Down = Up/Down an octave
784 UpArrow = Volume +10 DownArrow = Volume -10
785 RightArrow = Pan +16 LeftArrow = Pan -16
786 F1,F2=Una F3,F4=Tre F5,F6=Sos F7,F8=*Sos F9,F10=Ped F11,F12=*Ped
787 M = set a MIDI-Controller X/Y = govern a Controller by mouse X/Y
788 Home = reset all controllers End = all sounds off
789
790 =head1 DESCRIPTION
791
792 This script allows the use of the computer keyboard
793 as a simple monophonic MIDI keyboard.
794
795 Arguments are interpreted as ChannelSpecs, so the -C option has been removed.
796 In version 4.0 the command-line syntax has been made neater,
797 and more consistent with I<midiecho>,
798 and version 4.5 uses the MIDI::ALSA module to start its own ALSA client,
799 and therefore no longer needs to hijack a Virtual MIDI client.
800
801 I<Midikbd> is monophonic because of the impracticality
802 of detecting KeyUp and KeyDown events in an xterm.
803 If the <Space> bar is pressed
804 (or any other ascii-key which does not map to a note),
805 then the current note is stopped;
806 otherwise, each note lasts until the next note is played.
807
808 This also means that if you hold a key down (as you would on,
809 say, an organ keyboard) the key-repeat mechanism will start up;
810 this may sound, er, unexpected.
811
812 If the B<-o> option is not given then I<midikbd> writes to the
813 port specified by the I<ALSA_OUTPUT_PORTS> environment variable.
814
815 =head1 OPTIONS
816
817 =over 3
818
819 =item I<-o 128:0> or I<-o TiMidity>
820
821 This example plays into the ALSA B<p>ort I<128:0>,
822 or into the I<TiMidity> client..
823 It does this by using the I<MIDI::ALSA> Perl CPAN module.
824 When I<midikbd> exits the connection is automatically deleted.
825
826 This option allows I<midikbd> to use the same port-specification
827 as the other alsa-utils, e.g. I<aplaymidi> and I<aconnect>.
828 An ALSA-port is specified by its number; for port 0 of a client,
829 the ":0" part of the port specification can be omitted.
830 The output port is taken from the I<ALSA_OUTPUT_PORTS>
831 environment variable if none is given on the command line.
832
833 Since Version 5.0,
834 you may supply a comma-separated list of ports, e.g. I<-o 20,128:1>
835
836 Since Version 5.4,
837 the particular port value zero e.g. I<-o 0> is taken
838 as an instruction to not connect to anything at all.
839 This is useful if you want the output to go into another program like
840 I<midiecho> or I<midichord>;
841 you no longer have to go through a MIDI-Through client.
842 In separate I<xterm>s:
843 midikbd -o 0
844
845 and then
846 midiecho -i midikbd -c 0 -d 250,450 -s 45 -e 1,2
847
848 =item I<-ka> or I<-kd> or I<-kh> or I<-kp> or I<-kw>
849
850 =item I<-k augmented> or I<-k drumkit> etc.
851
852 Selects the B<k>eymap: possible keymaps are I<augmented> (the default),
853 I<drumkit>, I<harmonic>, I<piano> and I<wholetone>.
854 All keymappings are aimed at the US-keyboard; this could be seen as a bug.
855 The I<augmented> keymap is particularly good for improvisation.
856 The I<drumkit> keymap preselects Channel 9; in this mode,
857 it is pointless to change the Patch or the Transposition.
858 The I<harmonic> keymap is sort of inspired by accordion buttons,
859 and makes it very easy to play major and minor triads;
860 this is unfortunately not very useful as I<midikbd> is only monophonic,
861 which could also be seen as a bug.
862
863 the "piano" keymap (bottom 2 rows round middleC, top 2 treble clef):
864 1 2 3 5 6 8 9 0 = Back
865 F F# G G# A Bb B C C# D Eb E F F# G G# A Bb B c c# d eb e
866 Tab q w e r t y u i o p [ ] \
867 s d g h j l ;
868 C C# D Eb E F F# G G# A Bb B C C# D Eb E
869 z x c v b n m , . /
870
871 the "wholetone" keymap (bottom 2 rows bass, top 2 treble):
872 ` 1 2 3 4 5 6 7 8 9 0 - = Back
873 G G# A Bb B C C# D Eb E F F# G G# A Bb B c c# d eb e f f# g g# a bb
874 Tab q w e r t y u i o p [ ] \
875 a s d f g h j k l ; '
876 B_ C C# D Eb E F F# G G# A Bb B C C# D Eb E F F# G
877 z x c v b n m , . /
878
879 the "augmented" keymap (all 4 rows, starting from top left):
880 ` 1 2 3 4 5 6 7 8 9 0 - = Back
881 Bb C E G# C E G# c e g# c e g a
882 Tab q w e r t y u i o p [ ] \
883 B C# F A C# F A c# f a c# f g# bb
884 a s d f g h j k l ; '
885 D F# Bb D F# Bb d f# bb d f#
886 z x c v b n m , . /
887 Eb G B Eb G B eb g b eb
888
889 the "harmonic" keymap (rightwards, alternate maj and min 3rds):
890 1 2 3 4 5 6 7 8 9 0 - = Back
891 Eb Bb G D Bb F D A F C A E C G E B G D B F# D A F# C# A
892 q w e r t y u i o p [ ]
893 a s d f g h j k l ; '
894 F C A E C G E B G D B F# D A F# C# A E C# G# E
895 z x c v b n m , . /
896
897 the "drumkit" keymap (for General-MIDI channel 9):
898 Perc 1 2 3 4 5 6 7 8 9 0 - = Congas
899 HiHat q w e r t y u i o p [ ] Cymbals
900 Snare a s d f g h j k l ; ' TomToms
901 Metronome z x c v b n m , . BassDrums
902
903 =item I<-q>
904
905 B<q>uiet mode: doesn't display keystroke help
906
907 =item I<-h>
908
909 Prints B<h>elpful usage information.
910
911 =item I<-v>
912
913 Prints B<v>ersion number.
914
915 =back
916
917 =head1 CHANNELSPEC
918
919 After the options, the remaining command-line arguments are ChannelSpecs,
920 which specify how the MIDI-Channels are to be set up. For example:
921
922 B< 5>
923
924 This first example preselects B<C>hannel number 5 (out of 0..15).
925
926 B< 5:91:120 4:14:120 3:91:8 2:14:8 1:91:64 0:14:64>
927
928 The second example sets up I<Channel:Patch:Pan> on a number of channels,
929 and leaves I<midikbd> playing on the last channel mentioned.
930 A list of General-MIDI Patch-numbers is at
931 http://www.pjb.com.au/muscript/gm.html#patch
932 in separate xterm's:
933
934 midikbd -o 0 5:91:120 4:14:120 3:91:8 2:14:8 1:29:64 0:14:64 &
935
936 and
937
938 midiecho -i midikbd -d 1,2200,2201,4400,4401 -q 5 -e 1,2,3,4,5
939
940 B< 3:91:y0 2:92:y-0 1:93:x-10 0:94:x10>
941
942 The third example uses mouse movement X,Y
943 within its window to drive MIDI-controllers, with an B<x> or a B<y>
944 followed by a Controller-number.
945 A list of MIDI-Controller numbers is at
946 http://www.pjb.com.au/muscript/gm.html#cc
947 and if the number is preceded by a minus sign then I<midikbd> reverses the
948 direction of drive, so that right- or up-motions decrease the parameter
949 rather than increase it as they do normally.
950
951 Controller number zero is re-interpreted by I<midikbd> to mean Pitch-Bend,
952 which is not technically a real MIDI-controller, but is very useful.
953 (The real MIDI-controller number zero is a Bank-Select, which is a
954 slow and discontinuous operation not useful under a mouse.)
955
956 B<midikbd -o 14 3:91:y0 2:92:y-0 1:93:x-11 0:94:x11 >
957
958 This fourth example leaves I<midikbd> transmitting
959 to patch 94 on channel 0, after having set patch 91 on channel 3, and 92 on 2,
960 and 93 on channel 1;
961 and the X-motions of the mouse cross-fade from patch 93 to 94,
962 and the Y-motions raise and lower patches 91 and 92 in opposite directions.
963
964 Previously, in a different I<xterm>, you have to be running:
965
966 midiecho -i 14 -d 1,1,1 -s 1,1,1 -e 1,2,3
967
968 to duplicate channel 0 onto channels 1,2, and 3 (very wild :-).
969
970 I<Midikbd> detects mouse-motion events from the I<xterm>,
971 by using the DECSET SET_ANY_EVENT_MOUSE command: \e[?1003h
972 (An earlier version ran I<xev> and parsed its output).
973
974 =head1 SUPERSEDED OPTIONS
975
976 =over 3
977
978 =item I<-p>
979
980 Specifies the output ALSA-port. Just use B<-o> instead.
981
982 =item I<-C>
983
984 Preselect the MIDI-channel.Just specify the I<ChannelSpec>
985 arguments after the options on the command-line.
986
987 =item I<-P 32>
988
989 Preselects B<P>atch number 32 on whatever the current channel is.
990 This option is superseded by the I<ChannelSpec> arguments.
991
992 =back
993
994 =head1 CHANGES
995
996 20150603 5.8 X and Y mouse-control of pitchwheel displayed helpfully
997 20150531 5.7 X and Y mouse-control fixed
998 20150529 5.6 UI change: F1-F4=Una/Tre F5-F8=Sos/*Sos F9-F12=Ped
999 20150528 5.5 the Synopsis responds to Pedal on/off
1000 20130225 5.4 -o 0 doesn't connect to anything
1001 20120407 5.3 the Y-controller works correctly
1002 20120401 5.2 changing the X- or Y-controller is displayed correctly
1003 20111103 5.1 use the new MIDI-ALSA 1.11 to handle portnames
1004 20111028 5.0 OutputPort can be a comma-separated list
1005 20110917 4.9 Pan controlled by mouse is not falsely displayed
1006 20110620 4.8 drumkit offers z,x = metronome
1007 20110509 4.7 quit from drumkit mode cleans up screen properly
1008 20110414 4.6 keystroke A changes ALSA connections
1009 20110321 4.5 now uses MIDI::ALSA, not writing to /dev/snd/midi*
1010 20101213 4.4 display more compact; Controllers now displayed
1011 20101117 4.3 keystrokes X and Y map X and Y mouse at run-time
1012 20101017 4.2 keystroke M sets MIDI-Controller
1013 20101017 4.2 AutoPan is cancelled by Pan, but still unimplemented
1014 20100819 4.1 CursorRow set correctly for drumkit keymap
1015 20100419 4.0 -C deprecated, -p and -d subsumed into -o
1016 20100417 3.6 X and Y mouse movements govern controllers
1017 20100402 3.5 F1,F2 take new pedal; F3,F4 remove pedal
1018 20100326 3.4 -C accepts the Channel:Patch:Pan format
1019 20100325 3.3 handles multiple -C nn -P nn -C nn -P nn settings
1020 20100325 3.2 Left&Right pan; U&D transpose, Up&Down vol
1021 20100318 3.1 -d - outputs to stdout, e.g. to pipe into midiecho -i -
1022 20100215 3.0 -C and -P, and -p now means ALSA-port
1023 20100206 2.9 augmented keymapping
1024 20100202 2.8 uses aconnect to show "connected to" info for virmidi
1025 20100202 2.7 -d option
1026 20100130 2.6 in drumkit mode, no Channel, Patch or Transpose
1027 20100130 2.5 fixed -h option
1028 20100130 2.4 drumkit keymapping
1029 20100129 2.3 piano, wholetone and harmonic keymappings; -k option
1030 20100128 2.2 Quiet mode: doesn't display keystroke help
1031 20100127 2.1 display_note()
1032 20100127 2.0 different key2note mapping, starting from z=C
1033 20100126 1.9 bug fixed with note-off for bass c
1034 20100126 1.8 End = sounds off, Home = reset controllers
1035 20100126 1.7 looks through /dev/snd for midiC* files
1036 20100126 1.6 remembers Patch per Channel
1037 20100125 1.5 proper little Clui-style state display
1038 20100125 1.4 Left and Right arrows change volume
1039 20100125 1.3 the -p option works
1040 20100125 1.2 sub note_off; channel change stops last note
1041 20100125 1.1 PageUp,PageDown,Up,Down change transpose
1042 20100125 P changes patch, C changes channel
1043 20100124 1.0 first working version
1044
1045 =head1 AUTHOR
1046
1047 Peter J Billam http://www.pjb.com.au/comp/contact.html
1048
1049 =head1 REQUIREMENTS
1050
1051 Uses the CPAN modules Term::ReadKey and MIDI::ASLA.
1052
1053 =head1 SEE ALSO
1054
1055 Term::ReadKey
1056 MIDI::ALSA
1057 http://www.pjb.com.au/midi
1058 http://www.pjb.com.au/muscript/gm.html
1059 http://vmpk.sourceforge.net
1060 perl(1).
1061
1062 =cut