Skip to content

Commit

Permalink
feat: add text for displays
Browse files Browse the repository at this point in the history
chore: refactore
  • Loading branch information
xxpasixx committed Apr 2, 2024
1 parent 2d66571 commit 440e7fb
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 27 deletions.
68 changes: 43 additions & 25 deletions pam-OSC-Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@

// Todo: Refactor: This is only a temp solution
var displayDevice = null;
var displays = [
{ color: "0;0;0;0", seq: "", cue: "" },
{ color: "0;0;0;0", seq: "", cue: "" },
{ color: "0;0;0;0", seq: "", cue: "" },
{ color: "0;0;0;0", seq: "", cue: "" },
{ color: "0;0;0;0", seq: "", cue: "" },
{ color: "0;0;0;0", seq: "", cue: "" },
{ color: "0;0;0;0", seq: "", cue: "" },
{ color: "0;0;0;0", seq: "", cue: "" }
]
var colors = ["0;0;0;0", "0;0;0;0", "0;0;0;0", "0;0;0;0", "0;0;0;0", "0;0;0;0", "0;0;0;0", "0;0;0;0"]

const colorUtils = require('./colorUtils.js');

Expand All @@ -47,6 +38,21 @@ devices.forEach((config) => {
console.log("loaded mapping: ", config);
});


function stringToAsciiHex(str) {
let hexString = '';
for (let i = 0; i < str.length; i++) {
const asciiValue = str.charCodeAt(i);
const hexValue = asciiValue.toString(16).padStart(2, '0');
hexString += hexValue + " ";
}
return hexString;
}

function numberIntoHex(nr) {
return nr.toString(16).padStart(2, '0');
}

module.exports = {
getRoutingByControlerId: function (id) {
const returnArray = [];
Expand Down Expand Up @@ -199,6 +205,12 @@ module.exports = {
if (addressSplit[2].includes('Button')) {
const mappings = module.exports.getRoutingNoteByExecId(fader);
mappings.forEach((mapping) => {
// for the MC mode, it is required to send a note on with velocity 0
if (routing[mapping.device].mode == "mc" && args[0].value == "Off") {
send('midi', mapping.device, '/sysex', '90' + numberIntoHex(mapping.midiId) + ' 00');
return;
}

send('midi', mapping.device, '/note', 1, mapping.midiId, mapping.buttonFeedbackMapper(args[0].value));
});
}
Expand All @@ -217,32 +229,38 @@ module.exports = {
const mappingsDisplay = module.exports.getRoutingByDisplayId(fader);

mappingsDisplay.forEach((mapping) => {
displays[mapping.displayId].color = args[0].value;
colors[mapping.displayId] = args[0].value;
displayDevice = mapping.device;

// send('midi', mapping.device, '/sysex', "f0 00 00 66 14 12 07 48 61 6c 6c 6f 57 65 20 20 f7");
// send('midi', mapping.device, '/sysex', "F0 00 20 32 14 4C 00 05 48 41 4C 4C 4F 20 57 41 48 49 44 4B 45 50 F7");
// send('midi', mapping.device, '/sysex', "f0 00 00 66 14 12 07 48 61 6c 6c 6f 57 65 20 20 f7");
// send('midi', mapping.device, '/sysex', "F0 00 00 66 14 72 00 01 02 03 04 05 06 07 F7");
});


if(!displayDevice) {
if (!displayDevice) {
return;
}
var midiCommand = "F0 00 00 66 14 72";
displays.forEach(display => {
const t = colorUtils.parseColorString(display.color);

const displayColor = colorUtils.findNearestDisplayColor(t);
console.log(displayColor);

colors.forEach(colorString => {
const color = colorUtils.parseColorString(colorString);
const displayColor = colorUtils.findNearestDisplayColor(color);
midiCommand = midiCommand + displayColor + " ";
});
send('midi', displayDevice, '/sysex', midiCommand + "F7");
}

if (addressSplit[2].includes('Name')) {
const mappingsDisplay = module.exports.getRoutingByDisplayId(fader);
const values = args[0].value.split(";");

mappingsDisplay.forEach((mapping) => {
const seqMidiNote = numberIntoHex(mapping.displayId * 7);
const cueMidiNote = numberIntoHex(56 + (mapping.displayId * 7));
const seq = (values[0] + " ").substring(0, 7)
const cue = (values[1] + " ").substring(0, 7)

send('midi', mapping.device, '/sysex', "f0 00 00 66 14 12 " + seqMidiNote + " " + stringToAsciiHex(seq) + "f7");
send('midi', mapping.device, '/sysex', "f0 00 00 66 14 12 " + cueMidiNote + " " + stringToAsciiHex(cue) + "f7");
});
}
}

return { address, args, host, port }
},
}
}
18 changes: 16 additions & 2 deletions pam-OSC.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local executorsToWatch = {}
local oldValues = {}
local oldButtonValues = {}
local oldColorValues = {}
local oldNameValues = {}
local olsMasterEnabledValue = {
highlight = false,
lowlight = false,
Expand Down Expand Up @@ -45,6 +46,7 @@ for _, number in ipairs(executorsToWatch) do
oldValues[number] = "000"
oldButtonValues[number] = false
oldColorValues[number] = "0,0,0,0"
oldNameValues[number] = ";"
end

-- the Speed to check executors
Expand All @@ -55,10 +57,14 @@ local function getApereanceColor(sequence)
if apper ~= nil then
return apper['BACKR'] .. "," .. apper['BACKG'] .. "," .. apper['BACKB'] .. "," .. apper['BACKALPHA']
else
return "0,0,0,0"
return "255,255,255,255"
end
end

local function getName(sequence)
return sequence["NAME"] .. ";" .. sequence["CUENAME"]
end

local function getMasterEnabled(masterName)
if MasterPool()['Grand'][masterName]['FADERENABLED'] then
return true
Expand Down Expand Up @@ -111,21 +117,23 @@ local function main()
local faderValue = 0
local buttonValue = false
local colorValue = "0,0,0,0"
local nameValue = ";"

-- Set Fader & button Values
for maKey, maValue in pairs(executors) do
if maValue.No == listValue then
local faderOptions = {}
faderOptions.value = faderEnd
faderOptions.token = "FaderMaster"
faderOptions.faderDisabled = false;
faderOptions.faderDisabled = false

faderValue = maValue:GetFader(faderOptions)

local myobject = maValue.Object
if myobject ~= nil then
buttonValue = myobject:HasActivePlayback() and true or false
colorValue = getApereanceColor(myobject)
nameValue = getName(myobject)
end

end
Expand Down Expand Up @@ -153,6 +161,12 @@ local function main()
Cmd('SendOSC ' .. oscEntry .. ' "/Page' .. destPage .. '/Color' .. listValue .. ',s,' .. newValue ..
'"')
end

-- Send Name Value
if oldNameValues[listKey] ~= nameValue or forceReload then
oldNameValues[listKey] = nameValue
Cmd('SendOSC ' .. oscEntry .. ' "/Page' .. destPage .. '/Name' .. listValue .. ',s,' .. nameValue .. '"')
end
end
forceReload = false

Expand Down

0 comments on commit 440e7fb

Please sign in to comment.