Jacktube v0.20
==============

   Jacktube is an audio/MIDI processing program. It uses LADSPA plugins
to process audio, MIDI events to control its operation and Jack
is used for audio connections. The exact operation is governed by
a set of customizable rules.

   Even though Jacktube is primarily meant for audio work, it can be
used in any signal processing application.

   Maintainer: Kristian Amlie <kristian at amlie.name>


Command line options
====================

   I'm too lazy maintain documentation of options both here and in
the program. This should do the trick:

   jacktube -h


Rules
=====

   Jacktube operates by receiving audio from Jack input ports, using
LADSPA to process the audio and handing the result to one or more output
ports. In addition, MIDI events can be received from one or more
sequencer ports and can either be used to control the operation of the
audio path or can be modified and sent back out on a MIDI output port.

   The rule file consists of commands telling Jacktube what to do.
A simple command may look like this:

   $variable = 1.5;

   This assigns the value 1.5 to the variable called "$variable".
Variables have no direct effect on the signal path, but are useful to
hold values in the program. All variables start with "$".

   You can also use arrays like this:

   $array[3] = 4.3;

   Any positive integer (and zero) can be used as a subscript and a
variable or arithmetic expression can be used as well. All the elements
are created on the fly, and the array does not need to be declared first.

   An audio path can be constructed like this:

   >~output ~ <~input;

   This constructs a Jack output port ">~output" and an input port
"<~input", and creates a path between them, so that the signal will flow
from "<~input" to ">~output". All Jack output ports start with ">~"
(think shell redirection, you write "into" the port so that it appears
as an output port in the Jack port graph), and input ports start with
"<~" (similar redirection mnemonic). Any port can only be written to
by one other port, which means that the following command will replace
the audio path we made above.

   >~output ~ <~anotherInput;

   A port can be read by as many ports as you like. To remove an audio
path completely, use this command:

   >~output -;

   (Think "~" for audio wave, and "-" for flatline).

   Audio paths are useful, but they become much more powerful when
combined with plugins. Before a plugin can be used, it must be loaded.
You can obtain a list of available plugins by using "jacktube -l" (the
normal LADSPA environment variables apply). Once a plugin is selected,
it is loaded using either of these commands:

   %plugin = 1048;

   -or-

   %plugin = "amp_mono";

   You can identify a plugin using either its short name or its unique
ID, as shown above. The plugin is now loaded under the name "%plugin",
and again, all plugin instances start with "%".

   LADSPA plugins come with a number of ports, which are either control
ports or audio ports (can be obtained "jacktube -p"). Let's connect
them:

   %plugin["gain"] = 0.5;
   %plugin["input"] ~ <~input;
   >~output ~ %plugin["output"];

   So what happened here? We assigned the control parameter "gain" a
value of 0.5. Then we connected the plugins input to the input from
Jack, followed by connecting the Jack output to the output from the
plugin. This audio path will modify the input signal so that the output
signal has its amplitude cut in half.

   Note that you can use both variables and arbitrary arithmetics in the
control port assignment. In addition the port name can be replaced by its
numeric name if you like. So this is legal:

   %plugin[0] = $variable * 2 - 0.8;

   The operators are "+", "-", "*", "/" and "^" (raise).

   But the real magic is this: A control port can receive its input from
a signal path as well, like this:

   %plugin["gain"] ~ <~anotherInput;

   The gain parameter will now vary with its input signal (see the -s
option for controlling the granularity of this processing). You cannot
use arithmetics on this path directly, but the signal can come from a
plugin as well, so you can preprocess it there before it gets to the
control port.

   Why is this useful, do you ask? Won't the control just fluctuate
wildly and create noise? In most cases, yes, but remember that the input
signal doesn't have to be audio. It could be a low frequency oscillator,
for example like this:

   %gain = "amp_mono";
   %oscillator = "sine_fcac";
   %oscillator["freq"] = 1;
   %oscillator["amplitude"] = 0.5;
   %gain["gain"] ~ %oscillator["output"];
   %gain["input"] ~ <~input;
   >~output ~ %gain["output"];

   Here, the oscillator is set to oscillate at 1Hz, and send its output
to the gain control port, causing the audio signal to rise and lower
between 0 and 0.5 gain, once per second.

   As described before, MIDI events can be used to control the behavior
of Jacktube. MIDI events take the shape of an event range followed by an
event scope, which contains the commands that should be executed for that
event:

   [<@seqInput, 0-127, type[control]-type[control], 1-1, 0-127]
   {
      %gain["gain"] -;
      %gain["gain"] = event[value];
   }

   The first variable there is the sequencer input port (the names start
with "<@" and ">@", and have similar semantics like audio ports). After
follows four ranges, which specify for which event values this action
should trigger. The order is channel, type, key/control, velocity/value.
Type is the type of MIDI event, which is between 0 and 127. "type[xxx]"
constants can be used to test for specific types of events, where xxx is
either keyon, keyoff, keypress, pitch, program, control or channelpress.
The rest of the ranges should be self explanatory. The "event[value]" is
a variable containing the value which caused this event to trigger. The
different types are channel, type, key/param and velocity/value.

   Note that variables are allowed in the ranges, but no arithmetics. In
addition, plugin loading is not allowed inside the event scope. All
the events that match are executed; Jacktube does not stop on the first
match. This can be changed, however, by putting the "stop" statement
somewhere in the event scope. This prevents Jacktube from executing any
events that come after the one containing the statement.

In addition to the already mentioned actions, MIDI events can be sent out
too. Here is how that looks:

   [<@seqInput, 0-127, type[control]-type[control], 1-1, 0-127]
   {
      >@seqOutput = [3, event[type], event[key], event[value]];
   }

   This sends the same MIDI message back out on ">@seqOutput", except
that it is always sent on channel 3. MIDI messages are only allowed
inside an event scope.

   One can also put if statements inside the event scopes, and they look
more or less exactly like a C/C++ if statement, with some exceptions:
First, the braces are required, and second, you write "elseif" instead of
"else if". For example:

   [<@seqInput, 0-127, type[control]-type[control], 1-1, 0-127]
   {
      if (event[value] > 64) {
         >@seqOutput = [3, event[type], event[key], event[value]];
      } else {
         >@seqOutput = [4, event[type], event[key], event[value]];
      }
   }

   This will make events with values above 64 go to channel 3, while the
rest go to channel 4. Like C/C++, the else clause is optional. Jacktube
provides the <, <=, ==, >=, > and != operators for use in if statements.

   Comments in the rule file start with "#", continue to the next newline
and are accepted everywhere.


Disclaimer
==========

   This program is provided as is, with no warranty whatsoever.
Use the program at your own risk. The authors are not responsible for
the malfunction of this program, nor any of its consequences.

