Need Help to Save and Load Presets of Multiple Objects

Discuss problems and solutions.
tater01
Newbie
Posts: 38
Joined: 24 Jan 2016 19:17

Need Help to Save and Load Presets of Multiple Objects

Post by tater01 »

Ok, so I'm trying to build a drum sequencer and be able to store and load presets in a set of pads. I've started with the example given with the Lemur editor where there are two sets of 16 pads, one named store and the other named load. And the pads store and load presets of a multislider. I am using the same example but I want it to control several different stepswitches. So I can store and load presets of the stepswitches. So there are stepswitches named kick, snare, ride, etc. The stepswitches are each 16 buttons long.

So, first there is a container, named container. At the container level I have two expressions and a script:

presets=
presets_state=
init()

This is the script in the init is: if (sizeof(presets_state)<16) presets_state = stretch(0,16);

Then I copied the pads from the preset multislider example, store and load. Both 16 pads each.

The store pad has a script: action(). The script is executed on expression of x and contains this code:
decl index;
decl num = sizeof(x);
for (index=0; index<num; index++)
{if (x[index]){presets_state[index] = 1;presets[index*16] = {Kick.x};}}

The load pad has a script: action(). The script is executed on expression of x and contains this code:
decl index = firstof(x);
if (index>=sizeof(x)) return;
decl i;
for (i=0; i<16; i++)
{Kick.x = presets[index*16+i];}

So, this works for one stepswitch "kick." I need help getting it to control more than one of the stepswitches, Snare, ride, etc. Can anyone help me change these scripts to control more than one stepswitch at a time?

Also, just as an extra, not necessary. If anyone is smart enough to make it play through the presets. Like you can save 16 presets on the pads. It would be cool if when you hit play on the sequencer, it plays through all the presets sequentially!
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: Need Help to Save and Load Presets of Multiple Objects

Post by oldgearguy »

The summary is to make an array of the switch names, then loop through that array and use findobject() to get each object, then use getexpression()/setexpression() to get and set values as needed.
There's likely more clever ways to use the objects and container directly to get all the names, but I don't have a Lemur or the code you referred to here with me.

I'll try to gen up some code this weekend to show it in detail.
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: Need Help to Save and Load Presets of Multiple Objects

Post by oldgearguy »

It might be faster to simply attach your current version to a message rather than trying to work more abstractly.

Attached is a simple way to do what I was talking about. See if that helps.
Attachments
stepping.jzml
(11.61 KiB) Downloaded 121 times
tater01
Newbie
Posts: 38
Joined: 24 Jan 2016 19:17

Re: Need Help to Save and Load Presets of Multiple Objects

Post by tater01 »

Thanks for your help oldgearguy. I really appreciate it, as I just have very basic programming skills. So thank you!
Here's is the lemur example of how to make presets of a multislider:
Lemur Presets Example.jzml
Liine's example
(32.72 KiB) Downloaded 115 times
Here is what I want it to do but with more than one stepswitch. I can get it to work for the first stepswitch "Kick"
Stepswitch Presets.jzml
What I want it to do
(32.72 KiB) Downloaded 98 times
That seems like an awful lot of code in your example, whew that looks scary compared to what liine did with the multislider!

Thanks again!

**Edit**
I looked yours over, and it's actually kinda of awesome. Instead of having the pads to save presets, you made dedicated save and load buttons! Very cool. I will check it out and post back. Thanks!
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: Need Help to Save and Load Presets of Multiple Objects

Post by oldgearguy »

I'll pull up what you attached when I have some time later today with the Lemur in front of me.
It's more challenging reading the raw .jzml file and trying to understand the intent - with the Lemur up, it's easier to see what you wanted to have happen.

The main idea I wanted to get across (whether you use separate pads or a single button) is that you can find objects (like pads or step switches) and then adjust their values. That's the findobject()/getexpression()/setexpression() stuff.
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: Need Help to Save and Load Presets of Multiple Objects

Post by oldgearguy »

I'll adapt my example to allow you to save and restore multiple presets like the example. Just need a day or so to get some free time.
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: Need Help to Save and Load Presets of Multiple Objects

Post by oldgearguy »

Here's a version that saves/loads all 4 rows.

I didn't comment the code (yet), so if you have any initial questions, ask away.
Attachments
StepSwitches.jzml
(24.04 KiB) Downloaded 93 times
tater01
Newbie
Posts: 38
Joined: 24 Jan 2016 19:17

Re: Need Help to Save and Load Presets of Multiple Objects

Post by tater01 »

Cool! Thanks again oldgearguy. Downloading now! Will post back within a few days.
tater01
Newbie
Posts: 38
Joined: 24 Jan 2016 19:17

Re: Need Help to Save and Load Presets of Multiple Objects

Post by tater01 »

Ok, couldn't wait! First off, you are my f-ing hero! Thank you for being so smart and such a kind person to help out complete strangers!!! You are the best!
You're presets work awesome! Thank you very much. I think I semi understand about get object, setexpression stuff. Kinda lose me when you declare so many variables though.
So, again thank you! It works great! I am going to bug you for some more favors though. Since you are so smart and seem up to the challenge!
My new obstacle is that I would like to be able to make it 64 presets but use only the 4x4 pads, just use 4 sets of 4x4 pads to make a total of 64 presets. I kinda set it up using your preset buttons and made four sets of save/load pads. But, the extra sets of pads only mirror the first 16. So how do I make it 64 presets? Change the index to 64? Here is my page I am working on:
Examples.jzml
Stepsequencer
(118.44 KiB) Downloaded 73 times
Sorry for the small resolution, I have an old Galaxy Tab 2!

Also, if you don't mind. I put in a copy and paste pad and was hoping you could make them work for me too! Sorry for being so needy! I'm not that great a programmer, very noob!

Lastly, I know this is probably hard to script so I don't expect you to do it for me. I know it probably takes some time to script. But if you can, make it so that when you hit play it plays through all the presets sequentially. So I could basically program a whole song. Different parts to different presets, then play through them, A1,A2,A3, ....A16,B1,B2,B3,....B16,etc.

Thank you in advance for any and all of your help. You are a great person and very kind to script those buttons for me!

Thanks!!!
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: Need Help to Save and Load Presets of Multiple Objects

Post by oldgearguy »

I'll take a look when I have some time this weekend.

A couple things -
In the land of Lemur, 256 is a magic number. Strings, arrays, sysex messages, etc cannot be longer than 256. That's why I had each drum part save it's own data. 16 steps x 16 presets = 256 things being stored. If you want 64 presets, you have to jump through additional hoops to make it happen.

I haven't used the StepSwitch objects in a real application yet. I don't know how tight the timing will be switching between patterns while it's running. Probably at lower BPMs it'll be fine, but again - that's something to experiment with and see. Coding it up to efficiently switch will help, but there is a limit as to how quickly the Lemur app can process the information.

Also, I will document the code with comments to hopefully provide more explanation as to why some things were done a certain way. The goal is for you to understand what is happening and give you the ability to extend/modify it as needed.

If you don't really need a separate container for the pads I might delete that and move the contents up into the main container. Nesting objects like that, especially with the same name, can make it confusing to read through.


Finally - I have been fooling around with an updated version that allows you to dynamically set the number of steps for each drum row and I added a Start/Stop button and BPM knob. I am attaching it just to give you things to think about. The row length is not saved with the preset in this version. Once you start playing with it, more questions come up like if you have variable length rows, when do you switch to the next preset - after 16 steps always, follow the kick, or something else? There's the issues of starting from a preset other than 0 and how do you set the marker to indicate the last preset to play before looping back to the beginning? What do you do with empty presets - skip them or play them? (you might want a bar of rests)

Basically, you're (re)designing a step sequencer, so it can get as complicated as you want.

For your example, I might want to get everything else working (playing through each saved preset, copy/paste, etc) then figure out the expansion to 64 presets.
Attachments
StepSwitchesPlus.jzml
(42.59 KiB) Downloaded 91 times
Post Reply