Kyma Forum
  Kyma Support
  sorting arrays with hot parameters

Post New Topic  Post A Reply
profile | register | preferences | faq | search

next newest topic | next oldest topic
Author Topic:   sorting arrays with hot parameters
Phi Curtis
Member
posted 24 March 2010 10:07         Edit/Delete Message   Reply w/Quote
Hi,

Continuing on a theme from another recent thread about having variables/hot parameters inside literal arrays (and how that isn't possible in Capytalk):

I would like to sort an array of hot values from high to low. Taking advantage of the sorted array collection type, his smalltalk code works:

code:

| sortedArray |
sortedArray := #(1 6 3) asSortedCollection.
!Index of: sortedArray

!Index will then pull up the numbers in the correct (low to high) order. But the expression wont work with hot values in the array. Is there a way to somehow use the sorted array with hot values?

I'm sure there's a more labor-intensive way to do this with comparison operators, but thought I would ask first.

IP: Logged

SSC
Administrator
posted 24 March 2010 11:22         Edit/Delete Message   Reply w/Quote
Hi Phil, What is the result you are trying to achieve? Are you looking for the maximum/minimum value of several faders? Or are they checkboxes (Booleans)? What is the reason you are sorting the hot values? If you could please describe the result, we might be able to suggest some ways of accomplishing this using CapyTalk. Thanks!

BTW, just to clarify, asSortedCollection is a Smalltalk (not a CapyTalk) message. You cannot use Smalltalk to sort an Array of variables whose values are not yet known (or could change after the sorting). Because to put an element into its correctly sorted position, it must have a value so you can test whether that value is greater than or less than that of the other elements. Hot values can change while the Sound is playing but in your example, you are doing the sorting before the Sound even starts playing (all Smalltalk is executed before the Sound starts to play; it is only CapyTalk expressions that are evaluated while the Sound is playing).

quote:
Continuing on a theme from another recent thread about having variables/hot parameters inside literal arrays (and how that isn't possible in Capytalk):

I think the statement was rather that no language can use variables in a literal Array. That's just a matter of definition. The term 'literal' in this context means that all the elements are constants (in Smalltalk, those can be Strings, Characters, Symbols, or Numbers). Smalltalk provides a shortcut for creating literal Arrays. But it does not prevent you from creating Arrays of any objects, including variables. As I stated in that thread, Smalltalk Arrays can contain any objects (including other Arrays), when you create them using the Array's instance creation methods or, as Luddy suggested, using the collect: method, or by adding one element at a time in a loop (after the Array has been created and dimensioned).


IP: Logged

Phi Curtis
Member
posted 24 March 2010 12:45         Edit/Delete Message   Reply w/Quote
quote:
Originally posted by SSC:
Hot values can change while the Sound is playing but in your example, you are doing the sorting before the Sound even starts playing

I realized after I sent the message...I guess what I would need is a mechanism that re-evaluates and resorts the array every time the values of the members of the array change.

I know it would be very easy to find the highest or lowest member of the array (using vmin: or vmax: and just going through the entire array member by member), but how would you find the second lowest, for example?

IP: Logged

Phi Curtis
Member
posted 28 March 2010 19:28         Edit/Delete Message   Reply w/Quote

Sorting.kym

 
Here's my solution to the problem, done the labor-intensive way. It gets exponentially more complicated as the number of values you want to sort increases.

I'm curious if there would be a way to construct iteratively it so that all you had to give was the number of hot values and the names of the hot values, and it would generate the array for you.

IP: Logged

ChristianSchloesser
Member
posted 21 December 2013 08:37         Edit/Delete Message   Reply w/Quote
quote:
Originally posted by Phi Curtis:
I'm curious if there would be a way to construct iteratively it so that all you had to give was the number of hot values and the names of the hot values, and it would generate the array for you.

Did anybody ever found out a way to do that?
Implementing a good sorting algorithm for !HotValues in CapyTalk is puzzling me for a while. My current idea was to create a SmallTalk script which "creates" the necessary capyTalk expressions for a give number of !HotValues in an Array... using vMin and vMax... but still no success yet.
Maybe someone else here in the Forum already hast a good solution for this problem.
Any help or ideas are appreciated!
All the best
Chris

[This message has been edited by ChristianSchloesser (edited 21 December 2013).]

IP: Logged

SSC
Administrator
posted 21 December 2013 10:36         Edit/Delete Message   Reply w/Quote
Would you like the min and the max? (or do you need the entire array sorted)?

IP: Logged

ChristianSchloesser
Member
posted 21 December 2013 12:33         Edit/Delete Message   Reply w/Quote
I really would like to sort the entire array of !HotValues if one of the !HotValues changes.



IP: Logged

All times are CT (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply

Contact Us | Symbolic Sound Home

This forum is provided solely for the support and edification of the customers of Symbolic Sound Corporation.


Ultimate Bulletin Board 5.45c