-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmidizap.1
2496 lines (2488 loc) · 99.3 KB
/
midizap.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.\" Automatically generated by Pandoc 2.4
.\"
.TH "midizap" "1" "" "" ""
.hy
.SH Name
.PP
midizap \[en] control your multimedia applications with MIDI
.SH Synopsis
.PP
midizap [\-hkn] [\-d[rskmj]] [\-j \f[I]name\f[R]] [\-ost[\f[I]n\f[R]]]
[\-P[\f[I]prio\f[R]]] [[\-r] \f[I]rcfile\f[R]]
.SH Options
.TP
.B \-h
Print a short help message and exit.
.TP
.B \-d[rskmj]
Enable various debugging options: r = regex (print matched translation
sections), s = strokes (print the parsed configuration file in a
human\-readable format), k = keys (print executed translations), m =
midi (MIDI monitor, print all recognizable MIDI input), j = jack (print
information about the Jack MIDI backend).
Just \f[C]\-d\f[R] enables all debugging options.
See Section \f[I]Basic Usage\f[R].
.TP
.B \-j \f[I]name\f[R]
Set the Jack client name.
This overrides the corresponding directive in the configuration file.
Default: \[lq]midizap\[rq].
See Section \f[I]Jack\-Related Options\f[R].
.TP
.B \-k
Keep track of key (on/off) status.
This may occasionally be useful to deal with quirky controllers sending
repeated on or off messages.
See Section \f[I]Key and Data Translations\f[R].
.TP
.B \-n
No automatic feedback.
By default, midizap keeps track of controller feedback from the second
input port if it is enabled (\f[C]\-o2\f[R]).
This option lets you disable this feature if the second port is being
used for other purposes.
See Section \f[I]Automatic Feedback\f[R].
.TP
.B \-o[\f[I]n\f[R]]
Enable MIDI output and set the number of output ports \f[I]n\f[R] (1 by
default).
Use \f[I]n\f[R] = 2 for a second pair of MIDI ports, e.g., for
controller feedback, or \f[I]n\f[R] = 0 to disable MIDI output.
This overrides the corresponding directive in the configuration file.
See Section \f[I]Jack\-Related Options\f[R].
.TP
.B \-P[\f[I]prio\f[R]]
Run with the given real\-time priority (default: 90).
See Section \f[I]Jack\-Related Options\f[R].
.TP
.B [\-r] \f[I]rcfile\f[R]
Set the configuration file name.
The \f[C]\-r\f[R] is optional, but still supported for backward
compatibility.
Default: taken from the MIDIZAP_CONFIG_FILE environment variable if it
exists, or \[ti]/.midizaprc if it exists, /etc/midizaprc otherwise.
See Section \f[I]Configuration File\f[R].
.TP
.B \-s[\f[I]n\f[R]]
Pass through system messages from MIDI input to output; \f[I]n\f[R]
optionally specifies the port (0 = none, 1 = first, 2 = second port
only), default is pass\-through on both ports (if available).
This overrides the corresponding directive in the configuration file.
See Section \f[I]Jack\-Related Options\f[R].
.TP
.B \-t[\f[I]n\f[R]]
Pass through untranslated (non\-system) messages from MIDI input to
output; the meaning of the optional parameter \f[I]n\f[R] is the same as
with the \f[C]\-s\f[R] option.
This overrides the corresponding directive in the configuration file.
See Section \f[I]Jack\-Related Options\f[R].
.SH Description
.PP
midizap lets you control your multimedia applications using
MIDI (https://www.midi.org/), the venerable \[lq]Musical Instrument
Digital Interface\[rq] protocol which has been around since the 1980s.
Modern MIDI controllers are usually USB class devices which don\[cq]t
require any special interface or driver, and they are often much cheaper
than more specialized gear.
With midizap you can leverage these devices to control just about any
X11\-based application.
To these ends, it translates Jack MIDI input into X keyboard and mouse
events, and optionally MIDI output.
It does this by matching the class and title of the focused window
against the regular expressions for each application section in its
configuration (midizaprc) file.
If a regex matches, the corresponding set of translations is used.
If a matching section cannot be found, or if it doesn\[cq]t define a
suitable translation, the program falls back to a set of default
translations.
.PP
The midizaprc file is just an ordinary text file which you can edit to
configure the program.
The configuration language is fairly straightforward, basically the file
is just a list of MIDI messages (denoted with familiar human\-readable
mnemonics, no hex numbers!) and their translations.
An example.midizaprc file is included in the sources to get you started,
and you can find more examples of configuration files for various
purposes in the examples subdirectory.
.PP
Even if your target application already supports MIDI, midizap\[cq]s
MIDI output option will be useful if your controller can\[cq]t work
directly with the application because of protocol incompatibilities.
In particular, you can use midizap to turn any MIDI controller with
enough faders and buttons into a Mackie\-compatible device ready to be
used with most DAW (digital audio workstation) programs.
Another common use case is photo and video editing software.
This kind of software often lacks built\-in MIDI support, and midizap
can then be used to map the faders, encoders and buttons of your MIDI
controller to keyboard commands for adjusting colors, cutting, marking,
playback, scrolling, zooming, etc.
In other words, as long as the target application can be controlled with
simple keyboard shortcuts and/or MIDI commands, chances are that midizap
can make it work (at least to some extent) with your controller.
.SH Installation
.PP
First, make sure that you have the required dependencies installed.
The program needs a few X11 libraries and Jack.
And of course you need GNU make and gcc (the GNU C compiler).
On Ubuntu and other Debian\-based systems you should be able to get
everything that\[cq]s needed by running this command:
.IP
.nf
\f[C]
sudo apt install build\-essential libx11\-dev libxtst\-dev libjack\-dev
\f[R]
.fi
.PP
Then just run \f[C]make\f[R] and \f[C]sudo make install\f[R].
This installs the example.midizaprc file as /etc/midizaprc, and the
midizap program and the manual page in the default install location.
Usually this will be under /usr/local, but the installation prefix can
be changed with the \f[C]prefix\f[R] variable in the Makefile.
Also, package maintainers can use the \f[C]DESTDIR\f[R] variable to
install into a staging directory for packaging purposes.
.PP
For users of the Emacs text editor we provide a midizap mode which does
syntax\-highlighting of midizaprc files and also lets you launch a
midizap session in an Emacs buffer.
If Emacs was found during installation, the midizap\-mode.el file is
installed into the share/emacs/site\-lisp directory along with the other
files.
The Makefile tries to guess the proper installation prefix, but if
necessary you can also set the \f[C]elispdir\f[R] variable or copy the
file manually to a directory on your Emacs load\-path.
Please check midizap\-mode.el for more detailed instructions.
.SH Configuration File
.PP
After installation the system\-wide default configuration file will be
in /etc/midizaprc, where the program will be able to find it.
We recommend copying this file to your home directory, renaming it to
\&.midizaprc:
.IP
.nf
\f[C]
cp /etc/midizaprc \[ti]/.midizaprc
\f[R]
.fi
.PP
The \[ti]/.midizaprc file, if it exists, takes priority over
/etc/midizaprc, so it becomes your personal default midizap
configuration.
The midizaprc file included in the distribution is really just an
example; you\[cq]re expected to edit this file to adjust the bindings
for the MIDI controllers and the applications that you use.
.PP
It is also possible to specify the configuration file to be used, by
invoking midizap with the name of the midizaprc file on the command
line.
This is often used with more specialized configurations dealing with
specific applications or MIDI controllers.
E.g., to try one of the sample configurations in the sources:
.IP
.nf
\f[C]
midizap examples/APCmini.midizaprc
\f[R]
.fi
.PP
The program automatically reloads the midizaprc file whenever it notices
that the file has been changed.
Thus you can edit the file while the program keeps running, and have the
changes take effect immediately without having to restart the program.
When working on new translations, you may want to run the program in a
terminal, and employ some or all of the debugging options explained
below to see exactly how your translations are being processed.
.SH Basic Usage
.PP
The midizap program is a command line application, so you typically run
it from the terminal.
However, it is also possible to launch it from your Jack session manager
(see \f[I]Jack\-Related Options\f[R] below) or from your desktop
environment\[cq]s startup files once you\[cq]ve set up everything to
your liking.
If you\[cq]re an Emacs user, you can conveniently edit and launch
midizap configurations using midizap\[cq]s Emacs mode; please check the
midizap\-mode.el file included in the sources for details.
.PP
Try \f[C]midizap \-h\f[R] for a brief summary of the available options
with which the program can be invoked.
.PP
midizap uses Jack (http://jackaudio.org/) for doing all its MIDI input
and output, so you need to be able to run Jack and connect the Jack MIDI
inputs and outputs of the program.
We recommend using a Jack front\-end and patchbay program like
QjackCtl (https://qjackctl.sourceforge.io/) for this purpose.
In QjackCtl\[cq]s setup, make sure that you have selected \f[C]seq\f[R]
as the MIDI driver.
This exposes the ALSA sequencer ports of your MIDI hardware and other
non\-Jack ALSA MIDI applications as Jack MIDI ports, so that they can
easily be connected to midizap.
As an alternative, you can also run
a2jmidid (http://repo.or.cz/a2jmidid.git) as a separate ALSA\-Jack MIDI
bridge.
The latter method works well with both Jack1 and Jack2.
Jack\[cq]s built\-in bridge also does the job in Jack1, but in Jack2 it
doesn\[cq]t list the ALSA ports by their name, so it\[cq]s better to use
a2jmidid in that case.
When in doubt, just use a2jmidid.
You can have QJackCtl autostart a2jmidid by placing the command
\f[C]a2jmidid \-e &\f[R] into the \[lq]Execute script after Startup\[rq]
field which can be found under \[lq]Options\[rq] in QJackctl\[cq]s Setup
dialog.
.PP
Having that set up, start Jack, make sure that your MIDI controller is
connected, and try running \f[C]midizap\f[R] from the command line
(without any arguments).
In QjackCtl, open the Connections dialog and activate the second tab
named \[lq]MIDI\[rq], which shows all available Jack MIDI inputs and
outputs.
On the right side of the MIDI tab, you should now see a client named
\f[C]midizap\f[R] with one MIDI input port named \f[C]midi_in\f[R].
That\[cq]s the one you need to connect to your MIDI controller, whose
output port should be visible under the \f[C]alsa_midi\f[R] client on
the left side of the dialog (or the \f[C]a2j\f[R] client, if you\[cq]re
using a2jmidid).
.PP
To test the waters, you can hook up just about any MIDI keyboard and
give it a try with the default section in the distributed midizaprc
file, which contains some basic translations for mouse and cursor key
emulation.
Here is the relevant excerpt from that section:
.IP
.nf
\f[C]
[Default]
C5 XK_Button_1
D5 XK_Button_2
E5 XK_Button_3
F5 XK_Left
G5 XK_Up
A5 XK_Down
B5 XK_Right
CC1+ XK_Scroll_Up
CC1\- XK_Scroll_Down
\f[R]
.fi
.PP
We refer to Section \f[I]Translation Syntax\f[R] below for a discussion
of the syntax being used here, but it should be fairly obvious that
these translations map the white keys of the middle octave (MIDI notes
\f[C]C5\f[R] thru \f[C]B5\f[R]) to some mouse buttons and cursor
commands.
Switch the keyboard focus to some window with text in it, such as a
terminal or an editor window.
Pressing the keys C, D and E should click the mouse buttons, while F
thru B should perform various cursor movements.
Also, moving the modulation wheel (\f[C]CC1\f[R]) on your keyboard
should scroll the window contents up and down.
.PP
You can invoke the program with various debugging options to get more
verbose output.
E.g., try running \f[C]midizap \-drk\f[R] to have the program print the
recognized configuration sections and translations as they are executed.
Now press some of the keys and move the modulation wheel.
You\[cq]ll see something like:
.IP
.nf
\f[C]
$ midizap \-drk
Loading configuration: /home/user/.midizaprc
translation: Default for emacs\[at]hostname (class emacs)
CC1\-1\-: XK_Scroll_Down/D XK_Scroll_Down/U
CC1\-1\-: XK_Scroll_Down/D XK_Scroll_Down/U
G5\-1[D]: XK_Up/D
G5\-1[U]: XK_Up/U
A5\-1[D]: XK_Down/D
A5\-1[U]: XK_Down/U
\f[R]
.fi
.PP
The debugging output tells you pretty much everything you need to know
about what\[cq]s going on inside midizap, and helps you along when you
start developing your own configurations.
The \f[C]\-d\f[R] option can be combined with various option characters
to choose exactly which kinds of debugging output you want; \f[C]r\f[R]
(\[lq]regex\[rq]) prints the matched translation section (if any) along
with the window name and class of the focused window; \f[C]s\f[R]
(\[lq]strokes\[rq]) prints the parsed contents of the configuration file
in a human\-readable form whenever the file is loaded; \f[C]k\f[R]
(\[lq]keys\[rq]) shows the recognized translations as the program
executes them, in the same format as \f[C]s\f[R]; \f[C]m\f[R]
(\[lq]MIDI\[rq]) prints \f[I]any\f[R] received MIDI input, so that you
can figure out which MIDI tokens to use for configuring the translations
for your controller; and \f[C]j\f[R] adds some useful information about
the Jack backend, so that you see when the Jack client is ready, and
which MIDI ports it gets connected to.
You can also just use \f[C]\-d\f[R] to enable all debugging output.
Moreover, most of these options are also available as directives in the
midizaprc file, so that you can turn them on and off as needed without
having to exit the program; please check the comments at the beginning
of example.midizaprc for a list of these directives.
.PP
Most of the other translations in the distributed midizaprc file assume
a Mackie\-like device with standard playback controls and a jog wheel.
There are also a few more generic examples, like the one above, which
will work with almost any kind of MIDI keyboard.
The examples are mostly for illustrative and testing purposes, though,
to help you get started.
You will want to edit them and add translations for your own controllers
and favorite applications.
.SH MIDI Output
.PP
As already mentioned, the midizap program can also be made to function
as a MIDI mapper which translates MIDI input to MIDI output.
MIDI output is enabled by running the program as \f[C]midizap \-o\f[R].
This equips the Jack client with an additional MIDI output port named
\f[C]midi_out\f[R] (visible on the left side of QjackCtl\[cq]s
Connection window).
.PP
The example.midizaprc file comes with a sample configuration in the
special \f[C][MIDI]\f[R] default section for illustration purposes.
This section is only active if the program is run with the \f[C]\-o\f[R]
option.
It allows MIDI output to be sent to any connected applications, no
matter which window currently has the keyboard focus.
This is probably the most common way to use this feature, but of course
it is also possible to have application\-specific MIDI translations, in
the same way as with X11 key bindings.
In fact, you can freely mix mouse actions, key presses and MIDI messages
in all translations.
.PP
You can try it and test that it works by running \f[C]midizap \-o\f[R]
along with a MIDI synthesizer such as
FluidSynth (http://www.fluidsynth.org/) or its graphical front\-end
Qsynth (https://qsynth.sourceforge.io/).
Use QjackCtl to connect FluidSynth\[cq]s MIDI input to midizap\[cq]s
output port.
In the sample configuration, the notes \f[C]C4\f[R] thru \f[C]F4\f[R] in
the small octave have been set up so that you can use them to operate a
little drumkit, and a binding for the volume controller (\f[C]CC7\f[R])
has been added as well.
The relevant portion from the configuration entry looks as follows:
.IP
.nf
\f[C]
[MIDI]
C4 C3\-10
D4 C#3\-10
E4 D3\-10
F4 D#3\-10
CC7= CC7\-10
\f[R]
.fi
.PP
Note the \f[C]\-10\f[R] suffix on the output messages in the above
example, which indicates that output goes to MIDI channel 10.
In midizaprc syntax, MIDI channels are 1\-based, so they are numbered
1..16, and 10 denotes the GM (General MIDI) drum channel.
E.g., the input note \f[C]C4\f[R] is mapped to \f[C]C3\-10\f[R], the
note C in the third MIDI octave, which on channel 10 will produce the
sound of a bass drum, at least on GM compatible synthesizers like
Fluidsynth.
The binding for the volume controller (\f[C]CC7\f[R]) at the end of the
entry sends volume changes to the same drum channel (\f[C]CC7\-10\f[R]),
so that you can use the volume control on your keyboard to change the
volume on the drum channel.
.PP
Besides MIDI notes and control change (\f[C]CC\f[R]) messages, the
midizap program also recognizes key and channel pressure (\f[C]KP\f[R],
\f[C]CP\f[R]), program change (\f[C]PC\f[R]), and pitch bend
(\f[C]PB\f[R]) messages, which should cover most common use cases.
These are discussed in more detail in the \f[I]Translation Syntax\f[R]
section below.
In addition, unrecognized MIDI messages can be simply passed through
with the \f[C]\-t\f[R] option.
Also, while midizap cannot translate system messages such as system
exclusive, you can pass them through as well with the \f[C]\-s\f[R]
option, see the following section for details.
.SH Jack\-Related Options
.PP
There are some additional directives (and corresponding command line
options) to configure midizap\[cq]s Jack setup in various ways.
If both the command line options and directives in the midizaprc file
are used, the former take priority, so that it\[cq]s possible to
override the configuration settings from the command line.
Note that all these options can only be set at program startup.
If you later edit the corresponding directives in the configuration
file, the changes won\[cq]t take effect until you restart the program.
.SS Jack Client Name and MIDI Port Setup
.PP
Firstly, there\[cq]s the \f[C]\-j\f[R] option and the
\f[C]JACK_NAME\f[R] directive which change the Jack client name from the
default (\f[C]midizap\f[R]) to whatever you want it to be.
To use this option, simply invoke midizap as
\f[C]midizap \-j client\-name\f[R], or put the following directive into
your midizaprc file:
.IP
.nf
\f[C]
JACK_NAME \[dq]client\-name\[dq]
\f[R]
.fi
.PP
This option is useful, in particular, if you\[cq]re running multiple
instances of midizap with different configurations for different
controllers and/or target applications, and you want to have the
corresponding Jack clients named differently, so that they can be
identified more easily.
.PP
Secondly, we\[cq]ve already seen the \f[C]\-o\f[R] option which is used
to equip the Jack client with an additional output port.
This can also be achieved with the \f[C]JACK_PORTS\f[R] directive in the
midizaprc file, as follows:
.IP
.nf
\f[C]
JACK_PORTS 1
\f[R]
.fi
.PP
The given number of output ports must be 0, 1 or 2.
Zero means that MIDI output is disabled (which is the default).
You may want to use \f[C]JACK_PORTS 1\f[R] if the configuration is
primarily aimed at doing MIDI translations, so you\[cq]d like to have
MIDI output enabled by default.
\f[C]JACK_PORTS 2\f[R] or the \f[C]\-o2\f[R] option indicates that
\f[I]two\f[R] pairs of input and output ports are to be created.
The second port is typically used to deal with controller feedback from
the application, see the \f[I]MIDI Feedback\f[R] section for details.
.PP
Not very surprisingly, at least one output port is needed if you want to
output any MIDI at all; otherwise MIDI messages on the right\-hand side
of translations will be silently ignored.
.SS MIDI Connections
.PP
Setting up all the required connections for the Jack MIDI ports can be a
tedious and error\-prone task, especially if you have to deal with
complex setups involving feedback and/or multiple midizap instances.
It\[cq]s all to easy to mess this up when doing it manually, and end up
with a dysfunctional setup or, even worse, MIDI feedback loops crashing
your Jack MIDI clients.
While it\[cq]s possible to automatize the MIDI connections, e.g., with
QjackCtl\[cq]s persistent MIDI patchbay facility, this is often
inconvenient if you need to accommodate multiple midizap configurations
and you already have a complicated studio setup which you don\[cq]t want
to mess with.
.PP
As a remedy, midizap offers its own built\-in patchbay functionality
using the \f[C]JACK_IN\f[R] and \f[C]JACK_OUT\f[R] directives, which let
you specify the required connections in the configuration itself and be
done with it.
The port number is tacked on to the directive, so, e.g.,
\f[C]JACK_IN2\f[R] connects the second input port.
If the port number is omitted then it defaults to 1, so both
\f[C]JACK_OUT1\f[R] and just \f[C]JACK_OUT\f[R] connect the first output
port.
The directive is followed by a regular expression to be matched against
the Jack MIDI ports of your devices and applications.
Please see the regex(7) manual page for a discussion of the syntax and
meaning of regular expressions.
Note that regular expressions come in two different flavors,
\[lq]basic\[rq] and \[lq]extended\[rq]; midizap uses the latter kind.
.PP
A connection will be established automatically by midizap whenever a
MIDI port belonging to another Jack client matches the regular
expression, as well as the port type and I/O direction.
This also works dynamically, as new devices get added and new
applications are launched at runtime.
.PP
For instance, the following lines (from the XTouchONE.midizaprc example)
connect midizap to an X\-Touch One device on one side and Ardour\[cq]s
Mackie control port on the other:
.IP
.nf
\f[C]
JACK_IN1 X\-Touch One MIDI 1
JACK_OUT1 ardour:mackie control in
JACK_IN2 ardour:mackie control out
JACK_OUT2 X\-Touch One MIDI 1
\f[R]
.fi
.PP
To break this down, the X\-Touch One device will be connected to
midizap\[cq]s first input port, midizap\[cq]s first output port to
Ardour\[cq]s Mackie control input, Ardour\[cq]s Mackie control output to
midizap\[cq]s second input port, and midizap\[cq]s second output port
back to the device.
This is a typical setup for bidirectional communication between
controller and application as described in the \f[I]MIDI Feedback\f[R]
section.
The sample configurations in the examples folder in the sources have all
been set up in this manner, so that they will create the required
connections automatically.
.PP
Please note that in the present implementation, the built\-in patchbay
is only available through these directives, there are no corresponding
command line options.
Also, only one directive can be specified for each port, but since
midizap will connect to all ports matching the given regular expression,
you can connect to more than one application or device by just listing
all the alternatives.
For instance, to have midizap\[cq]s output connected to both Ardour and
Pd, you might use a directive like:
.IP
.nf
\f[C]
JACK_OUT1 ardour:MIDI control in|Pure Data Midi\-In 1
\f[R]
.fi
.PP
All matches are done against full port names including the
\f[I]client\-name\f[R]\f[C]:\f[R] prefix, so you can specify exactly
which ports of which clients should be connected.
However, note that in contrast to the QJackCtl patchbay, midizap does
substring matches by default, so that, e.g., \f[C]MIDI control\f[R] will
match \f[I]any\f[R] Ardour MIDI control port, in any instance of the
program (and also ports with the same name in other programs).
If you want to specify an exact match, you need to use the
\f[C]\[ha]\f[R] and \f[C]$\f[R] anchors as follows:
.IP
.nf
\f[C]
JACK_OUT1 \[ha]ardour:MIDI control in$
\f[R]
.fi
.SS Pass\-Through
.PP
If at least one output port is available then it also becomes possible
to pass through MIDI messages from input to output unchanged.
Two options are available for this: \f[C]\-t\f[R] which passes through
any ordinary (non\-system) message for which there are no translations
(not even in the default section), and \f[C]\-s\f[R] which passes
through all system messages.
The former is convenient if the incoming MIDI data only needs to be
modified in a few places to deal with slight variations in the protocol.
The latter may be needed when the input data may contain system
messages; midizap cannot translate these, but it can pass them on
unchanged when necessary.
You can find examples for both use cases in the examples folder in the
sources.
.PP
The corresponding directives are named \f[C]PASSTHROUGH\f[R] and
\f[C]SYSTEM_PASSTHROUGH\f[R], respectively.
In either case, you can optionally specify which port the pass\-through
should apply to (0 means none, 1 the first, 2 the second port; if no
number is given, both ports are used).
For instance, if you only need system pass\-through on the feedback
port, you might write \f[C]SYSTEM_PASSTHROUGH 2\f[R], or use the
\f[C]\-s2\f[R] option on the command line; and to have unrecognized MIDI
messages passed through in either direction, simply use
\f[C]PASSTHROUGH\f[R], or \f[C]\-t\f[R].
.SS Jack Sessions
.PP
midizap also supports \f[I]Jack session management\f[R] which provides a
convenient alternative way to launch your midizap instances.
Once you\[cq]ve finished a configuration, instead of running midizap
manually each time you need it, you just invoke it once with the right
command line options, and use a Jack session management program to
record the session.
The session manager can then be used to relaunch the program with the
same options later.
.PP
Various Jack session managers are available for Linux, but if you\[cq]re
running QjackCtl already, you might just as well use it to record your
sessions, too.
QjackCtl\[cq]s built\-in Jack session manager is available in its
Session dialog.
To use it, launch midizap and any other Jack applications you want to
have in the session, use QjackCtl to set up all the connections as
needed, and then hit the \[lq]Save\[rq] button in the Session dialog to
have the session recorded.
Now, at any later time you can rerun the recorded session with the
\[lq]Load\[rq] button in the same dialog.
Also, your most recent sessions are available in the \[lq]Recent\[rq]
menu from where they can be launched quickly.
.SS Realtime Priorities
.PP
Finally, midizap also offers an option to run the program with
\f[I]real\-time priorities\f[R].
Jack itself usually does that anyway where needed, but midizap\[cq]s
main thread won\[cq]t unless you run it with the \f[C]\-P\f[R] option.
Using this option, midizap should be able to get down to MIDI latencies
in the 1 msec ballpark which should be good enough for most purposes.
(Note that there\[cq]s no need to use this option unless you actually
notice high latencies or jitter in the MIDI output.)
.SH Translation Syntax
.PP
The midizap configuration file consists of sections defining translation
classes.
Each section generally looks like this, specifying the name of a
translation class, optionally a regular expression to be matched against
the window class or title, and a list of translations:
.IP
.nf
\f[C]
[name] regex
<A..G><#b><0..12> output # note
KP:<note> output # key pressure (aftertouch)
PC<0..127> output # program change
CC<0..127> output # control change
CP output # channel pressure
PB output # pitch bend
\f[R]
.fi
.PP
The \f[C]#\f[R] character at the beginning of a line and after
whitespace is special; it indicates that the rest of the line is a
comment, which is skipped by the parser.
Empty lines and lines containing nothing but whitespace are also
ignored.
.PP
Lines beginning with a \f[C][\f[R]\f[I]name\f[R]\f[C]]\f[R] header are
also special.
Each such line introduces a translation class \f[I]name\f[R], which may
be followed by an extended regular expression \f[I]regex\f[R] to be
matched against window class and title.
A \f[C]CLASS\f[R] or \f[C]TITLE\f[R] token may precede \f[I]regex\f[R]
to indicate that \f[I]only\f[R] the class or title is to be matched,
respectively; otherwise both are matched.
Note that the \f[I]regex\f[R] part is always taken verbatim, ignoring
leading and trailing whitespace, but including embedded whitespace and
\f[C]#\f[R] characters (so you can\[cq]t place a comment on such lines).
.PP
To find a set of eligible translations, midizap matches class and/or
title of the window with the keyboard focus against each section, in the
order in which they are listed in the configuration file.
If neither \f[C]CLASS\f[R] nor \f[C]TITLE\f[R] is specified, then both
are tried; in this case, midizap first tries to match the window class
(the \f[C]WM_CLASS\f[R] property), then the window title (the
\f[C]WM_NAME\f[R] property).
The first section which matches determines the translations to be used
for that window.
An empty \f[I]regex\f[R] for the last class will always match, allowing
default translations.
If a translation cannot be found in the matched section, it will be
loaded from the default section if possible.
In addition, there are two special default sections labeled
\f[C][MIDI]\f[R] and \f[C][MIDI2]\f[R] which are used specifically for
MIDI translations, please see the \f[I]MIDI Output\f[R] and \f[I]MIDI
Feedback\f[R] sections for details.
If these sections are present, they should precede the main default
section.
All other sections, including the main default section, can be named any
way you like; the given \f[I]name\f[R] is only used for debugging output
and diagnostics, and needn\[cq]t be unique.
.PP
This means that when you start writing a section for a new application,
the first thing you\[cq]ll have to do is determine its window class and
title, so that you can figure out a regular expression to use in the
corresponding section header.
The easiest way to do this is to run midizap with the \f[C]\-dr\f[R]
option.
Make sure that your controller is hooked up to midizap, click on the
window and wiggle any control on your device.
You\[cq]ll get a message like the following, telling you both the title
and the class name of the window (as well as the name of the translation
class if the window is already recognized):
.IP
.nf
\f[C]
translation: Default for mysession \- Ardour (class ardour_ardour)
\f[R]
.fi
.PP
Here, the class name is \[lq]ardour_ardour\[rq] and the window title
\[lq]mysession \- Ardour\[rq].
Either can be used for the regular expression, but the class name
usually provides the more specific clues for identifying an application.
So we might begin a translation section for Ardour as follows:
.IP
.nf
\f[C]
[Ardour] CLASS \[ha]ardour_ardour$
\f[R]
.fi
.PP
Here we explicitly specified that only the window class is to be matched
and we employed the \f[C]\[ha]\f[R] and \f[C]$\f[R] anchors to ensure
that the entire string is matched, so this section will match precisely
Ardour windows and nothing else.
We could also write, rather sloppily:
.IP
.nf
\f[C]
[Ardour] [Aa]rdour
\f[R]
.fi
.PP
This will match any window which has the string \[lq]Ardour\[rq] or
\[lq]ardour\[rq] \f[I]anywhere\f[R] in its class or title, so it will
match Ardour windows, but also, say, the window of a text editor which
happens to have a file named \[lq]Ardour.txt\[rq] loaded.
So while regular expressions give you a lot of leeway in identifying
windows, it\[cq]s always a good idea to be as specific with the regex as
possible.
.PP
The header is followed by a list of translations which define what
output should be produced for the given MIDI input.
Each translation must be on a line by itself.
The left\-hand side (first token) of the translation denotes the MIDI
message to be translated.
The corresponding right\-hand side (the rest of the line) is a sequence
of zero or more tokens, separated by whitespace, indicating MIDI and X11
keyboard and mouse events to be output.
The output sequence may be empty, or just the special token
\f[C]NOP\f[R] (which doesn\[cq]t produce any output), to indicate that
the translation outputs nothing at all; this suppresses the default
translation for this input.
Translation classes may be empty as well (i.e., not provide any
translations), in which case \f[I]only\f[R] the default translations are
active, even if a later non\-default section matches the same window.
.PP
\f[B]NOTE:\f[R] Translations may be listed in any order, but they
\f[I]must be determined uniquely\f[R], i.e., each input message may be
bound to at most one output sequence in each translation class.
Otherwise, the parser will print an error message, and the extra
translations will be ignored.
This restriction makes it easier to detect inconsistencies, and it also
ensures that midizap\[cq]s operation is completely
\f[I]deterministic\f[R].
That is, for each input sequence on a given window the program will
always generate exactly the same output sequence.
.PP
Example:
.IP
.nf
\f[C]
[Terminal] CLASS \[ha](.*\-terminal.*|konsole|xterm)$
F5 XK_Up
F#5 \[dq]pwd\[dq]
G5 XK_Down
G#5 \[dq]ls\[dq]
A5 XK_Return
\f[R]
.fi
.PP
This binds a few keys in the middle octave to the Up, Down and Return
keys as well as some frequently used shell commands, in a section named
\f[C]Terminal\f[R] which matches some common types of terminal windows
by their class names.
The bindings in this translation class will let you operate the shell
from your MIDI keyboard when the keyboard focus is on a terminal window.
.SS MIDI Message Notation
.PP
There\[cq]s no real standard for symbolic designations of MIDI messages,
but we hope that most users will find midizap\[cq]s notation easy to
understand and remember.
Notes are specified using a format which musicians will find familiar: a
note name \f[C]A\f[R], \f[C]B\f[R], \&..., \f[C]G\f[R] is followed by an
(optional) accidental (\f[C]#\f[R] or \f[C]b\f[R]), and a (mandatory)
MIDI octave number.
Note that all MIDI octaves start at the note C, so \f[C]B0\f[R] comes
before \f[C]C1\f[R].
By default, \f[C]C5\f[R] denotes middle C (you can change this if you
want, see \f[I]Octave Numbering\f[R] below).
Enharmonic spellings are equivalent, so, e.g., \f[C]D#5\f[R] and
\f[C]Eb5\f[R] denote exactly the same MIDI note.
.PP
The other messages are denoted using short mnemonics:
\f[C]KP:\f[R]\f[I]note\f[R] (aftertouch a.k.a.\ key pressure for the
given note); \f[C]CC\f[R]\f[I]n\f[R] (control change for the given
controller number); \f[C]PC\f[R]\f[I]n\f[R] (program change for the
given program number); \f[C]CP\f[R] (channel pressure); and \f[C]PB\f[R]
(pitch bend).
We will go into the other syntactic bits and pieces of MIDI message
designations later, but it\[cq]s good to have the following grammar in
EBNF notation handy for reference.
(To keep things simple, the grammar is somewhat abridged, but it covers
all the frequently used notation.
There is some additional syntax for special forms of translations which
will be introduced later.
Also, at the end of the manual you can find a complete grammar for the
entire configuration language.)
.IP
.nf
\f[C]
token ::= msg [ \[dq][\[dq] number \[dq]]\[dq] ] [ \[dq]\-\[dq] number ] [ flag ]
msg ::= ( note | other ) [ number ]
note ::= ( \[dq]A\[dq] | ... | \[dq]G\[dq] ) [ \[dq]#\[dq] | \[dq]b\[dq] ]
other ::= \[dq]CH\[dq] | \[dq]PB\[dq] | \[dq]PC\[dq] | \[dq]CC\[dq] | \[dq]CP\[dq] | \[dq]KP:\[dq] note
flag ::= \[dq]\-\[dq] | \[dq]+\[dq] | \[dq]=\[dq] | \[dq]<\[dq] | \[dq]>\[dq] | \[dq]\[ti]\[dq]
\f[R]
.fi
.PP
Case is ignored here, so \f[C]CC\f[R], \f[C]cc\f[R] or even \f[C]Cc\f[R]
are considered to be exactly the same token by the parser, although by
convention we usually write them in uppercase.
Numbers are always integers in decimal.
The meaning of the \f[C]msg\f[R] number depends on the context (octave
number for notes and key pressure, controller or program number in the
range 0..127 for other messages, MIDI channel number in the range 1..16
for the special \f[C]CH\f[R] token).
This can optionally be followed by a number in brackets, denoting a
nonzero step size.
Also optionally, a suffix with a third number (after the dash) denotes
the MIDI channel in the range 1..16; otherwise the default MIDI channel
is used (which is always 1 on the left\-hand side, but can be set on the
right\-hand side with the \f[C]CH\f[R] token).
The optional \[lq]increment\[rq] flag at the end of a token indicates a
\[lq]data\[rq] translation which responds to incremental (up/down) value
changes rather than key presses, cf.\ \f[I]Key and Data
Translations\f[R] below.
.SS Octave Numbering
.PP
A note on the octave numbers in MIDI note designations is in order here.
There are various different standards for numbering octaves, and
different programs use different standards, which can be rather
confusing.
E.g., there\[cq]s the ASA (Acoustical Society of America) standard where
middle C is C4, also known as \[lq]scientific\[rq] or \[lq]American
standard\[rq] pitch notation.
At least two other standards exist specifically for MIDI octave
numbering, one in which middle C is C3 (so the lowest MIDI octave starts
at C\-2), and zero\-based octave numbers, which start at C0 and have
middle C at C5.
There\[cq]s not really a single \[lq]best\[rq] standard here, but the
latter seems intuitive to mathematically inclined and computer\-savvy
people, and is also what is used by default in the midizaprc file.
.PP
However, you may want to change this, e.g., if you\[cq]re working with
documentation or MIDI monitoring software which uses a different
numbering scheme.
To do this, just specify the desired offset for the lowest MIDI octave
with the special \f[C]MIDI_OCTAVE\f[R] directive in the configuration
file.
For instance:
.IP
.nf
\f[C]
MIDI_OCTAVE \-1 # ASA pitches (middle C is C4)
\f[R]
.fi
.PP
Note that this transposes \f[I]all\f[R] existing notes in translations
following the directive, so if you add this option to an existing
configuration, you probably have to edit the note messages in it
accordingly.
.SS Key and Data Translations
.PP
Translations come in two flavors or \[lq]modes\[rq], \f[I]key
translations\f[R] and \f[I]data translations\f[R], which differ in the
way the extra data payload of the input message, called the
\f[I]parameter value\f[R] (or just \f[I]value\f[R] for short), is
processed.
The parameter value depends on the type of MIDI message.
Program changes (\f[C]PC\f[R]) have no value at all.
For notes, as well as key and channel pressure messages (\f[C]CP\f[R],
\f[C]KP\f[R]), it is a velocity value; for control changes
(\f[C]CC\f[R]), a controller value; and for pitch bend messages
(\f[C]PB\f[R]), a pitch bend value.
The latter is a 14 bit value composed of the two data bytes in the
message, which is considered as a signed quantity in the range
\-8192..8191, where 0 denotes the center value.
In all other cases, the parameter value consists of a single data byte,
which denotes an unsigned 7 bit quantity in the range 0..127.
.PP
Note that since translations must be determined uniquely in each
translation class, you can\[cq]t have both key \f[I]and\f[R] data
translations for the same input in the same section; it\[cq]s either one
or the other.
.PP
\f[I]Key mode\f[R] is the default mode and is available for all message
types.
In this mode, MIDI messages are considered as keys which can be
\[lq]pressed\[rq] (\[lq]on\[rq]) or \[lq]released\[rq] (\[lq]off\[rq]).
Any nonzero data value means \[lq]pressed\[rq], zero \[lq]released\[rq].
Two special cases need to be considered here:
.IP \[bu] 2
For pitch bends, any positive \f[I]or\f[R] negative value means
\[lq]pressed\[rq], while 0 (the center value) means \[lq]released\[rq].
.IP \[bu] 2
Since program changes have no parameter value associated with them, they
don\[cq]t really have an \[lq]on\[rq] or \[lq]off\[rq] status.
But they are treated in the same key\-like fashion anyway, assuming that
they are \[lq]pressed\[rq] and then \[lq]released\[rq] immediately
afterwards.
.PP
Key mode can optionally keep track of the current key (on/off) status,
so that a key translation is only triggered when its status actually
changes.
Normally this shouldn\[cq]t be necessary and thus it is disabled by
default.
You usually want to keep it that way, unless you\[cq]re dealing with a
quirky controller or an unreliable transmission line.
In such cases it may useful to enable this option with the \f[C]\-k\f[R]
option on the command line, so that, e.g., repeated note\-ons or \-offs
are filtered out automatically.
.PP
\f[I]Data mode\f[R] is available for all messages with a parameter
value, i.e., anything but \f[C]PC\f[R].
In this mode, the actual value of the message is processed rather than
just the on/off state.
Data mode is indicated with a special suffix on the message token which
denotes a step size and/or the direction of the value change which the
rule should apply to: increment (\f[C]+\f[R]), decrement (\f[C]\-\f[R]),
or both (\f[C]=\f[R]).
The two parts are both optional, but at least one of them must be
present (otherwise the rule is interpreted as a key translation).
.PP
In the following, we concentrate on \f[I]incremental\f[R] data mode
messages, i.e., the kind which has an increment suffix.
In this case, the optional step size in brackets indicates the amount of
change required to trigger the translation, so its effect is to
downscale the amount of change in the input value.
The variant without an increment suffix is more complicated and mostly
intended for more specialized uses, so we\[cq]ll have a look at it later
in the \f[I]Mod Translations\f[R] section.
.PP
Data mode usually tracks changes in the \f[I]absolute\f[R] value of a
control.
However, for \f[C]CC\f[R] messages there\[cq]s also an alternative mode
for so\-called \f[I]relative\f[R] controllers which can found on some
devices.
These usually take the form of jog wheels or rotary encoders which can
be turned endlessly in either direction, therefore we also just call
them \f[I]encoders\f[R] for short in the following.
There are various kinds of these which differ in the way they represent
relative changes, but these days most encoders found on MIDI controllers
employ the \f[I]sign bit\f[R] format; this is also the only kind
supported by midizap in the present implementation.
In the sign\-bit representation, a value <64 denotes an increment
(representing clockwise rotation), and a value >64 a decrement
(counter\-clockwise rotation); the actual amount of change is in the
lower 6 bits of the value.
In the message syntax, sign\-bit values are indicated by using the
suffixes \f[C]<\f[R], \f[C]>\f[R] and \f[C]\[ti]\f[R] in lieu of
\f[C]\-\f[R], \f[C]+\f[R] and \f[C]=\f[R], respectively.
These flags are only permitted with \f[C]CC\f[R] messages.
.SS Keyboard and Mouse Events
.PP
Keyboard and mouse output consists of X key codes with optional up/down
indicators, or strings of printable characters enclosed in double
quotes.
The syntax of these items, as well as the special \f[C]RELEASE\f[R] and
\f[C]SHIFT\f[R] tokens which will be discussed later, are described by
the following grammar:
.IP
.nf
\f[C]
token ::= \[dq]RELEASE\[dq] | \[dq]SHIFT\[dq] [ number ] |
keycode [ \[dq]/\[dq] keyflag ] | string
keycode ::= \[dq]XK_Button_1\[dq] | \[dq]XK_Button_2\[dq] | \[dq]XK_Button_3\[dq] |
\[dq]XK_Scroll_Up\[dq] | \[dq]XK_Scroll_Down\[dq] |
\[dq]XK_...\[dq] (X keysyms, see /usr/include/X11/keysymdef.h)
keyflag ::= \[dq]U\[dq] | \[dq]D\[dq] | \[dq]H\[dq]
string ::= \[aq]\[dq]\[aq] { character } \[aq]\[dq]\[aq]
\f[R]
.fi
.PP
Here, case \f[I]is\f[R] significant (except in character strings, see
the remarks below), so the special \f[C]RELEASE\f[R] and \f[C]SHIFT\f[R]
tokens must be in all caps, and the \f[C]XK\f[R] symbols need to be
written in mixed case exactly as they appear in the
/usr/include/X11/keysymdef.h file.
Besides the key codes from the keysymdef.h file, there are also some
special additional key codes to denote mouse button and scroll wheel
events (\f[C]XK_Button_1\f[R], \f[C]XK_Scroll_Up\f[R], etc.).
.PP
Any keycode can be followed by an optional \f[C]/D\f[R], \f[C]/U\f[R],
or \f[C]/H\f[R] flag, indicating that the key is just going down
(without being released), going up, or going down and being held until
the \[lq]off\[rq] event is received.
So, in general, modifier key codes will be followed by \f[C]/D\f[R], and
precede the keycodes they are intended to modify.
If a sequence requires different sets of modifiers for different
keycodes, \f[C]/U\f[R] can be used to release a modifier that was
previously pressed with \f[C]/D\f[R].
Sequences may also have separate press and release sequences, separated
by the special word \f[C]RELEASE\f[R].
Examples:
.IP
.nf
\f[C]
C5 \[dq]qwer\[dq]
D5 XK_Right
E5 XK_Alt_L/D XK_Right
F5 \[dq]V\[dq] XK_Left XK_Page_Up \[dq]v\[dq]