I attached an example that will do something like what you want, using list abs.
Without much trouble you could make this into an abstraction.
It follows the first solution someone posted -- pick a bunch of random numbers and then scale them so the total equals the target. I added a few things, though -- it also rounds the numbers to the nearest subdivision that you specify, and it goes through the list and moves anything lower than the min or higher than the max duration to the min or max, compensating elsewhere, until all the durations are in range. I capped the number of searches for outliers to 1000, but you could change that or get rid of it as need be.
I haven't tested this thoroughly, so let me know.
MB
Note that if you sum 1+2+3+4+5+6+7+8+9+10, that's already 55. How many time units do you have per 48 seconds ? (do you have a base tempo at all ?)
And then what do you want the distribution to be like ? Is there any maximum duration of a chord, minimum duration of a chord, etc ?
It's funny that you said that. I slept over this problem and yes, I want the chords to have a minimun and maximun duration. They don't need to bee all of different durations, the important is this section of the piece to sound like random/chaotic durations, and as we know random numbers (or durations?) sometimes don't look random. I will even make this again for the attacks of individual notes of the chords so the section will have a truly chaotic feeling. And by the way the tempo of this section is quarter = 60 so it's very easy to do this. (thank you Mathieu for making me think about it more deeply)
Thank you guys for the other answers. This really helps.
Caio Barros
Whoa! Nice! It worked very well here. Although sometimes I have to press the "Go" button more than once to get different results, even when I change the paramethers. Will do some more testing. I need some time to understand this patch but it looks awesome.
2011/3/4 Matt Barber brbrofsvl@gmail.com
I attached an example that will do something like what you want, using list abs.
Without much trouble you could make this into an abstraction.
It follows the first solution someone posted -- pick a bunch of random numbers and then scale them so the total equals the target. I added a few things, though -- it also rounds the numbers to the nearest subdivision that you specify, and it goes through the list and moves anything lower than the min or higher than the max duration to the min or max, compensating elsewhere, until all the durations are in range. I capped the number of searches for outliers to 1000, but you could change that or get rid of it as need be.
I haven't tested this thoroughly, so let me know.
MB
Note that if you sum 1+2+3+4+5+6+7+8+9+10, that's already 55. How many
time
units do you have per 48 seconds ? (do you have a base tempo at all ?)
And then what do you want the distribution to be like ? Is there any maximum duration of a chord, minimum duration of a chord, etc ?
It's funny that you said that. I slept over this problem and yes, I want
the
chords to have a minimun and maximun duration. They don't need to bee all
of
different durations, the important is this section of the piece to sound like random/chaotic durations, and as we know random numbers (or
durations?)
sometimes don't look random. I will even make this again for the attacks
of
individual notes of the chords so the section will have a truly chaotic feeling. And by the way the tempo of this section is quarter = 60 so it's very
easy
to do this. (thank you Mathieu for making me think about it more deeply)
Thank you guys for the other answers. This really helps.
Caio Barros
Sorry for the lack of comments. It's kind of a brute-force method; maybe I'll go through and document it at some point, but I just threw it together today to show the concept. A couple of things: if your max and min durations are restrictive you get an awful lot of values at the max and min (whereas you might want to randomize the corrected outliers within a certain range so that you get values that hover a certain random amount above the min or below the max).
Also, the total number of beats should be quantized to the nearest subdivision but I didn't worry about that. I guess it's the user's responsibility.
Not sure about the go button, seems to work here. At some point you might wish to add a seed for the random if you don't want things to repeat from the last time you opened the patch.
Matt
On Fri, Mar 4, 2011 at 6:57 PM, Caio Barros caio.barros@gmail.com wrote:
Whoa! Nice! It worked very well here. Although sometimes I have to press the "Go" button more than once to get different results, even when I change the paramethers. Will do some more testing. I need some time to understand this patch but it looks awesome.
2011/3/4 Matt Barber brbrofsvl@gmail.com
I attached an example that will do something like what you want, using list abs.
Without much trouble you could make this into an abstraction.
It follows the first solution someone posted -- pick a bunch of random numbers and then scale them so the total equals the target. I added a few things, though -- it also rounds the numbers to the nearest subdivision that you specify, and it goes through the list and moves anything lower than the min or higher than the max duration to the min or max, compensating elsewhere, until all the durations are in range. I capped the number of searches for outliers to 1000, but you could change that or get rid of it as need be.
I haven't tested this thoroughly, so let me know.
MB
Note that if you sum 1+2+3+4+5+6+7+8+9+10, that's already 55. How many time units do you have per 48 seconds ? (do you have a base tempo at all ?)
And then what do you want the distribution to be like ? Is there any maximum duration of a chord, minimum duration of a chord, etc ?
It's funny that you said that. I slept over this problem and yes, I want the chords to have a minimun and maximun duration. They don't need to bee all of different durations, the important is this section of the piece to sound like random/chaotic durations, and as we know random numbers (or durations?) sometimes don't look random. I will even make this again for the attacks of individual notes of the chords so the section will have a truly chaotic feeling. And by the way the tempo of this section is quarter = 60 so it's very easy to do this. (thank you Mathieu for making me think about it more deeply)
Thank you guys for the other answers. This really helps.
Caio Barros
Sorry for the lack of comments. It's kind of a brute-force method; maybe I'll go through and document it at some point, but I just threw it together today to show the concept. A couple of things: if your max and min durations are restrictive you get an awful lot of values at
the max and min (whereas you might want to randomize the corrected
outliers within a certain range so that you get values that hover a certain random amount above the min or below the max).
I noticed that.
Also, the total number of beats should be quantized to the nearest subdivision but I didn't worry about that. I guess it's the user's responsibility.
I'm not shure if I understood that. You mean that if I set the "nuber of subdivisions per beat" as 10 I can't set the number of beats to, say 8,255? As far as user's responsibility goes, it doesn't make sense to input negative numbers, yet it is possible.
Not sure about the go button, seems to work here. At some point you might wish to add a seed for the random if you don't want things to repeat from the last time you opened the patch.
Maybe I'm restricting the paramethers too much so the program doesn't have many options. Hence the repetitions of results. I don't know.
Anyway, nice work. I didn't work yet with all those list objects, so I need to learn them a bit. Also, for my purposes I'm thinking of implementing two other tools to this soon-to-be abstraction:
intervals (with max and min defined by the user) running together with a chronometer. So it outputs the exact time of the bangs. Maybe it could output two times: the overall duration since the chronometer started and the interval between tha bang and the last one, very easy to do.
user inputs the tempo. That's something that I saw once as an MS Excell spreadsheet that the spanish composer Jose Manuel Lopez Lopez had and is soooo useful. I remember that it even had many tempos side by side so the composer could know when the triplet in tempo x is equal to sixteenth in tempo y, à la elliott carter. I also have a friend that wanted to do that, maybe we can team up.
I'm not shure if I understood that. You mean that if I set the "nuber of subdivisions per beat" as 10 I can't set the number of beats to, say 8,255? As far as user's responsibility goes, it doesn't make sense to input negative numbers, yet it is possible.
I think we're saying the same thing, if you're using the comma the way americans use the dot for indicating decimal; did 8,255 mean "8 + 255/1000"?
Briefly -- it means that if I set the "subdivisions" to 4 (i.e. the "rhythms" will be quantized to "sixteenth notes"), I will not be able to generate something that lasts a total of 25.2 beats, since 25.2 is quantized to 5 subdivisions per beat ("sixteenth-note quintuplets).
Matt
2011/3/4 Matt Barber brbrofsvl@gmail.com
I'm not shure if I understood that. You mean that if I set the "nuber of subdivisions per beat" as 10 I can't set the number of beats to, say
8,255?
As far as user's responsibility goes, it doesn't make sense to input negative numbers, yet it is possible.
I think we're saying the same thing, if you're using the comma the way americans use the dot for indicating decimal; did 8,255 mean "8 + 255/1000"?
Briefly -- it means that if I set the "subdivisions" to 4 (i.e. the "rhythms" will be quantized to "sixteenth notes"), I will not be able to generate something that lasts a total of 25.2 beats, since 25.2 is quantized to 5 subdivisions per beat ("sixteenth-note quintuplets).
Oh yes, we are saying the same thing. Sorry for the comma, I always forget that. Even in pd sometimes I keep trying to write 0,25 in a number box and get angry because it doesn't work. One more thing. How hard it is to make possible for the user to choose between the random output that you already made and to sort that output from the smallest to longest duration and vice-versa?
Check out [list-sort] for short lists, [list-shellsort] for much longer ones (I don't remember at what point the shellsort starts beating the other one -- maybe if the list has 50 or more entries; but at any rate they do the same thing).
Also, if you're going to be doing something like this a ton in real time with long lists, it might be more productive to do all this manipulation with tables instead of lists (but there isn't yet a library of ready-made vanilla table abstractions like list-abs, at least that I know about; it's been on my to do list for a while but I've been busy with lots of other stuff, and anyway there are lots of externals which do these things with tables).
Matt
On Fri, Mar 4, 2011 at 9:49 PM, Caio Barros caio.barros@gmail.com wrote:
2011/3/4 Matt Barber brbrofsvl@gmail.com
I'm not shure if I understood that. You mean that if I set the "nuber of subdivisions per beat" as 10 I can't set the number of beats to, say 8,255? As far as user's responsibility goes, it doesn't make sense to input negative numbers, yet it is possible.
I think we're saying the same thing, if you're using the comma the way americans use the dot for indicating decimal; did 8,255 mean "8 + 255/1000"?
Briefly -- it means that if I set the "subdivisions" to 4 (i.e. the "rhythms" will be quantized to "sixteenth notes"), I will not be able to generate something that lasts a total of 25.2 beats, since 25.2 is quantized to 5 subdivisions per beat ("sixteenth-note quintuplets).
Oh yes, we are saying the same thing. Sorry for the comma, I always forget that. Even in pd sometimes I keep trying to write 0,25 in a number box and get angry because it doesn't work. One more thing. How hard it is to make possible for the user to choose between the random output that you already made and to sort that output from the smallest to longest duration and vice-versa?
On Fri, 4 Mar 2011, Matt Barber wrote:
Check out [list-sort] for short lists, [list-shellsort] for much longer ones (I don't remember at what point the shellsort starts beating the other one -- maybe if the list has 50 or more entries; but at any rate they do the same thing).
It vastly depends on the implementation, the interpreter it runs in, and the computer that the interpreter runs on.
However, from a short test of running time, it looks like [list-shellsort] runs much slower than what its theory calls the worst case. It probably takes O(n) time to perform stuff that usually takes O(1), probably because it avoids using [tabread] and such.
Actually, on my old computer, [list-shellsort] sorts an already-sorted list of size 1000 in 280 ms, and of size 4000 in 5530 ms. That's a 20-fold difference, whereas O(n^2) would be 16-fold, and shellsort's theoretical worst-case would be 8-fold, that is, O(n^1½).
[#sort] runs vastly faster than that. For the already-sorted list of size 1000, it does it in something like 0,22 ms, whereas for size 4000 it does it in about 0,90 ms. This means over a thousand times faster than [list-shellsort].
Also, if you're going to be doing something like this a ton in real time with long lists, it might be more productive to do all this manipulation with tables
Yes, you would be able to get speeds that are consistently about 10-20 times slower than [#sort] for any table size, which would be a vast improvement over [list-shellsort].
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC
This all sounds about right -- I made [list-shellsort] more as a pedagogical exercise for my students than as a model of speed or efficiency (I did a "quicksort" as well that didn't end up in list-abs). I'm pretty sure that whatever gains come from the algorithm are obliterated by "swapping" two values in a list -- I think it does bunch of splits to isolate values at two indices and then recopies the entire list TWICE in order to replace the two values. [list-swap] is ridiculously inefficient compared with the array/table analogue -- at one point I had sped up the whole thing vastly by dumping the list to a table first, sorting it all in place, and then dumping it back out to a list -- but then it uses fewer of the list abstractions and is less of an opportunity to show how the abstractions work "in action." And it's a good reminder for how slow list manipulations can be.
I remember a year or so ago I made a vanilla [list-s2l] that used a bunch of makefilename/sprintf shenanigans to slowly tease apart a symbol into constituent parts, with delimiting: http://lists.puredata.info/pipermail/pd-list/2009-11/074298.html -- one of the best exercises in constrained patching I've ever done, and fun for proving that some things are actually possible in vanilla that you think wouldn't be, but really stupid with comparison to the efficiency of something coded in C for actual use. Yet, I suspect that people go ahead and use [list-sort] all the time.
Matt
On Fri, Mar 4, 2011 at 10:29 PM, Mathieu Bouchard matju@artengine.ca wrote:
On Fri, 4 Mar 2011, Matt Barber wrote:
Check out [list-sort] for short lists, [list-shellsort] for much longer ones (I don't remember at what point the shellsort starts beating the other one -- maybe if the list has 50 or more entries; but at any rate they do the same thing).
It vastly depends on the implementation, the interpreter it runs in, and the computer that the interpreter runs on.
However, from a short test of running time, it looks like [list-shellsort] runs much slower than what its theory calls the worst case. It probably takes O(n) time to perform stuff that usually takes O(1), probably because it avoids using [tabread] and such.
Actually, on my old computer, [list-shellsort] sorts an already-sorted list of size 1000 in 280 ms, and of size 4000 in 5530 ms. That's a 20-fold difference, whereas O(n^2) would be 16-fold, and shellsort's theoretical worst-case would be 8-fold, that is, O(n^1½).
[#sort] runs vastly faster than that. For the already-sorted list of size 1000, it does it in something like 0,22 ms, whereas for size 4000 it does it in about 0,90 ms. This means over a thousand times faster than [list-shellsort].
Also, if you're going to be doing something like this a ton in real time with long lists, it might be more productive to do all this manipulation with tables
Yes, you would be able to get speeds that are consistently about 10-20 times slower than [#sort] for any table size, which would be a vast improvement over [list-shellsort].
On Fri, 4 Mar 2011, Matt Barber wrote:
This all sounds about right -- I made [list-shellsort] more as a pedagogical exercise for my students
So, what is that supposed to teach them ?
than as a model of speed or efficiency (I did a "quicksort" as well that didn't end up in list-abs).
How did you achieve the quicksort ?
Why didn't it end up in list-abs ?
but then it uses fewer of the list abstractions and is less of an opportunity to show how the abstractions work "in action."
Don't you think that it would be better to show the list-abs for what they are good at, rather than for what they aren't ?
And it's a good reminder for how slow list manipulations can be.
Ah, yes. But note that [list split] is O(1), which is the cool thing about pd's lists.
one of the best exercises in constrained patching I've ever done, and fun for proving that some things are actually possible in vanilla that you think wouldn't be,
Yeah, people didn't think a pure-vanilla [list-drip] could be O(n) either. I made one and now it's the new [list-drip]. I didn't mean to actually encourage people to use list-abs though. I already had written [foreach] in C++ which is a lot easier to understand :
\class ForEach { \constructor () {} \decl 0 list (...) {for (int i=0; i<argc; i++) out0;} }; \end class {install("foreach",1,1);}
this basically just says : make a class that has an inlet 0 list method that takes every element and sends it through outlet 0. Then name this class [foreach] and make it have 1 inlet and 1 outlet.
Your [s2l] looked more desperate though. ;)
Yet, I suspect that people go ahead and use [list-sort] all the time.
uh, who would do that ?
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC
On Sat, Mar 5, 2011 at 1:06 PM, Mathieu Bouchard matju@artengine.ca wrote:
On Fri, 4 Mar 2011, Matt Barber wrote:
This all sounds about right -- I made [list-shellsort] more as a pedagogical exercise for my students
So, what is that supposed to teach them ?
Right, well -- my students are almost all composers with very little experience with computers, except for maybe music engraving software. In our computer music program the emphasis has long been on "achieving musical results," and the technical training required to make this happen tends to be very hard for them. Many of them will look in books to find things that interest them, only to get scared by equations, block diagrams, bits of code, etc. They all get really excited about abstractions in Pd when it comes up, but they don't have any idea why or when to make them or use them. It's useful, then, to take concrete problems like sorting numbers, finding roots of quadratic equations, or making comb filters, for which there exist plenty of code or diagram examples, and "translate" them into Pd. At this level just getting from an analysis of the problem to "it works" takes a huge amount of time; analysis of time complexity would be way outside the scope of the course, unfortunately.
than as a model of speed or efficiency (I did a "quicksort" as well that didn't end up in list-abs).
How did you achieve the quicksort ?
Why didn't it end up in list-abs ?
Attached. It uses a table for all the partitioning, and uses until loops instead of the more classic recursion.
but then it uses fewer of the list abstractions and is less of an opportunity to show how the abstractions work "in action."
Don't you think that it would be better to show the list-abs for what they are good at, rather than for what they aren't ?
Yes, absolutely. Swapping numbers in a list is hard with vanilla tools (and I think [list-swap] could be improved considerably) -- my point was that the library seems to prefer using list operations all the way through, even if a table/array would be more efficient ultimately.
And it's a good reminder for how slow list manipulations can be.
Ah, yes. But note that [list split] is O(1), which is the cool thing about pd's lists.
one of the best exercises in constrained patching I've ever done, and fun for proving that some things are actually possible in vanilla that you think wouldn't be,
Yeah, people didn't think a pure-vanilla [list-drip] could be O(n) either. I made one and now it's the new [list-drip]. I didn't mean to actually encourage people to use list-abs though. I already had written [foreach] in C++ which is a lot easier to understand :
\class ForEach { \constructor () {} \decl 0 list (...) {for (int i=0; i<argc; i++) out0;} }; \end class {install("foreach",1,1);}
this basically just says : make a class that has an inlet 0 list method that takes every element and sends it through outlet 0. Then name this class [foreach] and make it have 1 inlet and 1 outlet.
Your [s2l] looked more desperate though. ;)
Yes, it was desperate. Desperate things happen quite often -- for instance when an audio chain has a number of if-then conditionals, if you don't want to use expr~ or externals you have to calculate all the sidechains and then choose among them arithmetically; there's no good way to avoid calculation of certain rare conditions (things that approach division by small numbers, e.g.) on a sample-by-sample basis.
Yet, I suspect that people go ahead and use [list-sort] all the time.
uh, who would do that ?
People who discover list-abs on their own and who then learn that there's a sort function in the library.
Matt
On Sat, Mar 05, 2011 at 02:02:09PM -0500, Matt Barber wrote:
On Sat, Mar 5, 2011 at 1:06 PM, Mathieu Bouchard matju@artengine.ca wrote:
On Fri, 4 Mar 2011, Matt Barber wrote:
This all sounds about right -- I made [list-shellsort] more as a pedagogical exercise for my students
So, what is that supposed to teach them ?
Right, well -- my students are almost all composers with very little experience with computers, except for maybe music engraving software. In our computer music program the emphasis has long been on "achieving musical results," and the technical training required to make this happen tends to be very hard for them. Many of them will look in books to find things that interest them, only to get scared by equations, block diagrams, bits of code, etc. They all get really excited about abstractions in Pd when it comes up, but they don't have any idea why or when to make them or use them. It's useful, then, to take concrete problems like sorting numbers, finding roots of quadratic equations, or making comb filters, for which there exist plenty of code or diagram examples, and "translate" them into Pd. At this level just getting from an analysis of the problem to "it works" takes a huge amount of time; analysis of time complexity would be way outside the scope of the course, unfortunately.
than as a model of speed or efficiency (I did a "quicksort" as well that didn't end up in list-abs).
How did you achieve the quicksort ?
Why didn't it end up in list-abs ?
Attached. It uses a table for all the partitioning, and uses until loops instead of the more classic recursion.
but then it uses fewer of the list abstractions and is less of an opportunity to show how the abstractions work "in action."
Don't you think that it would be better to show the list-abs for what they are good at, rather than for what they aren't ?
Yes, absolutely. Swapping numbers in a list is hard with vanilla tools (and I think [list-swap] could be improved considerably) -- my point was that the library seems to prefer using list operations all the way through, even if a table/array would be more efficient ultimately.
Well, there might be a slight bias towards list-ops, but table-ops are very welcome. I guess, I just forgot about the quicksort when it was posted in 2008 in a fury of other sorting implementations. I have added it now.
Frank Barknecht Do You RjDj.me? _ ______footils.org__
Hi guys. As I said before I wanted two complements to the wonderful solution by Matt Barber, and I just did the first! Is a patch that outputs bangs at random delays between them. The user can set the minimum and maximum duration between bangs (all in ms) and a setp size. This last one is easier to explain by an example: If the user set the minimum duration as 100ms, maximum as 2000ms and step size as 10ms the delays between bangs can be 100, 110, 120, 130 and so on, but never 115 or 127 for instance.
Also, the patch runs a stopwatch that can be programed to... stop at a given time
Everything can be saved to a text file, witch will contain the time of the bang (given by the stopwatch) and the time difference between bangs. This will allow me to create note attacks with durations that sound very random and non-directional.
I putted all the commands inside a "graph on parent" so it can be used as an abstraction. I plan to create a bigger patch with Matt's, this one and at least one more.
Hope you enjoy and give me feedback. Caio Barros
PS: This was the first time that i realized that you can do a graph on parent inside a graph on parent. cool!
On Fri, 4 Mar 2011, Caio Barros wrote:
Oh yes, we are saying the same thing. Sorry for the comma, I always forget that.
You shouldn't be sorry about the comma. Be proud about the comma :)
Even in pd sometimes I keep trying to write 0,25 in a number box and get angry because it doesn't work.
This means pd needs some help with it. Just apply this change to pd, and it will convert commas to periods :
--- g_text.c (révision 15012) +++ g_text.c (copie de travail) @@ -714,7 +714,7 @@ x->a_buf[len] = c; x->a_buf[len+1] = 0; goto redraw;
}
} else if (c == ',') strcpy(x->a_buf+len,".");
}
return;
redraw:--- g_numbox.c (révision 15012) +++ g_numbox.c (copie de travail) @@ -714,12 +714,12 @@ sys_queuegui(x, x->x_gui.x_glist, my_numbox_draw_update); return; }
buf[0] = c;
buf[0] = c==','?'.':c;
strcat(x->x_buf, buf);
sys_queuegui(x, x->x_gui.x_glist, my_numbox_draw_update);
}
One more thing. How hard it is to make possible for the user to choose between the random output that you already made and to sort that output from the smallest to longest duration and vice-versa?
[#sort] can sort any list of numbers very quickly.
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC
On Fri, 4 Mar 2011, Matt Barber wrote:
I think we're saying the same thing, if you're using the comma the way americans use the dot for indicating decimal; did 8,255 mean "8 + 255/1000"?
Only if the / doesn't indicate integer division as in [expr] ;)
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC