No internet connection
  1. Home
  2. Support

Midi CC toggle button

By Dryw Owens @Dryw_Owens
    2025-11-01 03:08:21.890Z

    Hello,
    I’ve been trying to emulate this stream deck workflow I had with the Elgato software. I’d like a single button to toggle between CC values 0 and 127 (off/on) and have separate images for each button state. I haven’t found a good way to do this. Can anyone help guide me?
    Thanks!

    • 3 replies
    1. D
      Dryw Owens @Dryw_Owens
        2025-11-06 03:35:27.292Z

        Anyone?

        1. In reply toDryw_Owens:

          Hey @Dryw_Owens,

          Sorry it took a while to get to this one. I'm happy to help.

          Here is a script that will toggle between two CC values. I've set it up so that it does so between 0 and 127 on CC64 (Sustain Pedal).

          Feel free to adjust the rest of the settings to your liking at the bottom of the script:

          /**
           * @param {{ 
           *   outputNum: number, 
           *   midiChannel: number, 
           *   midiCC: number, 
           *   minValue: number, 
           *   maxValue: number 
           * }} args 
           */
          function toggleMidiCC({ outputNum, midiChannel, midiCC, minValue, maxValue }) {
              const id = `${outputNum}_${midiChannel}_${midiCC}`;
          
              // Initialize state
              if (globalState.toggleMidiCC === undefined) {
                  globalState.toggleMidiCC = {};
              }
          
              if (globalState.toggleMidiCC[id] === undefined) {
                  globalState.toggleMidiCC[id] = { isOn: false };
              }
          
              const state = globalState.toggleMidiCC[id];
          
              // Flip the toggle
              state.isOn = !state.isOn;
          
              // Send the corresponding CC value
              sf.midi.sendCC({
                  outputNum,
                  midiChannel,
                  midiCC,
                  value: state.isOn ? maxValue : minValue
              });
          
              return { state };
          }
          
          toggleMidiCC({
              outputNum: 1,
              midiChannel: 1,
              midiCC: 64,
              minValue: 0,
              maxValue: 127
          });
          
          1. In reply toDryw_Owens:

            Regarding your second inquiry, unfortunately it is currently not possible to have different images on a button to reflect state.

            It is a feature that is requested often though, so please make sure to like and comment on the following link to keep bringing attention to it and hopefully have it implemented soon!