Best Encoder Library for DAW?

Does anyone have any thoughts as to what would be the best Encoder library to use for a MIDI DAW Controller?

Interrupts aren't an issue as I have a Due, so I can attach as many as I wish, on all pins if needed.

I have a mechanical encoder with 20 detents like the KY-040.

I appreciate that the code will only work as good as the product 'in this case a cheap encoder', but;

I just wondered what people thoughts would be?

Dizzwold.

For my MIDI Controller library, I use the PJRC Encoder library, and it works just fine. Haven't tried it on the Due though, (only on an Uno, a Leonardo and a Teensy) but it should work.

Pieter

Hi Pieter P,

So correct me if I'm wrong, I'm still a novice, but;

I could use your Encoder Example, and could change 'include MIDI_controller.h', with 'include RotaryEncoder.h', and I should be good to go?

Dizzwold.

No, that won't work.
Just use the example. If you have the necessary dependencies installed (see ReadMe), the Encoder example should work without modifying anything (apart from pin numbers).

The MIDI Controller library will automatically include RotaryEncoder.h for you.

Pieter

(see ReadMe)?

Is that in the Instructable step 13, As I don't see anyting else?

Dizzwold.

No, the Instructable is outdated. I mean the ReadMe on GitHub.

And the updated library documentation can be found on the GitHub Wiki.

Pieter

For anyone building a MIDI controller, the above is a must!

It also includes the MIDIUSB library, if your board supports a native USB.

I have however stumbled on a slight issue regarding using encoders with Arturia's Analog Lab VST via GarageBand.

I've read the ReadMe and played with the sketch many times, but the best i can get the encoders and the activated Analog Lab controls is;

1 click/detent C/W = 1 increment increase.
1 click CC/W = 1 increment decrease, next click CC/W = another 2 incrment decrease, next click CC/W = another 1 increment decrease.

So C/W works, but CC/W is 1,2,1,2,1,2 and so on.

I did find this regarding Arturia's MiDI controller, which may have some bearing on this issue;

Technical stuff for those who want to know more
RELATIVE MODE

Relative mode means that the encoders send MIDI messages that can increment or decrement a parameter without
there being jumps in the values. This allows for smooth operation and allows for greater interaction in applications that
support this type of MIDI data. Example:
If the encoders are set to RELATIVE 1 (using the free MIDI CONTROL CENTER software), the encoders will send a stream of
MIDI messages with data values of 65-67 when turned clockwise and will send a string of MIDI message 63-61 when turned
counter clockwise. The faster you turn the encoder, the higher or lower the data value. Relative 2 and Relative 3 modes
are similar in operation but send different values.

/*
This is an example of the "RotaryEncoder" class of the MIDI_controller library. 
Connect the A and B pins of the encoder to 2 interrupt pins (2 and 3). It's recommended to use 100nF capacitors between the A and B pins and ground.
Connect the common (C) pin to the ground. Pull-up resistors are not necessary, since the internal ones will be used.
Map the control change message 0x14 to the right control in your DJ or DAW software, and select 'relative' instead of 'absolute'.

If you are using a jog wheel, use JOG, if you are using a normal encoder (for normal controls like EQ or volume etc.) use NORMAL_ENCODER.
If you have strange results in your software, try another relative mode: ADD_64, SIGN_BIT or POS1_NEG127.
If the control works, but it goes in the wrong direction, swap the pins A and B of the encoder (physically, or when creating the 
RotaryEncoder member).

If you are using a Teensy, make sure you have the USB type set to MIDI.
If you are using an Arduino Uno or Mega, use the HIDUINO firmware for the ATmega16U2.


Written by tttapa, 21/08/2015
https://github.com/tttapa/MIDI_controller
*/

#include <MIDI_controller.h>

const static byte Channel = 1;
const static byte Controller1 = 0x14;
const static byte Controller2 = 0x15;

//________________________________________________________________________________________________________________________________

RotaryEncoder enc1(5,6,Controller1,Channel,1,JOG,ADD_64); // Create a new instance of the class 'RotaryEncoder', called 'enc', on pin 2 and 3, controller number 0x14, on channel1, no change in speed (speed is multiplied by 1), it's used as a Jog wheel, and the mode is set to POS1_NEG127.
RotaryEncoder enc2(7,8,Controller2,Channel,1,JOG,ADD_64);

//________________________________________________________________________________________________________________________________

void setup(){
  USBMidiController.blink(13);  // flash the LED on pin 13 on every message
  USBMidiController.setDelay(15);  // wait 15 ms after each message not to flood the connection
  delay(1000); // Wait a second...
}

//________________________________________________________________________________________________________________________________

void loop(){
  enc1.refresh();
  enc2.refresh();
}

Can anyone offer any thoughts so 1 click/detent = 1 increment + & -?

Dizzwold.

Normal encoders send 4 pulses per physical click. So you should use the NORMAL_ENCODER constant instead of JOG.

ADD_64 should be correct: +1 + 64 = 65, according to the quote you posted, this should increment the position, and -1 + 64 = 63, so it will decrement.

You could write a small test program for the Arduino, to test what kind of effect different numbers have. You could also use MIDI debugging/monitoring software on your computer.

It might be easier to write your own program for one encoder, to test things, instead of using the library. When you have figured out what commands you need, you can update the library source files if necessary, and use it for your final program.

Pieter

Hi PieterP,

For some reason 'NORMAL_ENCODER,ADD_64' = 11-14 C/W clicks for 1 increment increse, yet 1 CC/W click for 1 increment decrease.

I agree with your logic in the above post, but for whatever reason this is what it does.

Using an 'sp' of 2, '2,JOG,ADD_64', is the best I've got it.

Dizzwold.

Just find a Mac program that can send MIDI events to a virtual port, and connect that virtual MIDI port to Gb/VST.
Then try sending data, and see what happens.
You need to send B0 14 vv (in HEX, where vv is the value, if you want to send 63, for example, vv would be 3F hex).

I can't recommend any software for Mac, but I'm sure it exists.

Pieter

Hi PieterP,

I'll have look around for some snooping software.

Thank you for your input and time.

Dizzwold.

HI PieterP,

I found some software called SNOIZE.

I'm not sure if this provides the info you speak of, Sceen Shot attached.

C/W is giving a reading of 64, CC/W a reading of 62.

From the Analog Lab info quoted before, I think the VST is looking for a reading of 65-67 on C/W, but we're only giving it 64. Is this the problem?

Dizzwold.

That seems to be a bug in my library: the mode is called ADD_64 but it adds 63, sorry about that.
It's should be fixed now.

Pieter