Author Topic: DIY MIDI footswitch controller  (Read 716 times)

swisher

DIY MIDI footswitch controller
« on: November 24, 2019, 03:21:58 PM »
Hi!
I'm working on 'custom' footswitch to control my whole DIY rig. I stuck on MIDI part which I will use to control G-Major. I write whole program in C. Could anyone tell me how sending part should look (commands and order)? I mean:

1. Note on/off
2. CC
3. channel

or something different?

Thanks in advance for help!

ElectricDruid

Re: DIY MIDI footswitch controller
« Reply #1 on: November 24, 2019, 06:50:13 PM »
This is a pretty good explanation of the format of MIDI messages:

https://www.songstuff.com/recording/article/midi_message_format/

The basics are that you send one status byte, followed by either one or two data bytes (depending on the message).

There are a couple of exceptions: (1) the MIDI "system realtime" messages are a single byte and can appear anywhere, and (2) "running status" can be used to reduce the number of bytes sent when sending large numbers of notes (basically, if the status byte you're about to send is the same as the last one you sent, you don't have to bother. The receiving device will assume the status).

hope that helps,
Tom

swisher

Re: DIY MIDI footswitch controller
« Reply #2 on: November 25, 2019, 02:35:45 PM »
Thanks for help!
It helps a lot but I can't control G-Major thru midi still. "MIDI-IN" is blinking when I push the button but "learn" mode don't catch anything. Commands should be bin, hex or dec values?

pruttelherrie

Re: DIY MIDI footswitch controller
« Reply #3 on: November 25, 2019, 03:47:33 PM »
Are you sending Program Changes (PC) or Control Changes (CC) ? G-Major's "Learn" mode only reacts to Control Change values. Check the manual, page 22:
https://toneprints.com/media/666860/tcelectronic-gmajor-sw-1-27-_manual-english.pdf

To send a program change, it's enough to send just 0xCn 0xPP where c is the channel number and PP is the program to switch to.

The G-Major has a cool thing where you can configure it to send the tuner data back to the pedal (through a second cable). Then during a gig you don't have to look at the rack, just press Tune on your pedal and look at the pedal. A couple of years ago I reverse engineered the protocol, it's SysEx messages as follows:

F0 00 20 1F 00 48 70 NN XX F7

Where NN is the note: C=0, C#=1, etc. and XX is the tuning, from 10 - 17 - 1F. 
(1)7 is "in tune", lower and higher tells how much out of tune. 0 is most flat and f is most sharp: 0 1 2 3 4 5 6 7 8 9 a b c d e f
             
For that you'll have to build a MIDI-in on your pedal, though.

ElectricDruid

Re: DIY MIDI footswitch controller
« Reply #4 on: November 25, 2019, 06:07:21 PM »
Commands should be bin, hex or dec values?

MIDI is mostly quoted in hex (like pruttelherrie just did) but it doesn't really mae any odds, since they're all the same thing really. What MIDI *sends* and what is *received* is "a byte", but whether that byte is to be interpreted in binary, hex or decimal really depends on what's convenient for the context.

So what's the context? What are you using to send bytes to this G-Major, and do you know that it sends MIDI data correctly?

I struggled for ages with MIDI send until I got a MIDI monitor application on my computer so I could see what I was sending. It turned out it wasn't at all what I thought I was sending. I'd got some setting wrong in the UART used for sending MIDI bytes, and things were getting scrambled. Once I fixed that, everything sprang to life.

swisher

Re: DIY MIDI footswitch controller
« Reply #5 on: November 26, 2019, 04:57:54 PM »
Thanks a lot!  :icon_eek:

Finally I have some reactions in G-major but I think there is a problem with soft uart. When I send CC code (0xB1, 0x08, 0x7F) I get address=11, CC=55 and "MOD (055)" with first press and "MOD (056)" with next press (it's toggling - 055/056). If I use PC code (0xC1, 0x08) G-major doesn't receive MIDI signal.

EDIT:
I run footswitch code thru Proteus and in terminal I reiceive 0xFD, 0xF5, 0xFB instead of 0xB1, 0x08, 0x7F
« Last Edit: November 26, 2019, 06:12:44 PM by swisher »

anotherjim

Re: DIY MIDI footswitch controller
« Reply #6 on: November 27, 2019, 01:37:24 PM »
Is your midi transmission inverted by any chance?
I am restrained by law from answering any thread that Antonius is currently answering.

He is Spartacus!

ElectricDruid

Re: DIY MIDI footswitch controller
« Reply #7 on: November 27, 2019, 01:43:57 PM »
Is your midi transmission inverted by any chance?

That was my first thought too.

Sounds like you're nearly there though - keep fiddling with it and you'll get it. And as soon as you've done it once, you've got known-good code you can use for the future.

swisher

Re: DIY MIDI footswitch controller
« Reply #8 on: November 27, 2019, 06:14:18 PM »
I cleaned up my code a little and there is a progress. I can send simple values but there is always "3" before any number. When I'm sending "1" or "0x01" I get in terminal "31", if it's "127" I get "31 32 37". There is a mistake somewhere in code but I can't find it. Anyway, thanks a loooot for help!
« Last Edit: November 27, 2019, 06:44:21 PM by swisher »

Digital Larry

Re: DIY MIDI footswitch controller
« Reply #9 on: November 28, 2019, 12:53:03 AM »
30 hex is ASCII code for 0

https://www.ascii-code.com/
Digital Larry
DSP tinkerer and former transistor twister

potul

Re: DIY MIDI footswitch controller
« Reply #10 on: November 28, 2019, 09:20:52 AM »
On the other side, I have never been able to simulate in Proteus correctly so that I can see in the terminal the MIDI data transferred....

What I did some time ago to be able to debug midi in Proteus, was creating a virtual serial port in the PC connected to Proteus serial output, and then use a serial-to-midi software (like Hariless midi-serial bridge) and a MIDI virtual cable.....
I know this sounds complex, but once it's configured, you can use MIDOX or similar to monitor


swisher

Re: DIY MIDI footswitch controller
« Reply #11 on: November 28, 2019, 12:01:16 PM »
I'm testing uart with lower speed (9600) - I can't set 31250 baud in Proteus.

potul: Maybe I'll try this ;)
« Last Edit: November 28, 2019, 03:21:59 PM by swisher »

pruttelherrie

Re: DIY MIDI footswitch controller
« Reply #12 on: November 29, 2019, 06:09:17 PM »
30 hex is ASCII code for 0

https://www.ascii-code.com/
I think Larry is on to something:

I can send simple values but there is always "3" before any number. (snip) if it's "127" I get "31 32 37".
It looks like you're not sending a byte with value 127, but the 3 characters that make up "127".

Can you post the snippet of code where you actually send values to the serial port?


ElectricDruid

Re: DIY MIDI footswitch controller
« Reply #13 on: November 29, 2019, 06:52:56 PM »
It looks like you're not sending a byte with value 127, but the 3 characters that make up "127".

Yeah, well spotted! 31, 32, 37 makes sense like that. The compiler is treating it like a string not a byte.

swisher

Re: DIY MIDI footswitch controller
« Reply #14 on: November 30, 2019, 09:30:21 AM »
Right, that's what i found in ASCII table.
Two functions for sending:
Code: [Select]
C file:
void suart_puts( char * str ) {
while( *str ) sputchar( *str++ );
}

void suart_putint( int val ) {
char buf[9];
itoa( val, buf, 10 );
suart_puts( buf );
}

H file:
void sputchar( char zn );
void suart_puts( char * str );
void suart_putint( int val );

I've got assembler file also (soft uart). I don't understand anything from assembler so I didn't change anything.

pruttelherrie

Re: DIY MIDI footswitch controller
« Reply #15 on: November 30, 2019, 11:38:46 AM »
Ok, instead of suart_putint(value); use sputchar(value); and make sure value is a byte, not an int. (Note: 'char' is also a byte!)

sputchar(192);
sputchar(6);

(for example) should be a Program Change to 6.

Of course, sputchar(0xC0); sputchar(0x06); should be the same.
« Last Edit: November 30, 2019, 11:40:47 AM by pruttelherrie »

swisher

Re: DIY MIDI footswitch controller
« Reply #16 on: December 01, 2019, 02:20:39 PM »
Damn... it works!  :icon_surprised: Thanks a lot! Now I can test it with G-major  ::)

potul

Re: DIY MIDI footswitch controller
« Reply #17 on: December 02, 2019, 08:38:52 AM »
I'm testing uart with lower speed (9600) - I can't set 31250 baud in Proteus.

potul: Maybe I'll try this ;)

Yep,.. I faced this issue as well. That's one of the reasons I used serial-to-MIDI conversion.

Glad to see you have it working now.

potul

Re: DIY MIDI footswitch controller
« Reply #18 on: December 02, 2019, 09:04:45 AM »
on the other hand, what kind of microcontroller are you using for the project?

swisher

Re: DIY MIDI footswitch controller
« Reply #19 on: December 02, 2019, 02:39:45 PM »
For footswitch controller I'm using Atmega328. I didn't know anything about MIDI so I didn't know it works through UART. If I will know it I will use Atmega164 probably.