Loopy Pro: Create music, your way.

What is Loopy Pro?Loopy Pro is a powerful, flexible, and intuitive live looper, sampler, clip launcher and DAW for iPhone and iPad. At its core, it allows you to record and layer sounds in real-time to create complex musical arrangements. But it doesn’t stop there—Loopy Pro offers advanced tools to customize your workflow, build dynamic performance setups, and create a seamless connection between instruments, effects, and external gear.

Use it for live looping, sequencing, arranging, mixing, and much more. Whether you're a live performer, a producer, or just experimenting with sound, Loopy Pro helps you take control of your creative process.

Download on the App Store

Loopy Pro is your all-in-one musical toolkit. Try it for free today.

Mozaic: working with arrays: how to iterate, get size, etc.?

I'm currently working with arrays a lot, and I seem to miss some important features in the Mozaic manual, e.g. how to iterate over the values of an array, or how to get the size of an array (how many items it contains), or how to append and remove elements from an array.

I will probably add more questions when they arise...

Thanks a lot for help. And still: if there's a better place to ask such questions, please tell me. :wink:

Comments

  • wimwim
    edited August 2020

    If you know the number of elements in an array, you can just use a for loop:

    for idx = 0 to 9
      Log array[idx]
    endfor
    

    If you don't then it's best to fill the array with something identifiable like -1 then react accordingly

    lastIndex = 0
    while (array[lastIndex] <> -1) and (lastIndex < 1024)
      Inc lastIndex
    endwhile
    

    There aren't any functions for inserting or removing elements. I have some source code for removing elements around somewhere. I'll see if I can find it.

  • You are going to be shocked at how primitive Mozaic is but you will need to accept
    that is more than a compiler of high level commands... It's a real time executive engine
    with the promise of managing milli-second events without any dropouts. @brambos is
    very careful to limit the complexity of the code we can write so the interpreter in the engine
    doesn't get consumed by looping over variables or processing "text" and miss a MIDI
    time-based event.

    All arrays are 1024 elements by default. You can fill an array to a predetermined value
    and then when you get one of those values that's the end of the valid entries.

    FillArray recordbuffer, -1

    Iterate arrays using any of the looping statements and increment an index into the array.
    There are 3 types of loops available: “for”-loops, “while”-loops and “repeat until”-loops.

    You can add a new value anywhere in an array at any time so if your keeping an index for
    the last element you append with:

    new_data = 100
    my_array[index + 1] = new_data
    Inc index

    Good tips from @_Ki here:

    https://wiki.audiob.us/doku.php?id=mozaic_tips_and_tricks

    And @brambos here:

    http://ruismaker.com/wp-content/uploads/Mozaic.pdf

  • Ouch, this feels a lot like smelly code! Thanks, I'd be very happy for some help with modifying arrays. The way Mozaic creates and handles them feels very strange to me... Never seen this in a programming language before, and I've seen quite a few already. :wink:

  • You could have asked these questions in the Mozaic Helpline thread :)

    Its simple - all variables are in fact arrays with 1024 elements starting with index 0. If you just write a = 4 this sets the 0 element of a, its the short form of a[0] = 4

    You have to manage the number of stored elements by yourself, for instance in another variable named count.

    Here a short example for iteration and a count variable.

    @OnLoad
      a = [3,1,4,1,5,9]
      count = 6
      For i = 0 to count -1
        Log {a[}, i, {]=}, a[i]
      Endfor
    @End
    
  • _ki_ki
    edited August 2020

    Oh - two other answers, i‘m late to the Helpline party B)

    Will there be music and drinks ? Dancing ? Oh, oh what should i wear ? Probably just black

  • Ok, I see why Mozaic is limited in some respects. I will write my own array handler then.

    Another question: is there an easy way to debug an array? Ie. display its contents using Log?

  • @josh83 said:
    Ouch, this feels a lot like smelly code! Thanks, I'd be very happy for some help with modifying arrays. The way Mozaic creates and handles them feels very strange to me... Never seen this in a programming language before, and I've seen quite a few already. :wink:

    Think of it as a friendly "event-based" machine language with the machine being the MIDI Execution Engine it manages. It's as important for what it leaves out as for what it includes. Most of the grumbling from the heavy users of the language complain about the lack of character types for use in the GUI.
    You have to make big "if" trees to map a number to a text label for example.

    Anyway. It's sounds like you should code in Swift using Xcode. I'll bet you can't create a more efficient
    interpreter for a MIDI engine.

    For comparison... check out the StreamByter language in "MidiFire". Also very good at managing time-based events but even closer to assembly in syntax.

    Take it as a challenge. Lot's of great examples at:

    https://patchstorage.com/platform/mozaic/

  • heshes
    edited August 2020

    @josh83 said:
    Ok, I see why Mozaic is limited in some respects. I will write my own array handler then.

    Another question: is there an easy way to debug an array? Ie. display its contents using Log?

    Well, you just loop over it and log the values as _ki showed a post or two ago.

    Visually, it's not ideal because 'log' statement always has a carriage-return appended, so you get one value per line. (One of my suggestions for new "feature" is to allow appending a control character to the log string that suppresses the new line, allowing better tailoring of log output. Or just a second log statement: log-no-cr.)

  • wimwim
    edited August 2020

    Here are a couple of quickly written subroutines by way of example. I'm sure others can provide more elegant examples.

    @OnLoad
      FillArray array,-1
      array[0] = [0,1,2,3,4,5]
    
      Call @PrintArray
      Call @ArrayCount
    
      valueToFind = 4
      Call @FindValue
      Call @RemoveIndex
      Call @PrintArray
      Call @ArrayCount
    @End
    
    @PrintArray
      Log {Array contents: }
      index = 0
      while array[index] <> -1 and index < 1025
        Log {  },index,{: },array[index]
        Inc index
      endwhile
    @End
    
    @ArrayCount
      count = 0
      while array[count] <> -1 and count < 1024
        Inc count
      endwhile
      Log {Array has }, (count), { values.}
    @End
    
    @RemoveIndex
      Call @FindValue
      if index <> -1
        while array[index] <> -1 and index < 1024
          array[index] = array[index+1]
          Inc index
        endwhile
      endif
    @End
    
    @FindValue
      index = 0
      while array[index] <> valueToFind and array[index] <> -1 and index < 1024
        Inc index
      endwhile
      if array[index] <> valueToFind
        index = -1
      endif
    @End
    
  • wimwim
    edited August 2020

    BTW, while something like the @RemoveIndex routine above seems expensive for a large array, I was very surprised at how efficient the processing is and what I could get away with even within a 1ms timer interval for operations like this.

Sign In or Register to comment.