Traktor track name / time to LCD via MIDI! ...using Denon LCD support & Arduino

Some great findings guys, Iv been smiling at the idea of a twin processor project all weekend!

Just one thing to add further to DjNecro’s findings with the MIDI OUT stuff…

‘MIDI OUT > Output > Track End Warning’ outputs CC every time you load a new track in whether it be right click and load, or drag and drop, the only problem is it also outputs the same message when the play point crosses the ‘30 seconds left’ boundary, if you skip the play point before and after the 30 second left point this message is outputted whether the track is playing or not. I was thinking the LCD MIDI could be checked for new data if this message was received and the track was not playing, however if someone was to skip before and after the 30 second point with the track paused it would probably screw up the reading. grrr!! With what DjNecro said and what I have found there are several options that come close, but with a single quirk making it a pain!!

I was thinking about having something like…

A> TRACK NAME
TRACK NAME <B

…so I agree the 12 seg thing wont be a prob

Agreed agreed agreed! Anoying isnt it! :stuck_out_tongue:

Im gonna have a think a bit more about the final spec of my board design, defo got me thinking what has been said on here which is great, and part the reason I got involved on here so thanks again guys for giving me inspiration!

Here’s what I came up with… It will decode the track title and artist name, as well as the minute, second, track position (in percent). It also calculates the total track length every 20 seconds. It’s not 100% accurate, but it’s the best we have :slight_smile:

The example video shows it rotating between the artist/track and a two line time display with simple bar graph. The delay between changes is currently 15 seconds.

Note: Just want to draw attention to the fact that the decoding functions are completely independent of the MIDI code and the lcd code. While they are of course designed to decode MIDI, how you get the MIDI messages to the functions is up to you :smiley:

#include <WProgram.h>
#include <LiquidCrystal.h>
#include <Midi.h>

struct DENON_SEGMENT {
boolean valid;
byte seg;
byte col;
byte val;
};

struct DENON_TIME {
boolean valid;
byte minute;
byte sec;
byte pos;
byte totMin;
byte totSec;

};

LiquidCrystal lcd(8, 11, 9, 4, 5, 6, 7); // initialize the library with the numbers of the interface pins

class MyMidi : public Midi {
public:

MyMidi(HardwareSerial &s) : Midi(s) {}

void handleControlChange(unsigned int channel, unsigned int controller, unsigned int value) {
if (channel == 1 || channel == 2) {
DENON_SEGMENT segData = checkForSegmentData(controller, value);
DENON_TIME timeData = checkForTimeData(controller, value);
static unsigned long curTime, prevTime = 0;
static boolean flip = false;

curTime = millis();
if (curTime - prevTime > 15000) {
prevTime = curTime;
flip = !flip;
lcd.clear();
}

if (segData.valid == true && flip == false) track_name(segData.seg, segData.col+2, segData.val); // col+2 to center it on my 2x16 screen (the denon only has a 2x12)
if (timeData.valid == true && flip == true) updateTime(timeData.minute, timeData.sec, timeData.pos, timeData.totMin, timeData.totSec);
}
}
};

MyMidi midi(Serial);

void setup() {
lcd.begin(2, 16);
digitalWrite(14, HIGH);
midi.begin(0);
}

void loop() {
midi.poll();
}

struct DENON_TIME checkForTimeData(byte controller, byte value) {
static byte minute, second, pos, totMin, totSec, lastSecond;
static float tot = 0;

if (controller >= 0x40 && controller <= 0x49) {
if (controller == 0x42) {
minute = value;
} else if (controller == 0x43) {
second = value;
} else if (controller == 0x48) {
pos = value;
if (second != lastSecond) {
if (second % 20 == 0) {
tot = ((minute*60)+second) / ((float)pos / 100);
totMin = tot/60;
totSec = (int)tot%60;
}
lastSecond = second;
return (DENON_TIME){true, minute, second, pos, totMin, totSec};
}
}
}
return (DENON_TIME){false,0,0,0};
}

struct DENON_SEGMENT checkForSegmentData(byte controller, byte value) {
static byte seg1MSB, seg2MSB = 0;
if ((controller >= 0x01 && controller <= 0x05) || (controller >= 0x07 && controller <= 0x0D)) { // segment 1 MSB
seg1MSB = value;
} else if (controller >= 0x0E && controller <= 0x19) { // segment 2 MSB
seg2MSB = value;
} else if ((controller >= 0x21 && controller <= 0x25) || (controller >= 0x27 && controller <= 0x2D)) { // segment 1 LSB
return (DENON_SEGMENT){true, 0, getColumn(controller, 1), ((seg1MSB<<4) + value)}; // return completed packet
} else if (controller >= 0x2E && controller <= 0x39) { // segment 2 LSB
return (DENON_SEGMENT){true, 1, getColumn(controller, 2), ((seg2MSB<<4) + value)}; // return completed packet
}
return (DENON_SEGMENT){false,0,0,0}; // incomplete packet
}

// parameters: cc- controller number, seg- segment number
// returns: column number (zero indexed) or 255 if invalid segment
byte getColumn(byte cc, byte seg) {
byte col=255;
if (seg == 1) {
col = cc - 33; // convert into segment number (column)
if (col >= 6) col--; // work around the fact that Denon skipped 0x06 for segment 1-6 (they got segment 2 correct)
} else if (seg == 2) {
col = cc - 46; // convert into segment number (column)
}
return col;
}

void track_name(byte lcd_row, byte lcd_col, byte lcd_data){
lcd.setCursor(lcd_col, lcd_row);
lcd.print(lcd_data);
}

void updateTime(byte minute, byte sec, byte pos, byte totMin, byte totSec) {
char one[17], two[17] = {};

strcat(two, "|");
for (byte i=1;i<=14;i++) {
if (i <= map(pos, 0, 100, 0, 14)) strcat(two,"#");
else strcat(two, " ");
}
strcat(two, "|");

sprintf(one, "R:%02i:%02i  T:%02i:%02i", minute, sec, totMin, totSec);
lcd.setCursor(0, 0);
lcd.print(one);
lcd.setCursor(0, 1);
lcd.print(two);
}

Good work man :slight_smile:

The percentage track position gave me an idea actually… what about mounting a softpot potentiometer just above or below the LCD? Like this:

http://www.sparkfun.com/products/8607

If the softpot is the same length as the LCD display then it could be used to interact with the LCD in interesting ways. For example, as a touch pad to quickly scroll through the track. When the softpot is touched, the LCD changes mode, displaying the current track position (like this perhaps: [0--------||-----99]. It could also be used as a filter, eq or effects control parameter (all with visual queues from the LCD display).

Only problem is that the softpots are a bit pricey :disappointed:

Nice! I like the way you managed to calculate the remaining time! :slight_smile:

I have just been doing some reading about the MIDIStreaming subclass with intentions to hopefully develop my own USB connectivity in the future and have discovered some interesting stuff…

It turns out that USB-MIDI never emulates the serial MIDI baud rate of 31250bps. The basic principal is something like this… the MIDI bytes are encapsulated with an additional USB header byte to make a 32-bit packet of data which is transferred over USB at the USB connection speed and passed to the USB input of the MCU on the other end (MCU with USB input necessary). The MIDI bytes can then be manipulated as you choose within the code.

So even by the USB 1.1 standard at 12Mb, USB-MIDI information is being transmitted at just over 50 times the speed of standard serial MIDI!

When Denon setup their hardware to accept MIDI to control the LCD, as we discussed before it seems a bit stupid to have to receive all that data constantly to display information on the screen. It would seem better to send the track name and artist over MIDI with a start and end marker, as DjNecro mentioned in an earlier post, which could then be loaded in to the Denon and the Denon could handle the display including the scrolling.

When you think about it though, having the LCD set up in the way which they have done it has a plus side too, the host software can have complete control over what is displayed on the screen rather than be bounded by the Denon displaying info in a certain way. In terms of 31,250bps, it takes quite a lot of bandwidth to deliver this information but when we are talking USB speed its no prob at all!

Im not sure if this poses a problem, DjNecro your screen seems to be running nice and smooth with a standard MIDI connector, but this thought on USB does kind of answer why the Denon LCD MIDI stuff works in the way they have set it up!

:slight_smile:

Siytek - this was the site I was talking about for low run PCB manufacturing:

It costs $5 per square inch (2 layer, 3 pcbs per order included in price)

You reckon you could get the Arduino(s) talking to Traktor via midi over usb? That would be some achievement because afaik, this is notoriously difficult (especially with the older 1280 atmel’s). Good luck!

Oh and I might hit you up on Skype this week to discuss an idea I had regarding all of this stuff :slight_smile:

Defo good idea MiL0 :slight_smile: I was thinking about adding a little header to the board (next to the LCD header) which could accept some kind of menu key / pot inputs, the user could then choose their own pot / buttons for menu control :slight_smile:

Mind if I get OT for a minute? Can any of you smart people help me with this?

That’s possible using the Autohotkey script I’m writing (thanks to djnecro and siytek for working out all the tricky bits). So far, I’ve got a Windows exe that acts sits between Traktor and your controller and reads the artist/track name (endlessly! see the ‘bugs’ above). This information could easily be written to a text file. Can I ask what you intend to do with this text afterwards? It might help me to customise the script to better suit you.

Two disadvantages:

  • It requires Windows (no AHK support on MacOSX)
  • It requires a virtual midi input, rather than being plug’n’play

LCD MIDI + MIDI Serial baud rate info

Just pondering a few numbers with regards to my last post about USB-MIDI and baud rates, I realise this may be basic stuff to some but thought I would post it here just incase it was beneficial to anyone. I have done a few calculations related to the amount of bandwidth the LCD MIDI setup might take from a serial MIDI data stream, here are my findings….

1 MIDI CC message = x3 bytes (status, data, data) = 24 bits per message.

The LCD characters need two MIDI CC messages so a total of 48 bits to be sent to display a character.

There are 12 characters displayed by the HC4500 so 12 * 48 = 576 bits needed to display the whole line.

Both track and artist are on a separate line so 576 * 2 = 1152 bits are needed to display two lines with track and artist.

The update of minutes within the track time requires one message = 24 bits

The update of seconds within the track time requires one message = 24 bits

The update of frames within the track time requires one message = 24 bits

so…. If during 1 second of time, everything on the display needs to be updated…

(im not sure how many times track and artist scroll along the line in a second, lets say six times for an extreme example)

1152 * 6 = 6912 bits to move track and artist within the given second
24 bits to change minutes
24 bits to change seconds
100 * 24 bits to change frames (as 100 frames count over in 1 second)

= 9360 bits are required maximum to update all information over the period of one second

9360 x 2 = 18,720 bits for both decks

18,720 / 31250 * 100 = 59.9% of the MIDI bandwidth taken up.

So to conclude, even with the maximum amount of messages being transmitted at any given time for both decks transmitting data for the LCD MIDI display, there is still almost half of the MIDI in bandwidth remaining, meaning 31,250bps standard serial MIDI should have no problem coping with the amount of data. I don’t think the display actually scrolls 6 times a second (if it scrolls twice in a second the bandwidth drops to 30%) and is Traktor really going to need 40% of the bandwidth to Transmit all other MIDI message which will probably consist of a few messages to switch a few LEDs on and off periodically! :slight_smile:

So, I have no idea what you guys are doing, cuz Im a noob to electronics, but I have seen something similar in this vid. Traktor is sending song names to dns1200 display. Don’t know how…

Hi steffanko

Basically what we have achieved is we have ‘hi-jacked’ the MIDI data Traktor sends out in order to get track names and artist names to appear on Denon (DN4500 compatible) decks so we can get this info on the displays of our own custom MIDI controllers. We use Arduino with MIDI capability to capture this information that is intended for the Denon, and display it on our own LCD screens :slight_smile:

Phewww Too much math :wink: I just checked my display and it moves 20 segments to the left every 8 seconds… (2.5 segments per second).

I’m not nearly as worried about the midi bandwidth as much as I’m worried about available cpu cycles… We only have 16mhz with the arduinos :disappointed: I’d love to get into the better and faster pic’s and even the maple processor which runs at a ‘blazing’ 72mhz… (http://leaflabs.com/devices/maple/)

..Mil0, what sort of ideas are you thinking about? I’ll pm you my skype :slight_smile:

Sweet! Had a look at that PCB manufacturing, looks pretty good. I have had a look at a few companies in China but that seems like an easier way to get a one off made or a small run.

I have not looked at the USB in great detail yet, its a future project though. I want to start with making a USB MIDI interface utilising the class compliant driver first. I have also been looking at the possibility of tweaking the descriptors within the FTDI to make it appear as a MIDI device, aliasing the baud rate seems possible too for 31250 but to fully understand this im going to have to learn what I would have to know to making something from scratch with an MCU anyway! It would be nice to be able to offer a USB-MIDI shield for Arduino that can offer the full benefit of USB-MIDI speeds, virtual cables and still leave the UART open so the Arduino could function as a USB to MIDI interface too.

Yeh defo up for some Skype at some point, keen to discuss ideas. Im hectic this week, still working on the live set every day and I got three gigs this week too so if not this week then defo next! :slight_smile:

Funny you should mention that, I got a news letter from cool components earlier and was looking at this…

http://www.coolcomponents.co.uk/catalog/product_info.php?products_id=685&utm_source=Newsletter+List&utm_campaign=24aae74616-Newsletter_April_2011&utm_medium=email

The Fez Panda II using a 72Mhz ARM processor. It made me wonder about stepping up to a higher performance chip.

I know its not a great leap in performance but I dont know why Arduino dont use 20Mhz clock speeds as the ATMega is capable!

Likely due to cost issues with regards to the 20meg crystal… Also, wouldn’t your timing be seriously altered if you ran the same sketch from an atmega running at 16meg on one running at 20?

I have had zero issues so far chaining three controllers together with the head controller receiving and passing through the signals from two different midi sources. Each one has at least 2 or 3 varying multiplexers (4051’s 21’s 595’s etc).

The only time I have encountered issues is when I try my first ever controller that has a hacked apart synaptics touchpad built into it and two rotary encoders. If I enable the touchpad (which uses the ps2 protocol) it causes the encoders to become a little jittery… I’m sure there’s a way (either in hardware or software) to work around it, but I haven’t really bothered taking it any further since I don’t really use the xypad that much right now…

My ideal controller will have one per deck, so I’m going to have to figure it out eventually :slight_smile:

I’ve seen that .net board.. but the first time i saw the “.NET” part, I kinda threw up in my mouth a little… :wink: I have a deep down hate of any and all msft products and use them as little as i can (heh, that’s coming from a IT admin managing a couple dozen ms servers :wink:)

Yeh I agree dude! microsoft sucks and I dont use anything made by them! :wink: I wouldn’t go with a .NET system, just liked the look of the hardware spec.

Glad to hear your not having probs with the MIDI. Although it seems like a bit of a mission to sort out the problem with the processing for the LCD, it would probably be worse if it was a MIDI speed issue though as the only resolution would be to design a system from the ground up and run USB-MIDI to get a higher speed.

Yeh I think you would defo encounter timing problems using a 20Mhz xtal. I believe you can recompile the Arduino bootloader to accept a 20Mhz xtal but you get some timing issues with things like delay(x); ..I was more wondering why Arduino didnt just write the bootloader and programming environment for 20Mhz in the first place. As you say cost could very well be the issue of cost.

Think I should have taken in to account the start and stop bits too. This makes each MIDI message 10-bit instead of 8, so a full MIDI message requires 30 bits, not 24 so the bandwidth required to change track, artist, minutes, seconds and frames over the period of 1 second is (note: based upon DjNecro’s estimation of about 2.5 movements per second, this calculation roughly estimates the LCD scrolling to happen about 3 times a second)…

12 chars for title * 60 bits (2 MIDI messages)
12 chars for artist * 60 bits (2 MIDI message)
= 1440 bits to display track and artist * (about) 3 movements a second = 4320 bits
Minutes = 30 bits
Seconds = 30 bits
100 frames per second * 30 = 3000 bits

= 7380 bits total * 2 decks
= 14,760 bits total

14,760 / 31250 * 100 = 47.23% MIDI bandwidth used

to save costs and get around the potential midi bandwidth issue, what about using a teensyduino as a dedicated LCD controller?

That’s what I would do… the teensy would handle the lcd’s and the LED’s.

After some further testing, I am finding issues with the standard MIDI baud rate. Although the bandwidth is sufficient to deliver the messages there is still quite a lot of it taken and a noticable delay in certain messages. There is a slight pause in the ‘frames’ counter when displaying track time, which I believe happens when the messages to move the LCD text are sent. The Denon HC4500 would be connected with USB-MIDI running at USB data transfer rate so this would not be a problem in the case of Traktor to Denon, however using the standard MIDI baud rate just doesnt seem quick enough. Even though all the messages get delivered, when you send constant MIDI data streams (such as MIDI clock, VU meter and frames) delays happen when additional messages (such as moving LCD text) are sent. The solution I believe would have to be a seperate processor for the LCD which coupled via USB-MIDI. This chip could receive the LCD data and display it, then pass and MIDI data not related to the LCD out of the USART at 31250 bps so would double up as an internal USB to MIDI interface for Traktor controller projects as well as the LCD controller.

Teensy seems like a good idea as it has a direct USB connection running at full speed and not a USB-to-serial FTDI type sollution which is limited to the slower USART speed, it would be a great board to start working with that has capability of utilizing the USB-MIDI class compliant driver plus its USART is free to use so it could function as the LCD controller and internal USB-MIDI interface at the same time, its just a shame its not open source, I would rather design my own host board from scratch.