Re: midish, ecasound and jack

From: Alexandre Ratchov <>
Date: Sat Nov 10 2012 - 15:43:53 CET
On Sat, Nov 10, 2012 at 12:00:30AM +0100, gorest wrote:
> hello,
> just subscribed to the list, after testing rapidly some
> synchronization between midish, ecasound and Jack. My goal is to
> have a small "command line" linux able to play audio and midi in
> synchro, with the ability to move within the song


You may be interested in aucat (at least to pick ideas), it's a
audio player/recorder/converter with mtc/mmc capabiliry, see

Currently it's part of OpenBSD but it's being ported to linux. Drop
me a mail if you're interested in the linux port.

> First, one feature i want to add to midish is using MIDI markers
> to move within the song. I looked at the midi parser code, and it
> easy to add parsing for these events. Now i have to look deeper
> in the code to see if it is feasible to use the 'g' proc to move
> in the markers list with : g verse2

Interesting; afaics the hardest part would be to decide what to do
with markers during copy & paste operations.

> Then, adding jack_transport sync is a must. As it's working
> nearly perfect with ecasound, i want to have it working with
> midish.

there's no jack support for midish yet; to add jack transport &
sync in midish, you may have to masquarade jack as a mmc/mtc
capable midi device.

Another option would be to write a program to gateway between
jack and alsa, such that:
 - jack cycles trigger sending of MTC clock ticks
 - MMC messages trigger calls to jack start/stop/relocate
 - possibly MIDI data is routed as-is between jack & alsa

iirc there's some work in this direction, but I don't know to which
extent the MTC aspect of the problem is solved. Search for
jackctlmmc and a2jmidid on the web as an entry point.

> That may be a challenge for me, but i'll get into it for sure,
> only the time needed to achieve this is unknown (My C programming
> skills are significative, but i'm not a highly skilled
> developer).
> So far, i've been able to synchronise midish and ecasound using
> this trick (somewhat different that the one from julien) :
> 1) midish is sending MMC/MTC synchro to its midi out device
> 2) Adour/Rosegarden/Hydrogen is receiving this synchro (play/stop)
> 3) Ardour/Rosegarden/Hydrogen is forwarding the synchro to JACK
> 4) JACK is sending the synchro (start/stop/position) to ecasound which is in slave mode

At some point you need the audio player to send MTC back to midish.
This is required because audio playback advances at the sound card
clock rate while midish uses the system clock rate and both rates
are slightly different and will cause drift sooner or later

To get proper synchronization, to probably need midish to be MMC
master and MTC slave. Eg of how this works.

1.  the users requests midish to start playback

2.  it broadcasts a MMC relocate & start message

3.  the audio player (MTC master) receives the start request,
    broadcasts a MTC full-frame message and starts

4.  midish receives the MTC full-frame message and prepares to

5.  midish receives the first MTC clock tick and starts

6.  the audio players sends periodic MTC clock ticks extracted
    from the audio card's clock

7.  midish receives MTC ticks and advances its playback pointer
    accordingly, thus following exactly the audio card clock,
    and staying in sync with the MTC master

8.  goto 6, until the user requests (in midish) playback to stop,
    midish sends a MMC stop request

9.  the audio player receives the MTC stop and stops, thus midish
    reveives no MTC any longer and stops as well

> The start/stop are working ok, but i wasn't able to have ardour
> (for example) follow the MTC position of midish. 

I don't think the will work well, either midish will drift or
Ardour will be forced to resample to compensate the drift (if it
supports that, i don't know).

> It plays, pause, the always continue, and the cursor doesn't move
> when i use a 'g 4' command in midish. Maybe i missed something ?

I use the following in my .midishrc (with openbsd device names,

dnew 4 "midithru/1" wo		# audio player
dnew 15 "snd/0" rw              # MTC source
dmtcrx 15

and I configure audio programs to be the slave on device 4 and to
be the MTC master on device 15.

> Just let me know if someone has already move toward the
> jack_transport integration into midish, so i'd have some work
> already prepared.

Julien may give better insight about this.

-- Alexandre
Received on Sat, 10 Nov 2012 15:43:53 +0100

This archive was generated by hypermail 2.1.8 : Wed Nov 08 2017 - 16:32:23 CET