User Tools

This is an old revision of the document!


grandma msc

/*
sysex = f0 7f 70 02 01 01 31 2e 30 30 30 f7
univeral sysex = 127
device id = 112
msc = 2
command format = 1
command = 1
fader = 49
fader page = 46
fine value = 48
coarse value = 48

sysex = f0 7f 70 02 01 0a 30 2e 30 30 30 f7
univeral sysex = 127
device id = 112
msc = 2
command format = 1
command = 10
fader = 48
fader page = 46
fine value = 48
coarse value = 48

f0 7f usiversal sysex
70 device id
02 msc
01 command format (01 = general lighting)
0a command
30 2e 30 30 30 data
f7 end

=========== go 2.0 exec 2.1 ===========
0 f0 (240)
1 7f (127) universal sysex
2 7f (127) device id
3 02 (2) msc
4 01 (1) command format
5 01 (1) command
6 32 (50) ascii 2
7 2e (46) ascii .
8 30 (48) ascii 0
9 30 (48) ascii 0
10 30 (48) ascii 0
11 00 (0) ascii null
12 32 (50) ascii 2
13 2e (46) ascii .
14 31 (49) ascii 1
15 f7 (247)

=========== go 1.0 exec 2.1 ===========
0 f0 (240)
1 7f (127) universal sysex
2 7f (127) device id
3 02 (2) msc
4 01 (1) command format
5 01 (1) command (1 = goto)
6 31 (49) ascii 1
7 2e (46) ascii .
8 30 (48) ascii 0
9 30 (48) ascii 0
10 30 (48) ascii 0
11 00 (0) ascii null
12 32 (50) ascii 2
13 2e (46) ascii .
14 31 (49) ascii 1
15 f7 (247)

=========== goto 1.0 exec 2.1 ===========
0 f0 (240)
1 7f (127) universal sysex
2 7f (127) device id
3 02 (2) msc
4 01 (1) command format
5 01 (1) command (1 = goto)
6 31 (49) ascii 1
7 2e (46) .
8 30 (48) ascii 0
9 30 (48) ascii 0
10 30 (48) ascii 0
11 00 (0) ascii null
12 32 (50) ascii 2
13 2e (46) .
14 31 (49) ascii 1
15 f7 (247)

=========== off exec 2.1 ==============
0 f0 (240)
1 7f (127) universal sysex
2 7f (127) device id (127)
3 02 (2) msc
4 01 (1) command format (01 = general lighting)
5 0a (10) command (10)
6 30 (48) ascii 0
7 2e (46) .
8 30 (48) ascii 0
9 30 (48) ascii 0
10 30 (48) ascii 0
11 00 (0) ascii null
12 32 (50) ascii 2
13 2e (46) .
14 31 (49) ascii 1
15 f7 (247)

========= fader move ===============
0 f0
1 7f universal sysex
2 70 device id
3 02 msc
4 01 command format (01 = general lighting)
5 06 command (06 = set)
6 00 fader 1
7 01 page 1
8 7f 127 fine
9 7f 127 coarse
10 f7

fader value :
fader @45% =
45 * 1.28 = 57.6
coarse = 57
06 * 128 = 76.8
fine = 76
inverse =
Math.floor((new_fine_value + coarse_value) / 1.28)

osc address : /sysex
osc target : midi:gma_in
*/

INPUT_MIDI_DEVICE_NAME = 'gma_out';
OUTPUT_MIDI_DEVICE_NAME = 'gma_in';
DEBUG = true;

function faderToHex(fader_value) {
  var temp_coarse = fader_value * 1.28;
  var coarse = Math.floor(temp_coarse);
  var coarse_hex = coarse.toString(16);
  if (coarse < 16) coarse_hex = "0"+ coarse_hex;

  var coarse_decimals = (temp_coarse %1).toFixed(2);
  var temp_fine = coarse_decimals * 128;
  var fine = Math.floor(temp_fine);
  var fine_hex = fine.toString(16);
  if (fine < 16) fine_hex = "0"+ fine_hex;

  return {
    'coarse': coarse_hex,
    'fine': fine_hex
  }
}

function hexToFader(coarse, fine) {
  return Math.floor(((fine / 128) + coarse) / 1.28);
}

function moveOSCFader(host, port, address, args) {
  if (!(host === 'midi' && address === '/sysex' && port === INPUT_MIDI_DEVICE_NAME)) return;

  // hexadecimal string value
  
  var sysex_string = args[0].value
  if (DEBUG) console.log("sysex = " + sysex_string);

  // convert string to array of integers
  var ints = sysex_string.split(" ").map(x=>parseInt(x, 16))

  // parse items
  var [
    sysex_start,
    universal_sysex,
    device_id,
    msc,
    command_format,
    command,
    fader,
    fader_page,
    fine_value,
    coarse_value,
    sysex_end
  ] = ints;

  // if command = set
  if (command == 6) {
    var fader_percent = hexToFader(coarse_value, fine_value);
    if (DEBUG) console.log("fader percent = "+ fader_percent);
    receive("/fader_"+fader,fader_percent);
  }
  return true;
}

function moveMaFader(host, port, address, args) {
  if (host !== 'midi' || port !== OUTPUT_MIDI_DEVICE_NAME) return
  var fader_id = parseInt(address.substr(7)),
      fader_value = Math.ceil(args[0].value),
      outArgs = [];

  var fader_id_hex = fader_id.toString(16);
  if (fader_id < 16) fader_id_hex = "0"+ fader_id_hex;

  var hex_values = faderToHex(fader_value);
  var sysex = 'f0 7f 70 02 01 06 '+ fader_id_hex+ ' 01 '+ hex_values.fine+ ' '+ hex_values.coarse+ ' f7';

  send('midi', OUTPUT_MIDI_DEVICE_NAME, '/sysex', sysex);
  return true;
}

module.exports = {
    
  oscInFilter: (data)=>{
    if (DEBUG) console.log("in data : "+ JSON.stringify(data, null, 2));
    var {host, port, address, args} = data;
    if (moveOSCFader(host, port, address, args)) return;
    return data
  },

  oscOutFilter: (data)=>{
    var {host, port, address, args} = data;
    if (moveMaFader(host, port, address, args)) return;
    return data;
  }
  
}

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also, you acknowledge that you have read and understand our Privacy Policy. If you do not agree, please leave the website.

More information