Wednesday, December 14, 2011

PRO DSP1000P automation with Hydrogen PART 2

The original post can be found here, but to recap :

The goal : control a hardware FX unit with Hydrogen
Why : to be able to select a specific FX per song (or part of the song)
How : using Midi + minimal tools



After some googling and great help from the Linux Audio Developer mailing list (thanks Harry, Jeremy, Clemens, Frank, Olivier, Adrian) my FX unit now switches to a specific preset whenever i jump to the next/previous song in Hydrogen !


Initially i wanted to be able to change the FX settings in the middle of a song (eg reverb on the verse  / delay on the chorus) but that is currently not possible since Hydrogen can only send Midi note messages.  In a future version of Hydrogen this might be possible, but not now.

What do we need ?
1) A way to generate Midi messages
2) Find out what Midi data we need to send to the FX unit
3) A way to trigger these messages from within Hydrogen.


1) generate MIDI messages
For generating the midi messages there are several options, but i chose amidi because it's as simple as it gets : to send a midi message just type amidi -p hw:1,0,0 -S '1C 10' in a terminal window.
Where -p hw:1,0,0 defines what midi port to use and  -S '1C 10' means 'send hex data 1C 10 to that port'.


Note : You can use amidi -l to find out what Midi ports are available on your system (eg hw:1,0,0 )

For this setup i am using this cheapo USB midi interface which works great :
Initially i started testing with the MIDI interface on my Saffire LE audio interface, but since that is a firewire interface the MIDI ports are listed under MIDI iso ALSA (in QjackCtl) so they are not directly available to amidi.  That complicates things a bit, but that's another story.




2) what data ?
To know exactly what needs to be sent to the FX unit to change one of its parameters (in my case the FX preset) you can read the manual of the unit, or you can let the unit 'tell' you what you need to know.

Now i'm not sure if this will actually work for any FX unit, but this is what worked for me :
 - configure the FX unit so 'send MIDI' is enabled
 - connect the FX unit to the MIDI interface
 - create a virtual midi port by executing amidi -p virtual -d in a terminal window
 - connect the MIDI input of your MIDI interface to this virtual port (via QjackCtl)

Once all this is done the terminal window should output all midi data that is received from the FX unit, so as soon as you press a button or turn a knob on the FX unit the corresponding midi value is displayed in the terminal window.  Sure beats reading the manual  ;-)

So now we know what to send + how to send it, lets put all this into a simple script.  The script below simply switches the FX unit to whatever value you feed the script :  FX.sh 1  will select preset 1,  FX.sh 20 will select preset 20 ...

FX.sh
#! /bin/bash
DecValue=$1
# decrement input value by 1 since midi program value is zero-based
let DecValue--
# convert input to hex
HexValue=$(printf '%x\n' $DecValue)
# generate the complete midi data string (C1=the controller id)
MidiValue="C1 $HexValue"
# send the midi data to hw:1,0,0 (depends on your hardware)
amidi -p hw:1,0,0 -S $MidiValue 



3) Link to Hydrogen
As i mentioned before Hydrogen does not (yet) have the ability to send anything else than MIDI note messages, luckily there is another option to trigger the script : via the playlist.
When you create or open a playlist in Hydrogen (Tools - Playlist editor) you can link a script to each song in the playlist.  This script is executed when you jump to that song (by pressing F5/F6).

To add a script to a song : select the song, goto 'Scripts - Add Script to selected song' and select your script. Finally tick the 'exec Script' box and save the playlist.


Bummer.  Hydrogen does not allow you to add an argument (eg FX.sh 1).  I tried editing the playlist file and adding the argument there but that does not work either  :-(

Ah well, easily fixed by creating dedicated scripts for each preset, but still it would have been nice.
So lets copy the FX.sh script 3 times and rename the copies to FX_4.sh,  FX_10.sh and FX_22.sh (4, 10 and 22 are the presets i will be using).  Now edit those files and change DecValue=$1 to DecValue=4, DecValue=10 and DecValue=22 respectively.


Note : make sure that all scripts are error-free, have the .sh extension and are executable because Hydrogen will not tell you if something goes wrong with the execution of a script.

In the playlist editor we can now add the scripts :


Hitting F5/F6 to jump back and forward in the playlist now switches the FX unit to the correct preset :-)


Note : Jack midi driver may not be set to RAW because this means that Jack has exclusive access to the Midi ports and thus amidi will not be able to access the Midi port.


But is is reliable ?
This is the first time i am using amidi and since i will be using it for live performances it needs to be rock-solid.  To find out just how solid it is i used this oneliner :


while [ 1 ]; do ./FX_4.sh; ./FX_10.sh; ./FX_22.sh; done

This line simply hammers the FX unit with 'preset-change' Midi messages and after letting this run for about an hour the FX unit was still obeying it's master without any protest.
Power cycling the FX unit or disconnecting the Midi or USB stopped it from working for a moment, but the preset-switching continued as soon as the unit was up and the connections restored.

So yes, it's reliable !

No comments:

Post a Comment