midikbd


NAME

midikbd - a simple monophonic ascii-midi-keyboard


SYNOPSIS

   midikbd [-o output] [-ka|-kd|-kh|-kp|-kw] [-q] <ChannelSpec>...
   midikbd -o 128:0     # plays to ALSA-port 128:0 (needs virmidi)
   midikbd -o midiC1D0     # plays to Devicefile /dev/snd/midiC1D0
   midikbd -o - 1:90 0:105 | midiecho -i - -d 1 -q 40 -e 1 # to STDOUT
   midikbd 3              # plays to MIDI-Channel 3 (out of 0..15)
   midikbd 3:0:80 0:73:20     # sets Channel:Patch:Pan, plays to 0
   midikbd 3:92:x10:y1 # mouse X-motion controls pan; Y modulation
   midikbd -ka                # selects the "augmented" keymapping
   midikbd -q         # Quiet mode: doesn't display keystroke help
   perldoc midikbd

 the "piano" keymap (bottom 2 rows round middleC, top 2 treble clef):
    1    2    3        5    6       8    9    0        =   Back
 F  F# G G# A Bb B   C C# D Eb E  F F# G G# A Bb B   c c# d eb e
 Tab   q    w    e   r    t    y  u    i    o    p   [    ]    \
              s    d        g    h    j       l    ; 
            C C# D Eb  E  F F# G G# A Bb B  C C# D Eb E
            z    x     c  v    b    n    m  ,    .    /

 Q = Quit     P = change Patch      C = change Channel
 PageUp     = Up an octave   PageDown  = Down an octave
 U          = Up a semitone  D         = Down a semitone
 UpArrow    = Volume +10     DownArrow = Volume -10
 RightArrow = Pan +16        LeftArrow = Pan -16
 F1,F2   = take new pedal    F3,F4     = remove pedal
 End     = all sounds off    Home = reset all controllers


DESCRIPTION

Midikbd allows the use of the computer keyboard as a simple monophonic MIDI keyboard.

Midikbd is monophonic because of the impracticality of detecting KeyUp and KeyDown events in an xterm. If the Space-bar is pressed (or any other ascii-key which does not map to a note), then the current note is stopped; otherwise, each note lasts until the next note is played.

This also means that if you hold a key down (as you would on, say, an organ keyboard) the key-repeat mechanism will start up; this may sound, er, unexpected.

Different key-to-note mappings are available. The default mapping (piano) gives a range of just over three octaves. The lower two rows get the notes round Middle-C, so that z is the C below Middle-C and / is the E above it. Then the upper two rows get the treble-clef notes, so that Tab is the E above Middle-C and ] is the d above the treble-clef.

If the -o option is not given then midikbd writes to the port specified by the ALSA_OUTPUT_PORTS environment variable. If that is not set, it writes directly to an ALSA raw-MIDI device (midiC?D?) that it finds in /dev/snd/   If it finds more than one such device it uses Term::Clui to let the user choose between them. The only devices that appear there are the hardware-synths and the Virtual-MIDI ports; other ALSA-clients (e.g. timidity) do not appear in /dev/snd/; they can be accessed by using aconnect to connect a Virtual-MIDI port to the chosen ALSA-client, then using midikbd to play into the corresponding /dev/snd/midiC?D? device. This is what the -o option does for you.

If aconnect -oil doesn't reveal any Virtual-MIDI ports, you'll need to do modprobe snd-virmidi (or perhaps modprobe snd-card-virmidi) on startup. If you run out of free Virtual-MIDI ports, then you need to reload the snd-virmidi kernel-module with more virtual sound-cards enabled, e.g.:
  modprobe -r snd-virmidi
  modprobe snd-virmidi enable=1,1

This is midikbd version 4.0


OPTIONS

-o 128:0
-o midiC2D0
-o -

The first example plays into the ALSA port 128:0. It does this by using aconnect to find an unconnected Virtual-MIDI port, which it then to connects to the desired ALSA-port; it then plays into the Virtual-MIDI port's corresponding raw-MIDI device (midiC?D?). When midikbd exits it automatically deletes the connection (because, for example, as long as a timidity port is connected to, then timidity locks up the sound card for its own use).

This option allows midikbd to use the same port-specification as the other alsa-utils, e.g. aplaymidi and aconnect. An ALSA-port is specified by its number; for port 0 of a client, the ":0" part of the port specification can be omitted. The port specification is taken from the ALSA_OUTPUT_PORTS environment variable if none is given on the command line.

The second example plays into the ALSA raw-midi Device-File /dev/snd/midiC2D0   (and for old times sake, if the device is of the form midi1 then it plays into the old OSS raw-midi device /dev/midi1)

If the device is - then midikbd plays to STDOUT, e.g.:
  midikbd -o - | midiecho -i - -d 250,450 -q 45 -e 1,2

-ka   or   -kd   or   -kh   or   -kp   or   -kw
-k augmented or -k drumkit or -k harmonic or -k piano or -k wholetone

Selects the keymap: possible keymaps are augmented, drumkit, harmonic, piano (the default), and wholetone. All keymappings are aimed at the US-keyboard; this could be seen as a bug. The augmented keymap is particularly good for improvisation. The drumkit keymap preselects Channel 9; in this mode, it is better not to change the Patch or the Transposition. The harmonic keymap is sort of inspired by accordion buttons, and makes it very easy to play major and minor triads; this is unfortunately not very useful as midikbd is only monophonic, which could also be seen as a bug. The piano keymap is the default.

 the "piano" keymap (bottom 2 rows round middleC, top 2 treble clef):
    1    2    3        5    6       8    9    0        =   Back
 F  F# G G# A Bb B   C C# D Eb E  F F# G G# A Bb B   c c# d eb e
 Tab   q    w    e   r    t    y  u    i    o    p   [    ]    \
              s    d        g    h    j       l    ; 
            C C# D Eb  E  F F# G G# A Bb B  C C# D Eb E
            z    x     c  v    b    n    m  ,    .    /

 the "wholetone" keymap (bottom 2 rows bass, top 2 treble):
 `    1    2   3    4    5    6    7    8    9    0    -    =   Back
 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
   Tab  q    w    e    r   t    y    u    i    o     p   [    ]    \
          a    s    d    f    g    h    j   k    l    ;    '
          B_ C C# D Eb E F F# G G# A Bb B C C# D Eb E F F# G
             z    x    c   v    b    n    m    ,    .   /

 the "augmented" keymap (all 4 rows, starting from top left):
 `    1    2   3    4    5    6    7    8    9    0    -    =   Back
 Bb   C    E   G#   C    E    G#   c    e    g#   c    e    g    a
   Tab  q    w    e    r   t    y    u    i    o     p   [    ]    \
    B   C#   F    A    C#  F    A    c#   f    a     c#  f    g#   bb
          a    s    d    f    g    h    j   k    l    ;    '
          D    F#   Bb   D    F#   Bb   d   f#   bb   d    f#
             z    x    c   v    b    n    m    ,    .   /
             Eb   G    B   Eb   G    B    eb   g    b   eb

 the "harmonic" keymap (rightwards, alternate maj and min 3rds):
   1     2   3    4   5   6   7    8    9     0    -     =    Back
   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
      q    w    e   r   t   y   u    i     o    p     [     ]
         a    s   d   f   g   h    j    k     l    ;     '
         F  C A E C G E B G D B F# D A  F# C# A E  C# G# E
            z   x   c   v   b   n    m     ,    .     /

 the "drumkit" keymap (for General-MIDI channel 9):
 Perc  1   2   3   4   5   6   7   8   9   0   -   =    Congas
 HiHat   q   w   e   r   t   y   u   i   o   p   [     Cymbals
 Snare     a   s   d   f   g   h   j   k   l   ;   '   TomToms
             z   x   c   v   b   n   m   ,   .   /  Bass-Drums

-q

quiet mode: doesn't display keystroke help

-h

Shows helpful usage information

-v

Displays the version number.


CHANNELSPEC

After the options, the remaining command-line arguments are ChannelSpecs, which specify how the MIDI-Channels are to be set up. For example:

5

This first example preselects Channel number 5 (out of 0..15).

5:91:120 4:14:120 3:91:8 2:14:8 1:91:64 0:14:64

The second example sets up Channel:Patch:Pan on a number of channels, and leaves midikbd playing on the last channel mentioned. A list of General-MIDI Patch-numbers is at /muscript/gm.html#patch. E.g.:
midikbd -o - 5:91:120 4:14:120 3:91:8 2:14:8 1:29:64 0:14:64 \
| midiecho -i - -d 1,2200,2201,4400,4401 -q 5 -e 1,2,3,4,5

3:91:y0 2:92:y-0 1:93:x-10 0:94:x10

The third example uses mouse movement X,Y within its window to drive MIDI-controllers, with an x or a y followed by a Controller-number. A list of MIDI-Controller numbers is at /muscript/gm.html#cc and if the number is preceded by a minus sign then midikbd reverses the direction of drive, so that right- or up-motions decrease the parameter rather than increase it as they do normally.

Controller number zero is re-interpreted by midikbd to mean Pitch-Bend, which is not technically a real MIDI-controller, but is very useful. (The real MIDI-controller number zero is a Bank-Select, which is a slow and discontinuous operation not useful under a mouse.)

midikbd -o - 3:91:y0 2:92:y-0 1:93:x-11 0:94:x11 | midiecho -i - -d 1,1,1 -q 1,1,1 -e 1,2,3

This fourth example leaves midikbd transmitting to patch 94 on channel 0, after having set patch 91 on channel 3, and 92 on 2, and 93 on channel 1; and the X-motions of the mouse cross-fade from patch 93 to 94, and the Y-motions raise and lower patches 91 and 92 in opposite directions (very wild...).

Midikbd detects mouse-motion events from the xterm, by using the DECSET SET_ANY_EVENT_MOUSE command: \e[?1003h   (An earlier version ran xev and parsed its output).


SUPERSEDED OPTIONS

-p 128:0

Specifies the output ALSA-port. Just use use -o instead.

-d midiC2D0

Specifies the output device-file. Just use -o instead.

-C 5

As of version 4.0, the -C option is superseded. Just specify the ChannelSpec arguments after the options on the command-line.

-P 32

Preselects Patch number 32 (out of 0..127) on whatever the current channel is. This option is superseded by the the ChannelSpec arguments.


DOWNLOAD

The current version of midikbd is available by http at www.pjb.com.au/midi/free/midikbd
To install it, save it to disc, move it into your $PATH, make it executable, and if necessary edit the first line to reflect where perl is installed on your system. You will also need to install the Term::Clui and Term::ReadKey CPAN modules


CHANGES


4.0, 20100419, -C deprecated, -p and -d subsumed into -o
3.6, 20100417, X and Y mouse movements govern controllers
3.5, 20100402, F1,F2 take new pedal; F3,F4 remove pedal
3.4, 20100326, the -C option accepts the Channel:Patch:Pan format
3.3, 20100325, handles multiple -C nn -P nn -C nn -P nn settings
3.2, 20100325, Left and Right pan; Up and Down adjust volume; U and D transpose
3.1, 20100318, -d - outputs to stdout, e.g. to pipe into midiecho -i -
3.0, 20100215, -C and -P, and -p now means ALSA-port
2.9, 20100206, augmented keymapping
2.8, 20100202, uses aconnect to show "connected to" info for virmidi
2.7, 20100202, -d option
2.6, 20100130, in drumkit mode, no Channel, Patch or Transpose
2.5, 20100130, fixed -h option
2.4, 20100130, drumkit keymapping
2.3, 20100129, piano, wholetone and harmonic keymappings; -k option
2.2, 20100128, displays keystroke help (and cleans it up on Quit)
2.1, 20100127, display_note()
2.0, 20100127, different key2note mapping, starting from z=C
1.9, 20100126, bug fixed with note-off for bass c
1.8, 20100126, End = all sounds off, Home = reset all controllers
1.7, 20100126, looks through /dev/snd for midiC* files
1.6, 20100126, remembers Patch per Channel
1.5, 20100125, proper little Clui-style state display
1.4, 20100125, Left and Right arrows change volume
1.3, 20100125, the -p option works
1.2, 20100125, sub note_off; channel change stops last note
1.1, 20100125, PageUp,PageDown,Up,Down change transpose; P changes patch, C changes channel
1.0, 20100124, first working version


AUTHOR

Peter J Billam www.pjb.com.au/comp/contact.html


REQUIREMENTS


SEE ALSO

search.cpan.org/perldoc?Term::Clui
search.cpan.org/perldoc?Term::ReadKey
www.pjb.com.au/midi
www.pjb.com.au/midi/midiecho.html
www.pjb.com.au/muscript/gm.html
vmpk.sourceforge.net