Wednesday, January 23, 2019

Hacking the Ditto looper for MIDI control

I have long wished for a hardware looper that would allow me to record two loops of different lengths at once from the same source. It shouldn't come as a surprise that looking over the manuals of all available multiloop loopers reveals that no current looper hardware allows this. A software implementation would be trivial, but I'm fairly committed to my pedalboard at this point in the story.

Therefor, I've been considering a way of hacking existing hardware to implement this feature. I settled on the Ditto looper for this experiment because I would need two identical loopers and I already have one Ditto, which reduced my project cost.

My strategy involved two parts: I would first hack the Ditto to gain CV control over its footswitch and then code a microprocessor to translate MIDI commands into appropriate voltages to control the looper.

Ditto CV Mod

The first step was rather straightfoward. After considering a few options, I decieded to replace the footswitch with a mini-jack soldered to the LED side of an opto-isolator. The transitor side of the opto-isolator was soldered directly to the ground and to the appropriate pin of the tactswitch on the Ditto PCB. Sending 5V to the mini-jack makes the pedal respond exactly as it would if its footswitch were pressed.

This modification made for very interesting interaction with my modular synthesizer.

MIDI to CV Conversion

The second part of this project involved converting MIDI signals to CV to control two Ditto loopers. For this, I opted to use an Arduino Pro Mini, because they are inexpensive (~ 2$), small and so useful that I keep a few on hand at all times. Receiving and reacting to MIDI signal with an Arduino is rather straightforward and the information is readily available online (for instance here). A trickier aspect of this implementation is that two Arduino output pins need to be set at the exact same time. Using digitalWrite() in the usual way would introduce latency of a few microseconds between the two loopers. 

To resolve this problem, I had to become familiar with the concept of port manipulation:
Port registers allow for lower-level and faster manipulation of the i/o pins of the microcontroller on an Arduino board. The chips used on the Arduino board (the ATmega8 and ATmega168) have three ports:
  • B (digital pin 8 to 13)
  • C (analog input pins) 
  • D (digital pins 0 to 7)
Each port is controlled by three registers, which are also defined variables in the arduino language. The DDR register, determines whether the pin is an INPUT or OUTPUT. The PORT register controls whether the pin is HIGH or LOW, and the PIN register reads the state of INPUT pins set to input with pinMode(). 
For instance, assigning the binary number 00000011 to the variable PORTB will set pins 8 and 9 high (5 volts) at the exact same time. I decided to use MIDI CC commands to control the loopers with a bit of logic. Have a look at the truth table for exclusive or (XOR):

| x | y | x XOR y |
| T | T |    F    |
| T | F |    T    |
| F | T |    T    |
| F | F |    F    |

The operator returns TRUE if one and only if one of its operands is TRUE. This is a lot more useful than might first appear, since we can use it to toggle a bit on and off without keeping track of its current state. For example, if bit x is on (equals 1), assigning it the result of x XOR 1 will turn it off (equals 0). Repeating this operation will toggle the bit back on.

Returning to our MIDI CC, I control my loopers according to this scheme:
  • MIDI CC value of 1 controls the first looper
  • MIDI CC value of 2 controls the second looper
  • MIDI CC value of 3 controls both loopers
Converting this values to binary should make things rather clear:
  • 1 = 00000001
  • 2 = 00000010
  • 3 = 00000011
With the loopers connected to pin 8 and 9, all we need to do is assign to PORTB the result of a XOR operation (^ in the Arduino language) between itself and the received CC value:

PORTB = PORTB ^ ccValue
This worked like a charm, but I also wanted to sync execution of these commands to a MIDI clock. I solved this problem by pushing the received MIDI CC values into a FIFO buffer and counting the MIDI clock ticks to a certain number before popping values and sending them to PORTB as described above. The number of ticks to count depends on the note value to sync to. For instance, as there are 24 ticks per beat, to sync to sixteenth notes you need to count 6 ticks between function calls.

Possible next-steps

While this approach works and does bring about the desired effect (see video below), the Ditto looper remains a rather simple instrument. Successfully controlling a looper with MIDI messages converted to control voltages does suggest that it would be worthwhile to explore current offerings of eurorack loopers and delays.

No comments:

Post a Comment