Music Dev - CC64 flip switch checking functions - for HISE, kontakt or others
A very nifty little script that demonstrates a flip-switch of a variable upon input of a virtual CC64 input from a midi controller. Only for demoing a way you could use this in a music instrument script for a sustain pedal.
by andioak
HTML
<!DOCTYPE html>
<html>
<head>
<title>CC64 flip-switch check using JS function and button - by Anders Eklöv</title>
</head>
<body>
<h2>HISE Pedal switch script - using onController, storing flip-switch variable representing midi CC 64 messages</h2>
<p>The idea here is to set a variable to 0 or 1 based on the input from CC64 values. Because you can use either a normal
sustain pedal or a contiuous controller it´s easy to get an overwhelming amount of messages that may cause errors in
other parts of the script, like the onNoteOn callback. Setting the flip-switch variable is only interesting once we get a
flipped result. It´s either the opposite of 0 or 1 on every actual state change. To preserve action and attention.</p>
<button onclick="initiateCC()">Initiate CC64 messages run (2 times from 0-127 and back)</button>
<p id="output"></p>
<script>
// script written by Anders Eklöv, twitter.com/anderseklov/
// licensing: public domain.
// usage: in HISE-script, version of Javascript for HISE sample library creator.
// Easily integrated and transfered into other environments like Kontakt.
var stateOfCC64 = 0; // initialize with 0. Pedal is off.
var laststateofCC64 = 0;
var x = 1;
const out = document.getElementById("output");
function onController(cc) { // this would be the onController callback in HISE.
var messageCC64 = cc;
// by dividing 128 (midi interval) by the incoming midi-CC number we find if it is below 64 (128/2)
stateOfCC64 = ((128 / messageCC64) > 2) ? 0 : 1; // if splitting results in above 2, its a smaller number than 64, so a 0. Pedal is off.
if (stateOfCC64 != laststateofCC64) // to not have to worry about this pedal value if it is not different from the last value. Saves cpu-time in other callbacks.
{
laststateofCC64 = stateOfCC64; // use the laststateofCC64 in other parts of the script.
out.innerText += "input: " + cc + ". state: " + laststateofCC64 + ". ";
console.log("input: " + cc + ". state: " +...