Old 10-13-2018, 12:10 PM   #1
rothchild
Human being with feelings
 
Join Date: Oct 2007
Posts: 510
Default MIDI coding guidance, please?

Hi all,

I've finally taken the leap and started trying to write some code, I feel like I've done ok, as a rank amateur, but unsurprisingly it doesn't work and I'm a bit stuck, so I'm hoping I can get a bit of help to get me on the right path.

I think the bigger portion of my issue is that I'm really struggling to understand the MIDI aspect of what I'm trying to do (but I'm confident that my coding is rubbish too!)

I'm trying to make a programmer for my Roland SRV3030, starting with just one parameter (at least I'm trying walk before running).

The spec for the device is here: http://cdn.roland.com/assets/media/pdf/SRV-3030_MI.pdf

If some kind soul could let me know if I'm even in the right woods, let alone barking up the right tree I'd be most grateful.

In particular I'm struggling to understand how to construct the message that should be going to the box (because I'm stuggling to interpret the spec)

The secondary issue is how to put the code together to capture the slider info and update the buffer value (as this doesn't seem to be working - watching the data in ReaControlMidi I don't see anything change when I move the slider).

All advice and guidance gratefully received!

Code:
desc:Roland SRV3030 EZ Edit Midi Control Experiment

//this is the proof of concept version in which I demonstrate my ignorance of coding, maths and midi! 

in_pin:none
out_pin:none

slider1:50<0,100,1>Rev Time A 

@init
ext_noinit = 1; 
buf[0] = 0x50; //Temp program parameter block ofset MSB(? I think, and the next 3 lines..)
buf[1] = 0x00; //offset LSB of parameter block
buf[2] = 0x00; //offset address MSB
buf[3] = 0x0E; //offset address LSB (added to parameter block which is 00)
buf[4] = slider1; //data value (to change parameter setting) - not seeing this change anything...

@slider
//revat = slider1; //do I need to make the slider a variable and then feed that to the buffer or can I just set buf[n] = slider1?

@block
midisend_buf(0,buf,4+1); //the spec says 7 byte message, do I need to make this 5 to deal with the fact 
//that reaper adds sysex send and end (or is it 7 + status bytes)?
rothchild is online now   Reply With Quote
Old Yesterday, 11:32 AM   #2
rothchild
Human being with feelings
 
Join Date: Oct 2007
Posts: 510
Default

Feel like I'm getting closer at least (probably not, but it keeps me motivated!)

Thanks to this rather useful little guide: http://www.2writers.com/eddie/TutSysEx.htm

I've ended up with:

Code:
desc:Roland SRV3030 EZ Edit Midi Control Experiment

//this is the proof of concept version in which I demonstrate my ignorance of coding, maths and midi! 


in_pin:none
out_pin:none

slider1:50<0,100,1>Rev Time A 

@init
ext_noinit = 1; 

@slider
//revat = slider1; //do I need to make the slider a variable and then feed that to the data buffer or can I just set buf[n] = slider1?

@block
buf = 100000; //not sure what this value is for, can anyone advise please?
buf[0] = 0x41; //manufacturer ID
buf[1] = 0x10; //device ID - this is apparently arbitary as there's only 1 device
buf[2] = 0x00; //model ID MSB
buf[3] = 0x12; //model ID LSB
buf[4] = 0x12; //command ID
buf[5] = 0x00; //address MSB
buf[6] = 0x00; //address bb
buf[7] = 0x04; //address cc
buf[8] = 0x0E; //address LSB
buf[9] = 0x32; //data - just set to 50 to see if the prgram changes for now, I'll work out the slider later
//buf[10] = 0xnn; //checksum (want to make a funciton for this so it adds up the right bits and 
//changes it according to slider value, is this element mandatory?

midisend_buf(0,buf,10); //the spec says 7 byte message, do I need to make this 5 to deal with the fact 
//that reaper adds sysex send and end (or is it 7 + status bytes)?
At least the string that's coming through reacontrol midi looks like the right sort of thing.

The main bit I'm still not getting is how to interpret some of the stuff in the spec. For instance am I aiming to edit 'program parameters' or the 'temporary program parameters' (page 2), and if it's the latter, which one (they're listed twice with different addresss for some reason (10 00 00 00 and 50 00 00 00))

I appreciate that this must be painful to watch for anyone who actually knows what they're doing, so any help or tips that might set me on the right path are gratefully received.
rothchild is online now   Reply With Quote
Old Yesterday, 12:31 PM   #3
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 5,144
Default

Just one small piece of the puzzle...

Code:
@block
buf = 100000; //not sure what this value is for, can anyone advise please?
buf[0] = 0x41; //manufacturer ID
buf[1] = 0x10; //device ID
From the manual:
Code:
You may use brackets to index into memory that is local to your effect.
Your effect has approximately 8 million (8,388,608) slots of memory and
you may access them either with fixed offsets (i.e. 16811[0]) or with
variables (myBuffer[5]). The sum of the value to the left of the
brackets and the value within the brackets is used to index memory. If
a value in the brackets is omitted then only the value to the left of
the brackets is used.
So in this case you set your offset to start storing the values at 1000
so that writing to "buf[0]" writes to the memory location 1000, and writing to "buf[1]" writes to memory location 1001, etc.

You basically set the buffer to start at some specific place in memory. This is handy when you want to make sure that arrays do not overlap, for instance, in some code for doing FFT, I coded:

Code:
  BUF_SIZE = 16384;   // Must be at least 2 times max FFT size!
  // Set up the buffers
  window = 0;
  buf1 = window + BUF_SIZE; // buf1 = 16384;
  buf2 = buf1 + BUF_SIZE;        // buf2 = 32768;
  LoBuf1 = buf2 + BUF_SIZE;       // LoBuf1 = 49152;
  LoBuf2 = LoBuf1 + BUF_SIZE;       // LoBuf2 = 65536;
  MidBuf1 = LoBuf2 + BUF_SIZE;
  MidBuf2 = MidBuf1 + BUF_SIZE;
  HiBuf1 = MidBuf2 + BUF_SIZE;       // HiBuf1 = 81920;
  HiBuf2 = HiBuf1 + BUF_SIZE;       // HiBuf2 = 98304;
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
Fabian is offline   Reply With Quote
Old Yesterday, 12:42 PM   #4
rothchild
Human being with feelings
 
Join Date: Oct 2007
Posts: 510
Default

Thanks Fabian!

A timely and relevant intervention, awesome.

I've got the basic premise working now (downloaded the demo of midiquest and spied on the data it was kicking out ;-)

I'm now here:

Code:
desc:Roland SRV3030 EZ Edit Midi Control Experiment

//this is the proof of concept version in which I demonstrate my ignorance of coding, maths and midi! 


in_pin:none
out_pin:none

slider1:50<0,100,1>Rev Time A 

@init
ext_noinit = 1; 

@slider
//revat = slider1; //do I need to make the slider a variable and then feed that to the data buffer or can I just set buf[n] = slider1?

@block
buf = 100000; //not sure what this value is for, can anyone advise please?
buf[0] = 0x41; //manufacturer ID
buf[1] = 0x00; //device ID
buf[2] = 0x00; //model ID MSB
buf[3] = 0x12; //model ID LSB
buf[4] = 0x12; //command ID
buf[5] = 0x50; //address MSB
buf[6] = 0x00; //address bb
buf[7] = 0x00; //address cc
buf[8] = 0x0E; //address LSB
buf[9] = 0x32; //data
buf[10] = 0x70; //checksum (want to make a funciton for this so it adds up the right bits and 
//changes it according to slider value)

midisend_buf(0,buf,11); //sends the command
My next question was going to be about defining the variables for the buffers but I can see you've done that so I'm going to play with that and the maths for calculating the checksum and putting it in a variable.

I'm going to stew on the memory buffer thing for a while, I've not got to arrays yet (I don't think), so as long as they've got somewhere to go for now I'm happy.
rothchild is online now   Reply With Quote
Old Yesterday, 05:14 PM   #5
Time Waster
Human being with feelings
 
Time Waster's Avatar
 
Join Date: Aug 2013
Location: Bowral, Australia
Posts: 703
Default

Code:
buf = 100000; //not sure what this value is for, can anyone advise please?
The address for the memory location is the sum of the value in front of the square brackets (in this case "buf") and the value inside the brackets. In your previous code you had not set the value of buf so it would have defaulted to 0, which is fine as long as you aren't already using that block of memory. You can assign variables to either the number in front of the brackets, or the number inside the brackets, or both.
__________________
ReaRack JSFX Modular Synth - Mostly harmless: https://stash.reaper.fm/v/28403/ReaR...dularSynth.zip
The Wasters of Time: https://soundcloud.com/thewastersoftime
Time Waster is offline   Reply With Quote
Old Today, 06:54 AM   #6
rothchild
Human being with feelings
 
Join Date: Oct 2007
Posts: 510
Default

Thanks Timewaster, I can see how the buffers really matter for audio processing, I'm not so clear how and when I'm going to come up against them in this project as I'm dealing with comparatively small amounts of data (or maybe that's not the matter!)


For now I'm now after a graceful way to code the checksum calculator, at the moment I've got this:

Code:
//checksum calculator 
sum1 = addmsb + addbb;
sum2 = sum1 + addcc;
sum3 = sum2 + param;
sum4 = sum3 + value;
sum5 = sum4 % 0x80;
sum = 0x80 - sum5;
But it doesn't seem to work as expected, do I have to convert to decimals? (and if so is this what 'sprintf' is for?)

I'm tying to do this(http://www.2writers.com/eddie/TutSysEx.htm):

1. Convert hex to decimal:
40h = 64
11h = 17
00h = 0
41h = 65
63h = 99

2. Add values:
64 + 17 + 0 + 65 + 99 = 245

3. Divide by 128
245 / 128 = 1 remainder 117

4. Subtract remainder from 128
128 - 117 = 11

5. Covert to hex:
11 = 0Bh


But I have a different number of bytes to deal with than any other definition of the checksum that I've cound online, so if anyone has any insight as to whether the method described should still work or not (of if I have to work out the checksum another way) that would be most helpful.
rothchild is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:37 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.