midiecho


NAME

midiecho - Simulates tape-loop delay echo: on MIDI files, or on real-time MIDI


SYNOPSIS

 # on midi-files ( *.mid ) :
 midiecho -c 3 fn            # echo will be added to midi channel 3
 midiecho -c 3 -d 450,450,450 fn      # three echoes at 450 mS gaps
 midiecho -c 3 -d 450,450 -s 30 fn  # each echo is (MIDI) 30 softer
 midiecho -c 2 -d 450 -e 5 -s 30 fn # the echo appears on channel 5
 midiecho -c 3 -d 40 -e 4 -w 10 -s 0    # Automatic-Double-Tracking
 midiecho filename          #  defaults: midiecho -c 0 -d 300 -s 30
 muscript -midi f.txt | midiecho -c 1 -d 300 -s 25 -e 2 >f.mid

 # on real-time (raw) midi :
 $> xterm -g 80x16+1+1 -exec 'midiecho -i 32 -d 22 -c 3 -e 4' &
 $> midiecho -i 32:0 -o 128:0 -c 3 -d 450,400 -e 4,5
 ALSA client 129                midiecho pid=2157
 Input port 129:0 is connected from 32:0
 Ouput port 129:1 is connected to 128:0
 Echo is being applied to input channel 3
 Delay 450 ms, to Channel 4, Softer by 25
 Delay 400 ms, to Channel 5, Softer by 25
 _
 Up, n=New echo, q=Quit
 midiecho -c 3 -d 450,400 -e 3,3 -s 25,25


DESCRIPTION

Simulates a tape-delay echo on a particular MIDI-channel by issuing repeated note_on events with diminishing volume.   Since version 2.0, the -i and -o options allow midiecho to work on real-time (raw) midi inputs, as well as on midi files.

Midiecho sounds best if the -e option is used, to assign the echoes to different MIDI-channels; this avoids notes being restarted before they have finished.   If the -e option is not used, the echo note is played on the same channel as the original note, and in this mode midiecho works much better on transient sounds, e.g. banjo, or snare-drum.

Since version 4.5, the -E option specifies the list of CC controllers which will be echoed to the echo-channels. This is different from previous versions, in which the -E option did not work and was undocumented.

Since version 2.6, the delays are incremental (since the previous delay) not absolute (since the original note); this is a bug-fix, but it was a well-established bug.

Version 3.0 brings major changes, involving some loss of backward-compatibility. Since version 3.0:

Currently, echo can only be applied to one channel. At some time in the future this restriction may be removed. To make this possible, a more compact notation would be introduced to replace the -d, -e, -n, -p and -w options:
  midiecho -c 0 d300e1p0 d300e2p74
However, version 4.3 introduced the -N option, which allows more than one midiedit process to be started, with predictable ALSA-client names; these can then be connected up by aconnect in a script, which removes much of the need to run echoes on multiple channels within one midiecho process.


OPTIONS :   -c,   -d,   -e,   -E,   -n,   -p,   -w,   -s,   -i,   -o,   -N

-c 3

Echo will be added to midi Channel 3.   The channels are numbered from 0...15   If -c is not specified, the default channel is 0.   midiecho can only add echoes to one channel at once; the other channels pass through unaltered.

-d 350,300,250

The echo notes will be Delayed 350, 300 and 250 mS after the previous.   If -d is not specified, the default delay is just 300 mS

-e 4,5,4

The echoes are generated not on the original (-c) channel, but on the channels 4 then 5 then 4 again (in this example there are three echoes). This is a really useful option :-)
As one example usage, you might have set up your synth's channel 4 and 5 with the same patch (instrumental sound) as the original channel (e.g. 3), but panned to different places in the stereo image. This creates a very realistic echo-effect.
Another example usage could be to set up the echo-channels with a completely different sound, maybe something atmospheric or ethereal.
Another example usage could be to set up the echo-channels with a different patch, and use a 1ms delay, thus doubling the original channel with a different sound.
If the number of echo-channels (-e) is fewer than the number of delays in the -d list, then the last echo-channel is repeated as necessary.
By default, the controllers CCs 0,1,5,11,32,64,65,66,84 (Bankselect,Modulation,Portamento,Expression,Pedals) go through to the echo-channels. But if you want to control the echo-channels independently in these controllers, see the -E option . . .

-E 1,11,64,66

Only the controller-numbers specified here will get echoed into the echo-channels.
In this example, just Modulation, Pan, and the Pedals get echoed, so that the echo-channels in these controllers follow the the -c channel
-E needs a parameter, so if you want to block all CCs set it to some irrelevant controller, eg: -E 999

-n 38,40

Echo will be added only to midi notes 38 and 40. This option is mainly useful with General-MIDI channel 9, which represents a drumkit, with each note representing a different drum.

In this -c 9 -n 38,40 example, echoes would only be added to the Acoustic Snare and the Electric Snare sounds.

-p 74,93

The channels specifed by the -e option will be preset to use MIDI-Patches 74 and 93 (in this example).

-w 8

The echo will be changed by the pitch-Wheel up 8 cents (hundredths of a semi-tone). This is mainly useful in conjunction with the -e and -d options to produce the "Automatic-Double-Tracking" effect, e.g.
  midiecho -c 3 -d 40 -e 4 -w 10 -s 0
which assumes that the original channel 3 is panned over to one extreme, and the echo-channel 4 is set up with the same patch but panned over the other way. It then produces an "echo" just 40mS late and just 10 cents lower. Because the two sounds are in different speakers they don't beat with each other, and sound almost like two instruments playing in unison.

With larger parameters, it can be used to produce doubling at a large interval; e.g.   -d 2 -w 1200   causes the original voice to be doubled (with a delay of 2mS) at the octave (1200 cents).

-s 35,20

The first delayed note is 35 (MIDI) softer than the original, and the second is 20 softer still.   If the number of softenings (-e) is fewer than the number of delays in the -d list, then the last softening is repeated as necessary.   If an echo ends up with zero volume or less, then it is suppressed.   If -s is not specified, by default each delayed note is 30 softer than the previous.

-i 32:0   or  -i ProKeys

This option puts midiecho into raw-midi (or real-time, or midi-on-the-wire) mode, and takes the midi-data from the specified port.   The port is specified as an ALSA-port; you can check out the available ports with the command arecordmidi -l or aconnect -il.

Since Version 3.6, you may supply a comma-separated list of ports, e.g. -i 28,32
Since Version 4.4, if the ALSA port is specified as 0 then midiecho will start up in real-time mode but without connecting from anything; this is consistent with midichord usage.

-o 128:0   or  -o TiMidity

This option puts midiecho into raw-midi mode and sets the ouput-port to which the midi output will be sent.   You can check out the available ports with the command aplaymidi -l or aconnect -ol.
The default ouput-port (if only the -i option is present) is the environment variable $ALSA_OUTPUT_PORTS

Since Version 3.6, you may supply a comma-separated list of ports, e.g. -o Roland,128:1

-N my_echo_1

This option sets the ALSA Client-Name, to my_echo_1 in this example, that midiecho will adopt if the -i or -o option is used to put it into raw-midi mode,
This is useful if starting up midiecho (or especially multiple midiechos) from a script which will then need to connect them to other ALSA clients.
The default ALSA-name is midiecho pid=456 or whatever the pid is of the midiecho process.


EXAMPLES

As an example, note that this muscript file sets up some extra MIDI channels on the synth;
  channel 3 is patch 105, which is a banjo
  channel 4 is patch 105 pan 5, which is a banjo panned left
  channel 5 is patch 105 pan 95, which is a banjo panned right
  channel 6 is patch 91 pan 10, which is a Pad 4 (choir)
  channel 7 is patch 88 pan 90, which is a Pad 7 (halo), and
  channel 8 is patch 66 pan 35, which is a tenor sax

It was converted into midi by the command
muscript -midi t > t.mid     (or listen to t.mp3)

Then a couple of echoes on the same channel (3) were added with
midiecho -c 3 -d 250,200 -s 45 t.mid > t1.mid     (or listen to t1.mp3)

or on different channels with the same patch (banjo) but panned left and right with
midiecho -c 3 -d 250,200 -s 45 -e 4,5 t.mid > t2.mid     (or listen to t2.mp3)

or on channels with different, more ethereal, patches with
midiecho -c 3 -d 250,200 -s 45 -e 6,7 t.mid > t3.mid     (or listen to t3.mp3)

or on a channel with a saxophone patch and a one-millisecond delay, for a doubling effect, with
midiecho -c 3 -d 1 -s 5 -e 8 t.mid > t4.mid     (or listen to t4.mp3)


DOWNLOAD

The current version of midiecho is available by http at www.pjb.com.au/midi/free/midiecho.txt (rename it to midiecho, make it executable, and move it into your $PATH),
or as part of www.pjb.com.au/midi/free/midiscripts.tar.gz (unpack the tar archive somewhere in your $PATH).
If necessary, edit the first lines to reflect where perl is installed on your system.

You'll also need to install the MIDI-Perl module, and the MIDI::ALSA module.


CHANGES


4.5, 20160613, the -E option specifies which controllers get echoed
4.4, 20160326, -i 0 option doesn't connect from anything, conforming to midichord usage
4.3, 20140704, -N option to set the ALSA-Client name
4.2, 20140430, bug fix: don't sort the delay arguments !
4.1, 20120909, uses api_for_perl for file-mode; far simpler code, and -w works for big shifts like -1200
4.0, 20120110, in -w, store @pitch_delta by i_echo, not by channel
3.9, 20111116, option now works in midi-file mode
3.8, 20111103, uses the new MIDI-ALSA 1.11 to handle ALSA-ports by their names
3.7, 20111029, fix bug in -w %pitch_delta
3.6, 20111028, OutputPort and InputPort can be comma-separated lists
3.5, 20111028, controllers in DoEchoCC don't get echoed repeatedly to the same channel
3.4, 20111027, controllers in DoEchoCC get echoed correctly
3.3, 20110528, real-time w pitchWheel adjustments work from the UI
3.2, 20110527, -w > 100 handled with %pitch_delta{$cha}
3.1, 20110526, -w works, -p is Patch, -Q works properly
3.0, 20110520, MIDI::ALSA; kbd-UI in real-time mode
2.4, 20100420, bug fixed with real-time pitch-bend events
2.3, 20100325, real-time patch-changes do not get echoed
2.2, 20100324, real-time mode handles running-status; aconnect connections get cleaned up after Ctrl-C
2.1, 20100324, fixed bug: -p in real-time mode was a quarter-tone flat
2.0, 20100323, the -i and the -o options work on real-time raw midi, not just on .mid midi-files
1.9, 20071006, numerical sort of keys of %pending; start_time remembers $millisecs, not $unique_ms
1.8, 20070403, the -p option allows Automatic-Double-Tracking
1.5, 20060804, tracks overlapping note_ons in input,
1.4, 20060729, reads STDIN if no filename, for use in pipes
1.3, 20060728, first working version; -N is now the default, and -S introduced to handle stateless synths.


AUTHOR

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


CREDITS

Based on Sean Burke's MIDI CPAN module, and on Peter Billam's MIDI::ALSA CPAN module.


SEE ALSO

MIDI-Perl
MIDI::ALSA
www.pjb.com.au/muscript
www.pjb.com.au/midi/midichord.html
www.pjb.com.au/midi/midikbd.html
www.pjb.com.au/midi/bassline.html
www.pjb.com.au/midi/mididump.html
www.pjb.com.au/midi/midiedit.html
www.pjb.com.au/midi/midithru.html
www.pjb.com.au/midi/musicxml2mid.html
www.pjb.com.au/midi