No internet connection
  1. Home
  2. Ideas

Specify a range for triggering scripts with MIDI Controllers

At the moment when using CCs to trigger scripts (or to use as inputs to scripts) your choices are individual CCs on a channel or all of them.

It'd be useful to specify a range of CCs instead of creating multiple individual triggers.

So something like "CC#s 22 - 36".

  • 4 replies
  1. J
    Judson Crane @Judson_Crane
      2024-01-03 05:00:51.864Z

      just reactivated my account after a few months away and disappointed to find the first thing I wanted to do doesn't seem possible. I'd like to specify a certain cc VALUE for the trigger... ie cc 110 at a value of 1 for one trigger, and a value of 2 for another trigger... is this not possible? Thank you-

      1. Chris Shaw @Chris_Shaw2024-01-04 17:10:53.781Z2024-01-04 17:25:10.179Z

        Hey @Judson_Crane,
        The best way to do this would be to create individual scripts or macros that you'd like to be triggered by specific CC values (don't assign any triggers to these scripts/macros), then use a separate script with a midi input / CC assigned as a trigger to trigger those individual scripts.
        Something like this should do it:

        /*
        Ex:
        event.trigger.midiBytes = [177, 1 , 38]
        the three numbers are MIDI Channel, CC#, and CC Value
        */
        
        //de-structure values from midi byte values array
        let [channel, ccNumber, ccValue] = event.trigger.midiBytes
        
        // Command / Script / Macro table
        const commands = {
            10: {
                commandName:"Toggle Transport Window",
                commandID:"user:ckp49i4j60000a2100yfwywgf:cku7r4tjf00070t10edyt27kp#ckshbw2fk001nfp10lxc9v2n4",
            },
            60: {
                commandName:"Toggle Big Counter Window",
                commandID:"user:ckp49i4j60000a2100yfwywgf:cku7r4tjf00070t10edyt27kp#ckshbw2fk001afp104ur18p32",
            },
        }
        
        // Trigger command
        if (commands[ccValue]) {
            let commandToRun = commands[ccValue].commandID
            sf.soundflow.runCommand({
                // SF Script / Macro ID
                commandId: commandToRun
        
            })
        }
        

        Trigger the above script with the CC control you'd like to use like this:

        When the script is triggered via MIDI the MIDI bytes are passed via event.trigger.midiBytes.
        This script takes extracts the ccValue from the MIDI input and uses it to look up the command to be triggered via the commands object.

        if a ccValue matches the key to a command then the command/macro/script will be triggered.

        Just add entries to the command object for any command you'd like to use.
        (the commandName property isn't used in the script. I added it just for labeling purposes).

        You can get the command id by selecting the script/macro in the SF editor and selecting "Command > Command ID" from the SF Editor menu.

        1. If editing the command object seems daunting you could also do this:

          /*
          event.trigger.midiBytes = [177, 1 , 38]
          the three numbers are MIDI Channel, CC#, and CC Value
          */
          
          //destructure values from midi byte values
          let [channel, ccNumber, ccValue] = event.trigger.midiBytes
          
          // Trigger commands
          if (ccValue == 10) {
              sf.soundflow.runCommand({
                  // SF Script / Macro ID
                  commandId: "user:ckp49i4j60000a2100yfwywgf:cku7r4tjf00070t10edyt27kp#ckshbw2fk001nfp10lxc9v2n4" // toggle transport window
              })
          }
          if (ccValue == 60) {
              sf.soundflow.runCommand({
                  // SF Script / Macro ID
                  commandId: "user:ckp49i4j60000a2100yfwywgf:cku7r4tjf00070t10edyt27kp#ckshbw2fk001afp104ur18p32" // toggle BIg Counter window
              })
          }
          
          if (ccValue == 90){
              log ("hey, the CC value is 60")
          }
          
          if (ccValue == 127){
              log ("CC value is as high as it gets: 127")
          }
          if (ccValue == 0){
              log ("CC value is as low as it gets: 0")
          }
          
      2. J
        In reply toChris_Shaw:
        Judson Crane @Judson_Crane
          2024-01-04 19:53:56.393Z

          ah good stuff, thank you!! Would be good to get cc value added to the trigger eventually, but this seems like a good work around for now. Thanks!!