No internet connection
  1. Home
  2. How to

What am I missing trying to repurpose Logic knob script?

By Thomas Linder @Thomas_Linder
    2024-09-03 00:44:31.014Z

    What I'm trying to solve:
    I'm trying to resolve the distinction that the current SF-Logic package has with respect to putting the Zoom +- sliders on Streamdeck+ knobs, and the fact that the current SF implementation ONLY targets the Track window, when Logic puts a different set of Zoom sliders on the Piano Roll view, that aren't addressed by the current SF-Logic package (afaict).

    What I've tried so far:
    Take a generic Knob macro, present in the SF Basics package, unpack its js and paste Pick js to that with appropriate parameter modifications. While I was able to generate Pick data, I don't appear to be getting any js from the Basics package that I can work with (see below, from a Generic Knob Command package macro js extraction):

    //Calling command "<3>" from package "Basics" (installed from user/pkg/version "srAasovvDiQacRZ2mcId4RrOA8R2/ckuxffxq80000u010m7g02u3l/clycxeqx60000hy10jnc4f8zj")
    sf.soundflow.runCommand({
        commandId: 'user:ckuxffxq80000u010m7g02u3l:clkv1kl7f0000np10izwlbmao#cm0a61g8s0004vw10fyzvr3o5',
        props: {}
    });
    
    sf.ui.logic.mainWindow.groups.whoseDescription.is("Piano Roll").first.groups.whoseDescription.is("Piano Roll").first.sliders.whoseDescription.is("Vertical Zoom").first.children.whoseRole.is("AXValueIndicator").first.mouseClickElement();
    
    

    ....or this...

    //Calling command "Zoom Sliders - Adjust - Horizontal Zoom -5%" from package "Logic Pro" (installed from user/pkg/version "uOwKfD26NbWKAWotin3dmnSne7B3/cli50xtc200015210vyksy31z/cly64m6na0004m210xs4aihkd")
    sf.soundflow.runCommand({
        commandId: 'user:cli50xtc200015210vyksy31z:cllvac80d0000np100qxewqfl#cllvekk1a000bnp100etetexx',
        props: {}
    });
    
    sf.ui.logic.mainWindow.groups.whoseDescription.is("Piano Roll").first.groups.whoseDescription.is("Piano Roll").first.sliders.whoseDescription.is("Vertical Zoom").first.children.whoseRole.is("AXValueIndicator").first.mouseClickElement();
    
    

    I'm not a complete coding noob, but I don't know what to do with this. The Generic Knob Command js just seems to identify me as a 'valid user'. Am I putting code inside the run command? After the run command? Within the props: {} or outside the props: {}? Or am I completely off in how to approach modifying existing script? I initially assumed I could just swap out mouseClickElement() with some equivalent of knobTurnElement(), but I didn't find anything knob-related that I recognized as useful.

    Full disclosure, I did try using UI_Element with a macro, and while I could generate access to the appropriate element in the Logic UI, I failed to find anything in the SF codebase that would allow me to convert mouse-sliding into knob turn values. Maybe there's a generic approach to do this, or a function/property I didn't recognize as helpful?

    I also gave some thought about reversing the approach, and have the Streamdeck knobs generate MIDI data through SF that could be recognized by Logic using Logic's Learn function. I can get Streamdeck MIDI recognized, but there again, I was stymied by only finding MIDI button and toggle functions, but not an attribute designed to generate 0-126 (1-127) knob values. Did I miss those, or are they not present?

    Please advise, and thanks in advance! Cheers.

    PS: This is an ai-generated mockup of what I expect I'm in for:

    sf.streamDeck.onKnobTurn((event) => {
        const { device, knobIndex, delta } = event;
    
        // Handle the knob turn
        if (delta > 0) {
            // Knob turned clockwise
            sendMidiCC(device, knobIndex, delta);
        } else {
            // Knob turned counterclockwise
            sendMidiCC(device, knobIndex, delta);
        }
    });
    
    function sendMidiCC(device, knobIndex, delta) {
        // Convert delta to MIDI CC value and send it
        const midiCCValue = convertDeltaToCCValue(delta);
        sf.midi.sendCC({
            device: "Your MIDI Device",
            channel: 1,
            cc: knobIndex, // You can map knobIndex to specific CCs
            value: midiCCValue,
        });
    }
    
    function convertDeltaToCCValue(delta) {
        // Implement your logic to convert delta to MIDI CC value
        return Math.max(0, Math.min(127, delta));
    }
    
    
    • 11 replies

    There are 11 replies. Estimated reading time: 11 minutes

    1. Kitch Membery @Kitch2024-09-03 19:15:50.527Z

      Hi @Thomas_Linder,

      Ah yes, you are correct the Zoom Slider commands are currently only designed to work in the Tracks Area.

      Thanks for bringing this to my attention. I'll log this feature request for implementation.

      You can learn more about Generic Knob Commands in the following video.

      Regarding the use of AI for generating SoundFlow scripts, AI models do not have access to the SoundFlow API. While they may be helpful in generating accurate Javascript, they will yield poor results, because they lack understanding of both the SoundFlow API and the target application.

      As the Logic Pro package is still in its early stages, it would be great if you have any other requests or suggestions for functionality, to start a new thread in the Logic Ideas section of the forum. SoundFlow Forum

      Thanks in advance. :-)

      1. TThomas Linder @Thomas_Linder
          2024-09-03 21:54:11.690Z

          Thanks, Kitch! Yeh, I understood that bit regarding ai-script, which is why I included the phrase "mock-up" of what I was attempting. Lol. It was obvious that the SF api wasn't being referenced.

          Anyway...
          So the GKC video you posted was great, however it didn't show me anything I hadn't figured out already re: the GKC. As the title of this forum query hints, I was looking for a bit more insight into how to start with repurposing js script. The examples I gave in my initial post show what resulted with script extracted from a SF macro. With Logic, unlike PT, we don't get key commands that do what the Zoom sliders do (that I'm aware of), so I can't do what Chad did in the video with PT, which is why I mentioned using Pick js to select the UI element. But how to extend a Select into a knob turn? I'm stuck with a macro-extracted runCommand() and a Pick-generated mouseClickElement() without knowing how, or if, these two functions go together in the same script?

          As I mentioned in my first post, I'm not completely new to manipulating code, but I need a hand with how to start mixing macro-extracted js with Pick-generated js. For instance, the GKC is described as a template command. Is that 'template' in codespeak, which means it has defined properties and is ready to receive function calls? Or is that 'template' as a colloquialism, where nothing is defined and nothing can be assumed? The runCommand() seems like a closed user-validation test. How to begin adding new code to such a script if I'm not sure whether it's a true code-template or just a 'template'?

          Also mentioned, I did begin examining the SF codebase for knob-related functions/properties/events (to use in converting a Select into a KnobTurn) but didn't seem to find any defined KnobTurn events. I thought I could repurpose defined KnobTurn events from existing Knob-related macros, but....see above...I get a runCommand() when I extract js.

          I know this is likely viewed as a tl;dr comment, but once I get my bearings with the SF code editor, I should be on my way. Can you give me a start on this? I'm a bit puzzled and don't want to waste time chasing down blind alleys. Cheers.

          1. Kitch Membery @Kitch2024-09-03 22:18:50.975Z

            Hi @Thomas_Linder,

            As mentioned in my previous reply, I plan on implementing the feature you have requested. My goal would be to update the Zoom Slider command to work with both the Tracks Area, Piano Roll, and Docked Piano Roll depending on the frontmost logic window and which panel is focused.

            The Logic Pro UI can be difficult to control due to its dynamic nature, so right now, getting requests for features will allow me to create more robust commands that are available to the whole SoundFlow / Logic Pro Community.

            Regarding this "I know this is likely viewed as a tl;dr"... Absolutely not, however, it may be best to field your other questions in a Zoom call. If that is something you'd be interested in, please send an email to me at support@soundflow.org and we can set up a time. :-)

            1. In reply toThomas_Linder:
              Kitch Membery @Kitch2024-09-03 22:25:35.766Z

              Ahhhh.... On my fourth read-through, I think I now understand what you're trying to achieve...

              Let me take a look at converting the knob command into Javascript.

              This is no doubt a limitation at the moment with new Meta Commands that have callbacks.

              Thanks for your patience on this.

              1. In reply toThomas_Linder:
                Kitch Membery @Kitch2024-09-03 22:33:56.386Z

                Hi @Thomas_Linder,

                I can confirm that this is a limitation. The "Generic Knob Command" or its presets can't be converted into editable javascript.

                This is unlikely to change in the near future but if you have a list of functionalities that you'd like to see accomplished with the "Generic Knob Command" please let me know and I'll log them for consideration.

                Still happy to jump on a Zoom call though. Would love to meet another SF/Logic Pro user. :-)

                1. TThomas Linder @Thomas_Linder
                    2024-09-04 15:40:04.591Z

                    Thanks for the offer to zoom on this, Kitch. Honestly, I'm not really set up to zoom in the studio, though I could either use my phone or iPad, if you think it might help me achieve a fix until the Logic package gets an update? Let me start by asking what time zone you're in? I'm in NYC, but I unfortunately have a day job, so my home time is limited. But if it looks like something we can do, I'll finalize with you offline by email. Cheers.

                    1. Kitch Membery @Kitch2024-09-04 20:47:00.248Z

                      Hi @Thomas_Linder,

                      No worries at all... For now, I'll see if I can get the functionality working, and next time we schedule a SoundFlow - Logic Pro hangout I'll give you plenty of notice so that you can make it :-)

                      Rock on!

                      1. TThomas Linder @Thomas_Linder
                          2024-09-04 23:10:02.458Z

                          Much appreciated, Kitch! At the risk of abusing my welcome here, perhaps you can point me to the SF MIDI command that would let me send cc messages from the knob(s) to Logic as a workaround? I could employ Logic's Learn function for that, as I've already verified that Logic can 'hear' Streamdeck+ MIDI events. However, I only found the button and toggle events, but nothing that seemed designed to spit out continuous values across a range of values. Did I miss something there? Cheers.

                          1. The action is called "Send MIDI CC".
                            Create a preset under the Generic Knob Commands template, and in the Turn Left or Turn Right Action, add a "Send MIDI CC" action, and configure it to your taste:

                            Alternatively, MIDI can be sent/received bi-directionally using the MIDI Knobs package here:

                2. S
                  In reply toThomas_Linder:
                  SoundFlow Bot @soundflowbot
                    2024-09-03 19:16:01.084Z

                    This issue is now tracked internally by SoundFlow as SF-1429

                    1. T
                      In reply toThomas_Linder:
                      Thomas Linder @Thomas_Linder
                        2024-09-09 15:39:56.085Z

                        Thanks, Christian! The GKR macro was attempted, but presently has no Zoom+- slider Logic target as currently implemented in the 5.8.0 Logic package outside of the Tracks window. I'm looking to target the sliders in the Piano roll window. That's what Kitch was able to verify and logged for future SF updates.

                        However, the alternative you suggested, using the Send MIDI mod wheel type assigned to the Streamdeck+ knob is something I hadn't yet tried, and will attempt when I get home. Thanks!