Script Scripts Help

JBDS1252 views5 posts
  • JBDS1

    Hi Mangus ,can you please help me to modify the script that loads different patches “ peak new patches “ please !
    The original script pics patches from the folder called “ All “ ( picture A,B ) and i guess it taking patches from the subfolder By category ( picture C ) . What I want it to change the factory folder, with one of my own ( picture D, E ) . Let say I have that folder full with patches containing all the subcategory patches , but all in one folder. So instead of looking in the subcategory folders, I want Microtonic to look in only One folder that contain all of the categories, my own folder G01. The way I did it it's not working because Microtonic it's trying to look in the subcategory folders and i got error [-43] and it dosen't load anything.
    The second thing is that when no matches were found Microtonic doesn't do anything (see picture F). Well in my folder, I have patches that doesn't contain the subcategory prefix and I want this line to be changed like this : When no prefix matches found, make Microtonic choose a Random patch that doesn't contain the prefix ! With other words, when no prefix found choose random patches with no prefix. For example : if the patch I tried to change it's called Focus_02 (this it a file with no prefix) let Microtonic to chose patches with no prefix.
    Can you Please modify the original script with this changes ? Thank you

    A.png

    B.png

    C.png

    D.png

    E.png

    F.png
  • Fredrik Lidström

    Hey, a script hacker, I like it!

    It actually looks like it is searching in the "All" folder only and switching it to G01 should work for you.

    I'll try to break down the script and explain the different parts of it. I didn't write it, but hopefully, I understand it correctly. 😊

    	if (!exists(@::PickNewPatches.inited)) {
    		print('Building ::PickNewPatches');
    		dir(drumDir, >{
    			if (wildmatch($0, '*.mtdrum'))
    				append(@::PickNewPatches.drums, $0);
    			if (wildmatch($0, '??~~ {??~~~~~~} ?*.mtdrum', @category))
    				append(@::PickNewPatches.drumsByCategory[upper(category)], $0);
    		});
    		::PickNewPatches.inited = true;
    	};
    

    This part initializes the script by listing all files in the drumDir folder and then populating two arrays.
    The PickNewPatches.drums array contains the name of each patch.
    The wildmatch($0, '??~~ {??~~~~~~} ?*.mtdrum', @category) line is where the category "magic" happens. With our patch naming conventions like KM Clap Rombi.mtdrum it skips the first 2-4 characters and then captures the next 2-8 characters into the category variable. So in this case the category will be Clap. You can read more about how wildmatch works here.

    	getElement('preset', @p);
    	pickedCount = 0;
    	for (ch = 1; ch <= CHANNEL_COUNT; ++ch) {
    		if (p.Mute[ch] < 0.5) {
    			dp = @p.drumPatches[ch];
    			if (pick('??~~ {??~~~~~~} ?*') || pick('{??~~~~~~} ?*'))
    				++pickedCount;
    		}
    	};
    

    Here it gets the current preset and loops through all drum channels. For each channel that is not muted, it tries to pick an alternative drum channel using the pick function. Please note here that it calls pick twice, because it does support if you have creator prefix in your current drum patch names or not. Like FL SD Fat or SD Snappy.

    	pick => {
    		if (wildmatch([dp].name, $0, @category)
    				&& exists(@[a = @::PickNewPatches.drumsByCategory[upper(category)]].n)) {
    

    Here you can see that the pick function uses the input variable $0 as the match pattern to figure out the category of your currently loaded patch. It assigns the category array to a and checks that it exists.

    			i = randomInt() % [a].n;
    			path = drumDir # [a][i];
    			s = load(path);
    

    [a].n here will be the length of the category array, so we use random to pick one and then load it in.

    			origOutput = [dp].Output;
    			origChoke = [dp].Choke;
    			unmarshal('drumPatch', s, @[dp]);
    			[dp].name = chop([a][i], 7);
    			[dp].path = path;
    			[dp].Output = origOutput;
    			[dp].Choke = origChoke;
    

    Copies the current Output and Choke settings and applies them to the newly loaded patch.

    So if I understand you correctly, what you want to do is pick any random drum if you cannot match a category. You could do that by modifying the pick function, but the easiest way would be to just copy it. Something like this:

    	pickRandom => {
    		a = @::PickNewPatches.drums;
    		i = randomInt() % [a].n;
    		path = drumDir # [a][i];
    		s = load(path);
    		assert(> isMarshaledFormat('drumPatch', s));
    		origOutput = [dp].Output;
    		origChoke = [dp].Choke;
    		unmarshal('drumPatch', s, @[dp]);
    		[dp].name = chop([a][i], 7);
    		[dp].path = path;
    		[dp].Output = origOutput;
    		[dp].Choke = origChoke;
    		( true )
    	};
    

    and then add it to the picking process like

    			if (pick('??~~ {??~~~~~~} ?*') || pick('{??~~~~~~} ?*') || pickRandom())
    				++pickedCount;
    

    Disclaimer, I have not tested it, so I might have made a mistake somewhere. 😁

  • Fredrik Lidström

    Ah, I see now that you want it to only match patterns with no prefix if there is no prefix in the current patch? That makes it a bit harder, but it would go something like identifying the drum patches without a category in the init script and adding it to a non-category, like.

    			if (wildmatch($0, '??~~ {??~~~~~~} ?*.mtdrum', @category)) {
    				append(@::PickNewPatches.drumsByCategory[upper(category)], $0);
    			} else {
    				append(@::PickNewPatches.drumsByCategory["unknown"], $0);
    			}
    

    and then randomize from the ::PickNewPatches.drumsByCategory["unknown"] category only when there is no category detected in the current patch name.

  • JBDS1

    Hi thank you for this complex answer but first let me tell you something :

    1. I don't know nothing about programming or coding :))))
    2. I am a human I can think

    Now, take it one by one :

    1. The Case where I change only the name of the folder :
      Here the problem was not the folder or the code, it was about the names of the patches! I've got to tell you that I made that folder G01 by exporting all the batches from G01 patternarium folder that someone uploaded here on your forum. And the names are missing those first two letters and because of this the script skips the two letters and sees all the names even if the two letters are actually the type of the drum. So for this case where I change only the name of the folder it will be interesting to modify the script so he will not skip the first two letters which are actually a drum category please see the pictures. These are the names that Microtonic script export patches came up after the export. We can of course modify the export script to not skip those two letter before, I'm not sure which one is the best option: to change the script that exports or to change the script that changes new patches.

    Screenshot 2021-12-09 at 13.33.11.png

    Screenshot 2021-12-09 at 13.33.05.png

    Screenshot 2021-12-09 at 13.32.38.png

    Screenshot 2021-12-09 at 13.33.32.png
    1. Another thing that I noticed it's, if I choose patches from the G01 folder first, I mean all the patches, original script it's changing patches, but not all of them. And if, after changing the folder name, and try again the original script, I got a erros finding patches. From here I presume that the scripts understand to change patches only for the selected patch folder, meaning if all my patches in the individual drum slot, are chosed from the folder All, the the script will choose only patches from All folder.. If I change the name of the script to G01 folder, but all the individual drums are chosen from the All folder, then the script will have an error of finding patches. wierd
    1. After reading carefully what you told me I managed to understand and modify the script. funny right, regarding the fact that I don't know nothing about scripts and coding :)))) .. and made 2 scripts :)

    1 it not working and i got this error :

    Screenshot 2021-12-09 at 14.57.55.png

    it this script
    Pick New Patches3.pika(2.79kB, 520 downloads)

    I don't know that 'n' letter came from :)))

    The second script that they made it working, but it's too random and I don't think it follows the drum category protocol, which is kind of important I guess :))) I mean I want him to change patches randomly but when he find the prefix I want him to change drum patches with the same prefix. it this script
    And again if the patcher are from a different folder , it got the Not founding patches error .

    Pick New Patches4.pika(2.38kB, 532 downloads)

    At the end I will say again what I'm trying to achieve:
    a script that understand first two letters as a category ( because of the export script language),
    a script that understand patches with no category,
    a script that randomly choose patches with the same category and randomly choose patches with no category,
    a script that understand the folder that has been give it to him from where to choose patches,

    I hope you will find my answer funny and interesting... :))))) thank you for your help

  • JBDS1

    UPDATE:
    I realise that when I'm changing patches with the original script with folder 'All', I have to quit and restart Microtonic to be able to use the second script which contains patches in the 'G01' folder. The script understand the folder that exists in the script you trying to use, And if you change the script that has different folder, he needs to be restarted, I don't know why . In this test I was using the Original script 'Pick New Patches' with folder 'All' and my new created the script called 'Pick New Patches4.pika' with folder 'G01'

You need to be to post a reply

Sign In / Sign Up


First time here? Just enter your current email and sign up.
×
Facebook sign in no longer available. Use the same email to set password and access your account. If you need help, contact us.