Audiobus: Use your music apps together.

What is Audiobus?Audiobus is an award-winning music app for iPhone and iPad which lets you use your other music apps together. Chain effects on your favourite synth, run the output of apps or Audio Units into an app like GarageBand or Loopy, or select a different audio interface output for each app. Route MIDI between apps — drive a synth from a MIDI sequencer, or add an arpeggiator to your MIDI keyboard — or sync with your external MIDI gear. And control your entire setup from a MIDI controller.

Download on the App Store

Audiobus is the app that makes the rest of your setup better.

MOZAIC - Create your own AU MIDI plugins - OUT NOW!

18990929495102

Comments

  • edited May 2023

    I managed to solve the Send Midi cc issue last night, But until now, I am solving the problem of saving highlight and un-highlight pads in layers, which unfortunately I did not succeed,.

    But before I try to solve this problem, I want to ask you a small bug about the highlight and un-highlight pads.

    This patch is related to highlighting and un-highlighting pads in two series :for pads 0 to 3 and for pads 4 to 15.

    1, upload the codes via green color upload button of mozaic.
    2, touch pad num 0 : result Highlighting or turning the pad red.
    3, touch one of 12 pads of second series ,from pad num 4 to num 15 . Result: The blue color of that pad AND ,
    4, result bug : Pad number 0 will be un-highlighted unwanted. While it should not be discolored at all.
    5, again touch the pad num 0 and then touch the one of 12 pads of second series.
    6, result: The problem of pad No. 0 becoming discolored will no longer be repeated. And along the way, the bug is completely fixed.

    1: The interesting thing is that if we repeat the same steps from the beginning, but instead of step 2, we touch pad num 1 or 2 or 3, this problem does not exist at all.

    2: if i replace num 0 with num 1, in this code : if LastPad >= 0 and LastPad <= 3 , This bug does not occur for pad number one.

    Is the problem with the number 0 or is the problem from somewhere else?

    Because this patch has no problem with any number other than 0.


    @OnLoad ShowLayout 2 padrevert = LastPad padrev = LastPad @End @OnPadDown if LastPad >= 0 and LastPad <= 3 ColorPad padrevert, 0 ColorPad LastPad , 1 padrevert = LastPad elseif LastPad >= 4 ColorPad padrev , 0 ColorPad LastPad , 5 padrev = LastPad endif @End
  • wimwim
    edited May 2023

    @pejman - I only looked at it briefly, but I think I see what the problem may be.

    You're setting padrevert and padrev to LastPad in the @OnLoad section. @OnLoad fires when the script first loads, but at that time no pads have been touched so LastPad is invalid. Try setting them directly to whatever number they should be when the script first loads.

    Before you make that change, it might be a good idea to check the Log screen to see if any informative errors show there when you load the previous script. That's always a good idea when things don't work the way you expect.

  • Ok i will try,
    Yes i always check the log. No error is presented in this patch.

  • The problem was solved with your suggestion, thank you very much.🙏

    But my question is why this problem does not exist in relation to pad number 1, 2 and 3 ?

  • @pejman said:
    The problem was solved with your suggestion, thank you very much.🙏

    But my question is why this problem does not exist in relation to pad number 1, 2 and 3 ?

    Probably because when you tried to assign padrevert and padrev to LastPad in @OnLoad, they were both set to zero. I'm not sure though since I haven't taken the time to look closely at your code. Normally the first thing I do when troubleshooting is to fix anything that's obviously wrong and see what happens. After that I try to understand why.

    I would be asking the question, "How would my code work if I assign 0 to those two variables?" If that doesn't shake loose some answers for you, and you still need to understand why, I'll take a closer look.

  • I assigned 0 and 4 to solve my problem, but when i assigned 0 and 0 , The same problem occurs again. Of course, I tried these numbers myself to understand the issue, but unfortunately it is still not understandable for me clearly.

  • @pejman said:
    I assigned 0 and 4 to solve my problem, but when i assigned 0 and 0 , The same problem occurs again. Of course, I tried these numbers myself to understand the issue, but unfortunately it is still not understandable for me clearly.

    Grab a pencil and paper and simulate what is happening by going through the code line by line (in the order executed by the program) and writing down what the values of your variables after each line

    Do that for the various actions you might take.

    Then add log statements that print out the variable values and compare to your paper simulation.

    It is a valuable exercise for checking your understanding of your code. I find and fix a lot of errors this way as it makes you very aware of how each step contributes.

  • @espiegel123 , your right. I always do the same thing, which is to analyze the events.
    But sometimes the topic becomes very confusing for me for certain reasons, maybe because I expect something else from it.

    Regarding the previous issue, I have come to the conclusion that the number that I determine for each series of pads should not exceed their limits, that is, it should not exceed the limits of others.🙂

  • @pejman said:
    @espiegel123 , your right. I always do the same thing, which is to analyze the events.
    But sometimes the topic becomes very confusing for me for certain reasons, maybe because I expect something else from it.

    Regarding the previous issue, I have come to the conclusion that the number that I determine for each series of pads should not exceed their limits, that is, it should not exceed the limits of others.🙂

    Post your current code. Explain what you expect to happen and what does happen.

    If the results are surprising you, use the log to print out variables at the beginning of onPadDown and at the end, to see if they were what you expect.

  • edited May 2023

    @spiegel , thanks for attention.

    this is my patch about send cc value with selectable cc# num
    Via same knob in second layer through shift button.

    In which I have put the code related to setknobvalue the knob to value 90 , only for layer 1 ( send cc value ) , not cc # num .

    @OnLoad
    
    if Unassigned init
      init = YES
    
      Shift = 0
      selection = Shift
      value = 90
      num = GetKnobValue
      [selection] = Round value
      snum[selection] = 64
      svalue[selection] = [90]
        LabelKnob 0, {Value},Round value
        
        
        
    endif
    
        Call @SetKnobPosition
        Call @SetKnobLabel
      
      @End
    
    
    
    @OnShiftDown
    
     if Shift = 0
       Shift = 1
       else
       Shift = 0
      endif
          
          selection = Shift     
    
    for knob = 0 to 9
    
       Call @SetKnobPosition
        Call @SetKnobLabel
        
     endfor
       
       
       @End
       
       
    @OnKnobChange
       
       
       Knob = LastKnob
       
       if Knob = 0 and Shift = 0
       
          svalue[selection] = value
         
         elseif  knob = 0 and Shift = 1
     
          snum[selection] = num
          
          endif
       
       
       if Shift = 0
       
         set = GetKnobValue 0 
         if set = 64
         a = 90
         SetKnobValue 0, a 
         SendMIDICC 1, num, 90, 300 
      endif
      
       value = TranslateScale (GetKnobValue 0), 0,127,0,127
           SendMIDICC 1, num, value
           
           elseif  Shift = 1
       num = TranslateScale (GetKnobValue 0), 0,127,0,127
       
     endif
     
        Call @SetKnobPosition
        Call @SetKnobLabel
    
    
    @End 
    
    
    
    @SetKnobPosition
    
        if  Shift = 0
           SetKnobValue 0, svalue[selection]
    
        else
            SetKnobValue 0, snum[selection]
    
        endif
        
        @End
        
        
    @SetKnobLabel
    
     if Shift = 0
       LabelKnobs {SEND CC}
       LabelKnob 0, {Value},Round value
    
      else
       LabelKnobs {SETTING CC}
       LabelKnob 0, {cc#num},Round num
    
    endif
    
    @End
    
    
  • I want to with double tap on knob 0 in first layer ( send cc value ) knob set to 90 , even After every time I change the knob.

    But this patch has bug .

    1, load patch .
    2, change knob to value 40 for example.
    3, double tap on knob.
    4, bug issues: knob sets to 40 instead of 90.
    5 , with double tap again, knob sets to 90 this time.

  • Hi @pejman

    First, to make things easier for everyone going forward let's clear up how to post code blocks correctly so that the formatting doesn't go so badly.

    To make a code block, place three back-tick marks together on a line by themselves before and after the code. The lines should look like this:

    ```
    Your code goes here
    Note: don't simply copy the ``` above because it may not work that way. Find the
    "back-tick" character on your keyboard and type it in three times.
    ```

    And it should appear formatted as a code block like this:

    Your code goes here
    Look at me! I'm a code block~
    

    You don't need to bother trying to nest that in a "spoiler" block as it will only complicate things. If you're interested in knowing how to do that then ask once you're comfortable with posting code blocks cleanly.

    I'll tell you what went wrong with your code in the next post.

  • @pejman - there are some other problems with your code, which I'll explain in a bit. But first:

    In your @OnKnobChange you do successfully set the value to 90 here:

       if set = 64
          a = 90
          SetKnobValue 0, a 
          SendMIDICC 1, num, 90, 300 
        endif
    

    But right after that you call @SetKnobPosition which sets the knob to svalue[selection].

    1. You set value to 90 at the beginning of the script.
    2. You move the knob to 40, which sets svalue[selection] to 40.
    3. You double-tap the knob, which sets the knob to 90 using value ... but you don't see it because immediately after that ...
    4. You call @SetKnobPosition, which sets the knob using svalue[selection] which is still at 40.
  • I've embedded some comments about other issues with your code. Some are actual syntax errors, others are just suggestions for improvement.

    I hope it helps.

    @OnLoad
    
    if Unassigned init
      init = YES
    
      Shift = 0
      selection = Shift
      value = 90
      
    // Incorrect syntax - must specifiy a knob for GetKnobValue
    // Also, at init, GetKnobValue is unnecessary as all knobs are set to 64
    // Better to set num to a fixed/known value
      // num = GetKnobValue
      
    // Incorrect syntax. [selection] isn't a valid variable declaration
      // [selection] = Round value
      
      snum[selection] = 64
    
    // Incorrect syntax. [90] isn't a valid number. Remove the brackets
      svalue[selection] = [90]
      
    // No need to Round an intger value (value = 90), but if you do want to include
    // it, then surround Round value in parenthesis
        LabelKnob 0, {Value},Round value
        
    endif
    
        Call @SetKnobPosition
        Call @SetKnobLabel
      
    @End
    
    
    
    @OnShiftDown
    
     if Shift = 0
       Shift = 1
       else
       Shift = 0
     endif
          
          selection = Shift     
    
    for knob = 0 to 9
    
       Call @SetKnobPosition
        Call @SetKnobLabel
        
    endfor
       
       
    @End
       
       
    @OnKnobChange
       
       
      Knob = LastKnob
       
      if Knob = 0 and Shift = 0 
        svalue[selection] = value
      elseif  knob = 0 and Shift = 1
        snum[selection] = num  
      endif 
       
      if Shift = 0 
        set = GetKnobValue 0 
        if set = 64
          a = 90
          SetKnobValue 0, a 
          SendMIDICC 1, num, 90, 300 
        endif
    
    // Note: you don't need TranslateScale since you're not changing anything
    // when the input range and output range are the same
    // value = GetKnobValue 0 
    // is enough
        value = TranslateScale (GetKnobValue 0), 0,127,0,127
        SendMIDICC 1, num, value
       
      elseif  Shift = 1
    // See note above
        num = TranslateScale (GetKnobValue 0), 0,127,0,127
       
      endif
     
      Call @SetKnobPosition
      Call @SetKnobLabel
    
    @End 
    
    
    
    @SetKnobPosition
    
        if  Shift = 0
           SetKnobValue 0, svalue[selection]
    
        else
            SetKnobValue 0, snum[selection]
    
        endif
        
    @End
        
        
    @SetKnobLabel
    
     if Shift = 0
       LabelKnobs {SEND CC}
    // Best to surround "Round value" with parenthesis
       LabelKnob 0, {Value},Round value
    
      else
       LabelKnobs {SETTING CC}
    // Best to surround "Round num" with parenthesis
       LabelKnob 0, {cc#num},Round num
    
    endif
    
    @End
    
  • Are any of the AI code tools of any use with Mozaic? (ChatGPT et al)

    I keep wanting to complete the Dixie sequencer I made yonks ago but don’t have the chops to get the more complicated bits done, so I’ve been wondering if even some generic blocks could be done by one of those things…

  • I asked chatGPT if it could code in Mozaic or Streambyter a few months ago. At that time it could not - though it thought it could until I pointed out it was giving me code in C++, JavaScript, or Python.

    I just asked again and it told me that it can't right programs in any language, that it's just a text AI model. To which I replied:

    User
    But you do provide code examples in C++ and Python for example.

    ChatGPT
    Yes, that is correct. As a language model, I have been trained on a large corpus of text, which includes programming code written in various programming languages, including C++ and Python. As a result, I am capable of generating examples and snippets of code in those languages based on the input I receive. However, I do not have specific knowledge or expertise in any one programming language, and my ability to generate code examples is limited to the knowledge and examples that have been presented to me during my training.

    User
    Have you been presented with any code examples in the Mozaic programming language?

    ChatGPT
    As far as I am aware, I have not been specifically trained on code examples in the Mozaic programming language. However, if you have specific questions or concepts related to Mozaic, I can use my understanding of programming concepts and my general knowledge of programming languages to provide assistance to the best of my abilities.

  • @wim said:
    I asked chatGPT if it could code in Mozaic or Streambyter a few months ago. At that time it could not - though it thought it could until I pointed out it was giving me code in C++, JavaScript, or Python.

    I just asked again and it told me that it can't right programs in any language, that it's just a text AI model. To which I replied:

    User
    But you do provide code examples in C++ and Python for example.

    ChatGPT
    Yes, that is correct. As a language model, I have been trained on a large corpus of text, which includes programming code written in various programming languages, including C++ and Python. As a result, I am capable of generating examples and snippets of code in those languages based on the input I receive. However, I do not have specific knowledge or expertise in any one programming language, and my ability to generate code examples is limited to the knowledge and examples that have been presented to me during my training.

    User
    Have you been presented with any code examples in the Mozaic programming language?

    ChatGPT
    As far as I am aware, I have not been specifically trained on code examples in the Mozaic programming language. However, if you have specific questions or concepts related to Mozaic, I can use my understanding of programming concepts and my general knowledge of programming languages to provide assistance to the best of my abilities.

    I’ll give it a whirl and see 🙏

  • edited May 2023

    Hi @wim , thank a lot.🙏🙏🙏

    I did what you suggested for the correct way to post the codes and I'm interested in learning the spoiler too if you have time to explain as I don't want it to take up too much space in the posts.

    But if this issue is not very important and there is no problem (in terms of occupying space in the post), then we will ignore it

    I did what you said and I remove by my own ( call @ setknobposition ) of @onknobchange , and my problem is fixed. But again a new problem arose.

    1, load patch
    2, move knob to value 40
    3, double tap on knob
    4, this time knob skip to value 90 properly.
    5, press shift button: go to next layer and press shift again return back to previous layer ( sending cc ) .
    6, the knob is on value 40 instead 90, but label knob shows value 90.

    Should I create a new( call @ xxx ) for this double tap on knob for set specific value and save in layer ?

  • wimwim
    edited May 2023

    Hi @pejman
    If you want to enclose a code block in a "Spoiler", then after you have added the three back-ticks at the beginning and the end, highlight all the lines from the first line with the back-ticks all the way down to the last line with the back-ticks. Then click the paragraph formatter at the top of the editor and select Spoiler. That will put the characters ">! " at the beginning of every line, which is what hides those lines in a spoiler block.

  • @pejman said:
    Should I create a new( call @ xxx ) for this double tap on knob for set specific value and save in layer ?

    Adding a new event to call for a specific sequence of events like you described isn't a good idea. You want the knobs to be positioned differently when shift is 0 or shift is 1. So, check that in the @SetKnobPosition block in the same way you check it in the @SetKnobLabel block.

  • heshes
    edited May 2023

    @wim said:
    I asked chatGPT if it could code in Mozaic or Streambyter a few months ago. At that time it could not - though it thought it could until I pointed out it was giving me code in C++, JavaScript, or Python.

    I think this is may be because virtually nobody uses Github for Mozaic (probably because Mozaic makes that cumbersome to do).

    There are quite obscure languages that ChatGPT is trained on and provides good code for. E.g., I think there are a decent number of people using it with Reaper, for programming with Reaper's proprietary "ReaperScript" language. It's pretty cool, can see examples of its use on youtube.

  • Then by all means post Mozaic code on this forum. More code and these AI tools will have text to study and integrate into its data sets. I think a couple million examples should work wonders. Maybe a site called NakedMozaic would be better.

    On 60 Minutes they said that DeepMind’s AI learned Bangladesh (or the language spoken there) just by scanning the web.

  • edited May 2023

    @wim said:

    @pejman said:
    Should I create a new( call @ xxx ) for this double tap on knob for set specific value and save in layer ?

    Adding a new event to call for a specific sequence of events like you described isn't a good idea. You want the knobs to be positioned differently when shift is 0 or shift is 1. So, check that in the @SetKnobPosition block in the same way you check it in the @SetKnobLabel block.

    Unfortunately, I do not succeed in every change and every move i make.

  • wimwim
    edited May 2023

    Hi @pejman
    See if this helps. Rather than keep iterating back and forth trying to understand what might be going wrong, I wrote something similar but in the ways that I would do it. Note that this is based on my understanding of what you're trying to do. I could have it wrong since it's a little hard to sort out at times. There could be bugs too, if so I apologize. I only tested very lightly. I'll post the example with and without comments below.

    I almost didn't want to do this because in order to move forward you really need to learn to do as @espiegel123 suggests and follow your code step by step, writing down what variables are equal to each step of the way. But, that's a skill that can be hard to develop if you're really lost in the weeds with a particular piece of code. You'll get better at it with practice.

    With comments:

    @Description
    Example for @pejman: 
    - Using the Shift button to switch between different behavior of knobs (which he refers to as "layers"). 
    - Resetting knobs to a value other than "64" on double-tap.
    - Storing different values for each layer
    - Sending different MIDI values depending on the layer
    @End
    
    @OnLoad
      if Unassigned init
        init = YES
        
    // To make the code easier to follow lets assign some named constants so we don't have to remember
    // what's going on every time.
        _sendLayer = 0
        _setLayer = 1
    
    // I don't like the variable name "Shift" when all discussions are about "layers". Let's use a variable
    // name that's less abstract instead.
        layer = _sendLayer
        LabelKnobs {SEND CC}
        
    // I'm not sure why you used the svalue[selection] and snum[selection] variables it accomplishes what you want
    // for only one knob. What I think you want to do is store two values for 10 knobs. So, better to make variables
    // that can do that. Otherwise you'll need two variables for every knob ... 20 variables.
    // this also gives you the opportunity to initialize each variable / knob to what you want it to be on load.
        val = [90, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        num = [64, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        
    // Since val and num are always going to be changing, but you want a default value for each on double-tap
    // we need variables to store those defaults
        default_val = [90, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        default_num = [64, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        
    // You hard code the channel to 1 (Midi channel 2), but it's much better to set to a variable on script load
        _chan = 1
    
    // In your code you only call @SetKnobPosition for one knob here, but in other places you call it for
    // knobs 0-9. Better to keep things consistent to avoid surprises later on.
        for knob = 0 to 9
          Call @SetKnobPosition
          Call @SetKnobLabel
        endfor
    // Note: if you always call @SetKnobPosition and @SetKnobLabel together, you could combine them into
    // a single event, maybe called something like @UpdateKnobs
      endif
      
    @End
    
    @OnShiftDown
    // Note the use of constants instead of 0 and 1. This makes the code easier to follow. Maybe not so
    // important where you only have two layers, but cleaner and would help a lot if you introduced more
    // layers
    
    // Also note LabelKnobs works better here, when the change happens, than in @SetKnobLabel where it
    // redundantly gets called on every knob value change.
    
      if layer = _sendLayer
        layer = _setLayer
        LabelKnobs {SETTING CC}
      else
        layer = _sendLayer
        LabelKnobs {SEND CC}
      endif
      
    // Your code sets another variable "Selection" here. I don't see any need for that.
    // Just refer to the "layer" variable instead.
    
      for knob = 0 to 9
        Call @SetKnobPosition
        Call @SetKnobLabel
      endfor
        
    @End
    
    @OnKnobChange
    // You don't have to assign variables here, but it's more convenient than calling 
    // "GetKnobValue" and "LastKnob" all the time
      knob = LastKnob
      value = GetKnobValue LastKnob
    
    // Set the appropriate variable depending on which layer is active. Note that
    // knob determines the position in the array to set.
    
    // Note code has been reduced by nesting things in if blocks instead of calling
    // multiple blocks that override eachother.
      if layer = _sendLayer
        if value = 64
          val[knob] = default_val[knob]
        else
          val[knob] = Round value
        endif
        SendMIDICC _chan, num[knob], val[knob]
        
      elseif layer = _setLayer
        if value = 64
          num[knob] = default_num[knob]
        else
          num[knob] = Round value
        endif
      endif
      
      Call @SetKnobPosition
      Call @SetKnobLabel
    @End
    
    @SetKnobPosition
    // Just as in @KnobChange, use an if condition to act differently depending on the layer.
    // Note that "knob" needs to be set before calling this event.
      if layer = _sendLayer
        SetKnobValue knob,val[knob]
      elseif layer = _setLayer
        SetKnobValue knob,num[knob]
      endif
    @End
    
    @SetKnobLabel
    // See note for @SetKnobPosition
      if layer = _sendLayer
        LabelKnob knob,{Value }, val[knob]
      elseif layer = _setLayer
        LabelKnob knob, {CC# }, num[knob]
      endif
    @End
    

    Comments removed:

    @Description
    Example for @pejman: 
    - Using the Shift button to switch between different behavior of knobs (which he refers to as "layers"). 
    - Resetting knobs to a value other than "64" on double-tap.
    - Storing different values for each layer
    - Sending different MIDI values depending on the layer
    @End
    
    @OnLoad
      if Unassigned init
        init = YES
        
        _sendLayer = 0
        _setLayer = 1
    
        layer = _sendLayer
        LabelKnobs {SEND CC}
        
        val = [90, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        num = [64, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        
        default_val = [90, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        default_num = [64, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        
        _chan = 1
    
        for knob = 0 to 9
          Call @SetKnobPosition
          Call @SetKnobLabel
        endfor
      endif
      
    @End
    
    @OnShiftDown
      if layer = _sendLayer
        layer = _setLayer
        LabelKnobs {SETTING CC}
      else
        layer = _sendLayer
        LabelKnobs {SEND CC}
      endif
      
      for knob = 0 to 9
        Call @SetKnobPosition
        Call @SetKnobLabel
      endfor
        
    @End
    
    @OnKnobChange
      knob = LastKnob
      value = GetKnobValue LastKnob
    
      if layer = _sendLayer
        if value = 64
          val[knob] = default_val[knob]
        else
          val[knob] = Round value
        endif
        SendMIDICC _chan, num[knob], val[knob]
        
      elseif layer = _setLayer
        if value = 64
          num[knob] = default_num[knob]
        else
          num[knob] = Round value
        endif
      endif
      
      Call @SetKnobPosition
      Call @SetKnobLabel
    @End
    
    @SetKnobPosition
      if layer = _sendLayer
        SetKnobValue knob,val[knob]
      elseif layer = _setLayer
        SetKnobValue knob,num[knob]
      endif
    @End
    
    @SetKnobLabel
      if layer = _sendLayer
        LabelKnob knob,{Value }, val[knob]
      elseif layer = _setLayer
        LabelKnob knob, {CC# }, num[knob]
      endif
    @End
    
  • @wim .
    There are no bugs or problems in the code you sent. All the codes were written very well and are very informative for me. I learn much better and easier this way. Thank you very much for the detailed explanation you gave me in the codes. But I don't know why the end of some lines related to the description are hidden.

    Unfortunately, I still have problems in writing the codes in terms of where exactly to write them and, for example, where ( endif ) should be placed.😅. It means that I have understood many concepts, but I have a problem with how to write them and where exactly I should put them. That's why I can't apply your tips exactly.

    I adapted this patch for layering from patch ( luanch key mk3 ). So you see signs of the words used in that patch. Like svalue[selection] , …

    Just because I wanted to learn through this patch how I can save the position of the knobs through different pads . Or, for example, I use your patch ( Basic midi controller ) so that I can create new layers through shift.

    Maybe that's why some of the examples or tips you give I can't create them in my own patch.

    For example, I asked you a question about pad layers through pads, but I still couldn't save their color in pads. I will explain more about it.

    Therefore, if possible, please show me the exact error in my patch that causes the bug I described to you.

  • @pejman : I hope you won't mind some advice. For beginners (and this is also true for advanced coders -- doing anything non-trivial), it is very beneficial before you write your actual script/code that you write out a fairly detailed pseudo-code description of what you are doing as a sort of specification of what you are doing -- without worrying about the actual code that implements it.

    This will force you to clarify your thinking AND if you do it, translating the pseudo-code into the actual script is usually faster and easier than if you start without doing that.

    Then implement one chunk of pseudocode at a time.

    A pseudocode example:

    • knobs 0 through 5 will each be able to have two values associated with them
    • one set of values (which I'll call normValues) are displayed unless the shift key is down
    • normValues will be stored in an array called normValues
    • when the shift key is down, knobs display a set of values which I'll call shiftValues
    • at startup, the normValues and shiftValues are set to default values IF this is the first time the script has run
    • if a knob's value changes when the shift key is down, the new value is stored in shiftValues
    • if the shift key is not down, knob value changes are stored in normValues

    Implement just one bullet point at a time. And test it before moving on to the next bullet point. You may find that you don't need to implement in the order you wrote it down. For example, the 'at startup' pseudocode might be the first thing that I implement

    You asked about where the ENDIFs go. The IF/ENDIF block contains instructions that you only want to happen when the IF statement is true. Sometimes, it will be obvious -- sometimes you will realize after you started writing that you need to move things into or out of the block.

    The important thing, is you should be able to walk through your code line by line and predict what can happen when a line is executed.

    I can't emphasize enough that if this doesn't come naturally (and it doesn't to most people), print out or write out the code and use a pencil and go through line by line predicting what will happen and how variable values will change.

  • wimwim
    edited May 2023

    @pejman said:
    Therefore, if possible, please show me the exact error in my patch that causes the bug I described to you.

    Sorry, I'm not going to let you off that easily. 😉

    Look at your @SetKnobPosition and @SetKnobLabel blocks.

    • In @SetKnobPosition you're using svalue[selection] and sum[selection].
    • In @setKnobLabel you're using value and num

    So, you should be asking yourself the question, "Why do num and value have the right value when I hit shift to return to the previous layer but svalue[selection] and snum[selection] do not?"

    Or, more importantly, "Why am I using different variables to label the knob than I am to position it?" (Hint: you shouldn't be.)

    Hopefully that hint will help you narrow the problem down.

    [edit] my answer in the Spoiler block above is based on the last code you posted. However, I'm no longer sure that is the code you're now referring to.

    I was going to point out that there are still some syntax errors in the @OnLoad section, which makes me wonder if I'm answering off of the same version of code that you're referring to.

  • @spiegel thanks for clear explanation. This info are very useful for me . Thank you for your time. I would like to talk more about your post.

  • edited May 2023

    Thank you again for your kind guides.@espiegel, @wim

    Dear Espiegel, I'm not at all upset with your advice. I totally understand what your purpose is.

    @wim said;

    Sorry, I'm not going to let you off that easily. 😉

    It makes me happy and encouraging that you won't leave me🙏😍.

    I have to say about the mistake in my code in @setknobposision, I did not think svalue[selection] would cause this bug because I was content with the luanch key mk3 patch. ( An uninformed imitation ).

    And I thought this was the only way to code when we wanted to save the position of Knobs ( knob layers ) via Shift or Pad.

    But if you want, I will send you the patch I wrote this way to see that they have no problem saving Knobs position via shift or pad. The only thing is that when an option like Double Tap Knob for reset, or maybe any other option I want to add to the patch, it gets bugged. I'm so glad to understand this.

    So I started deleting X[Selection] in my main patch, which I am evolving with your help.

    And again, I came across a problem similar to the previous one, which is related to the SetKnobposition being saved through the pads.
    Label knobs and send ccs works properly with [p] , means lastPad, I used it in front of cc and for labe knobs. But when I put [p] in front of the gate for setknobvalue kgate, in @Setknobpositsion , Knobs get in trouble.

    I checked everything line by line and word by word, as @spiegel suggests, but unfortunately I could not discover the problem.
    I even tried [p] in different places.
    The point is that [p] can be identified in setknoblable and send cc but not in setknobposition

    @OnLoad
    
     for knob = 0 to 9     
     
    if Unassigned init
      init = YES
     
       gate = [57,57,57,57]
       p = LastPad
       
       ccgate = [1,6,11,16]
      
                             ////for changable knobs for user 
       kgate = [5]
         
       padrevert = 0
       padrev = 4
                            
       ColorPad 0, 5 
       
       endif
    
        Call @SetKnobPosition
        Call @SetKnobLabel
     endfor
    
    LabelPads {TRACKS } 
    
    LabelPad 0, {1️⃣} 
    LabelPad 1, {2️⃣} 
    LabelPad 2, {3️⃣} 
    LabelPad 3, {4️⃣} 
    
    @End
    
    
    @OnPadDown
    
    p = LastPad  
      for knob = 0 to 9
      
        Call @SetKnobPosition
        Call @SetKnobLabel
      endfor
    
    if LastPad >=0 and LastPad <=3
          
          ColorPad padrevert, 0
          ColorPad LastPad, 5
          padrevert = LastPad
               
    if LastPad = 0 
    LabelKnobs {TRACK 1} 
    
    elseif LastPad = 1 
    LabelKnobs {TRACK 2} 
    
    elseif LastPad = 2 
    LabelKnobs {TRACK 3} 
    
    elseif LastPad = 3 
    LabelKnobs {TRACK 4} 
    
    endif
    endif
                 
    @End 
    
    
    @OnKnobChange
    
    knob = LastKnob           
    value = GetKnobValue 
    
    for p = 0 to 3    
    p = LastPad
    
    gate = GetKnobValue kgate  
    if LastKnob = kgate
    SendMIDICC 1, ccgate[p], gate 
    
    endif
    endfor
    
    Call @SetKnobPosition
    Call @SetKnobLabel
    
    @End 
    
    
    @SetKnobPosition       
    
    for p = 0 to 3    
     p = LastPad
    
      //if knob = kgate             
        gate = GetKnobValue kgate
        SetKnobValue kgate, gate[p]    ////?????
        
      //endif
      endfor
    @End
    
    
    @SetKnobLabel         
    
       for p = 0 to 3    
     p = LastPad
    
    gate = GetKnobValue kgate
    lgate = Round TranslateScale gate, 0,127,-100,100
    LabelKnob kgate, {GATE}, { } ,lgate
         if LastKnob = kgate
         LabelKnobs {Track  },p+1,{  GATE},{  },lgate
        endif   
    endfor
    
      @End
    
  • @pejman : have you added log lines liberally to your code to watch the variable values to see if they match your expectations?

    Look at your for loops. Do a written simulation of what happens to p in each iteration of the loop when they are triggered.

Sign In or Register to comment.