• SONAR
  • Randomizing Note Lengths in the Interpolate Dialogue Box
2017/02/21 01:24:10
jsg
I thought I figured out how to do this, but now I can't get it to work.
Does anybody use Interpolate to randomize, say, 4 quarter notes into 4 notes with slightly less and slightly more duration?
The Length command is good for precise change relative to start time, but not for randomizing note lengths.
 
Thanks,
Jerry
 
 
 
2017/02/21 03:32:54
promidi
Have you considered using a CAL script to do this?  The following script will randomise the duration of selected notes away from their original to a maximum possible of 30 (defined by the  (int range 30) )

(do
    (int offset)
    (int range 30)
    (int new_duration)
    (int pos_range range)
    (int  neg_range (*= range -1))
    (forEachEvent
        (if (== Event.Kind NOTE)
            (do
                (= offset (random neg_range pos_range))
                (= new_duration Note.Dur)
                (+=  new_duration offset)
                (if (<= new_duration 127)
                    (if (>= new_duration 0)
                        (= Note.Dur new_duration)
                    );end if
                );end if
            );end do
        );end if
    );end for
);end do
2017/02/21 03:45:09
Bristol_Jonesey
Great solution there Paul!
2017/02/21 14:59:05
jsg
promidi
Have you considered using a CAL script to do this?  The following script will randomise the duration of selected notes away from their original to a maximum possible of 30 (defined by the  (int range 30) )

(do
   (int offset)
   (int range 30)
   (int new_duration)
   (int pos_range range)
   (int  neg_range (*= range -1))
   (forEachEvent
       (if (== Event.Kind NOTE)
           (do
               (= offset (random neg_range pos_range))
               (= new_duration Note.Dur)
               (+=  new_duration offset)
               (if (<= new_duration 127)
                   (if (>= new_duration 0)
                       (= Note.Dur new_duration)
                   );end if
               );end if
           );end do
       );end if
   );end for
);end do




Hey, thanks!    I am almost certain I can do this with the Interpolation routine, but if I can't I'll use the CAL code above.   By the way, when I paste this into a .txt file, how do I turn it into a CAL file?  Sonar won't read it as a CAL file if it has an extension of .txt..
 
UPDATE:  I was able to turn the file into a .CAL file, and tried running it on some music.  It didn't do anything at all, there was no dialogue box to ask me how much variation I want, nothing.   I copied and pasted the exact code you gave...
 
Best,
Jerry
www.jerrygerber.com
 
2017/02/21 15:03:46
scook
Change the extension to .cal
2017/02/21 15:08:22
Atsuko
And if you want an editor, you can download from here: http://www.softpedia.com/...itors/CAL-Editor.shtml
2017/02/21 15:50:47
berlymahn
Atsuko - thank you.
2017/02/22 00:00:40
SquireBum
Jerry,
  I took the liberty of modifying the script by @promidi by adding an input field in ticks and removed the line that was preventing the script from setting the new duration.  I tested it, but please use it at your own risk.
 
-- Ron
 
;;Randomize duration
;;This script will randomize MIDI note duration based on a user
;;provided range in ticks from 1 to 240 ticks.  Checks are
;;provided to prevent zero durations.
;;
;;
(do
    (int offset)
    (int range 30)            ;; Change default input value here
    (getInt range "Select +/- range (ticks): " 1 240)
    (int new_duration)
    (int pos_range range)
    (int  neg_range (*= range -1))
    (forEachEvent
        (if (== Event.Kind NOTE)
            (do
                (= offset (random neg_range pos_range))
                (= new_duration Note.Dur)
                (+=  new_duration offset)
                (if (>= new_duration 0)  ;; Make sure calculated duration is not zero
                        (= Note.Dur new_duration)
                );end if
            );end do
        );end if
    );end for
);end do
2017/02/22 02:40:32
jsg
SquireBum
Jerry,
  I took the liberty of modifying the script by @promidi by adding an input field in ticks and removed the line that was preventing the script from setting the new duration.  I tested it, but please use it at your own risk.
 
-- Ron
 
;;Randomize duration
;;This script will randomize MIDI note duration based on a user
;;provided range in ticks from 1 to 240 ticks.  Checks are
;;provided to prevent zero durations.
;;
;;
(do
   (int offset)
   (int range 30)            ;; Change default input value here
   (getInt range "Select +/- range (ticks): " 1 240)
   (int new_duration)
   (int pos_range range)
   (int  neg_range (*= range -1))
   (forEachEvent
       (if (== Event.Kind NOTE)
           (do
               (= offset (random neg_range pos_range))
               (= new_duration Note.Dur)
               (+=  new_duration offset)
               (if (>= new_duration 0)  ;; Make sure calculated duration is not zero
                       (= Note.Dur new_duration)
               );end if
           );end do
       );end if
   );end for
);end do




Thanks very much SquireBum, much appreciated.  I tested it and it does exactly what I was trying to do.
 
Thanks for tweaking it!
 
Best,
Jerry
www.jerrygerber.com
 
2017/02/22 07:06:52
chuckebaby
This is very interesting to me as I don't use CAL scripts.
It seems they have a lot to offer. I don't use Midi all that much, maybe 20% of my project has midi, the rest being Audio (stringed instruments, drums, vocals, exc).
 
However CAL scripts is something I would like to learn more about. some good reads here in this thread (Promidi, Ron and others) Interesting stuff. thanks.
12
© 2026 APG vNext Commercial Version 5.1

Use My Existing Forum Account

Use My Social Media Account