[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] Dictionary:choose - loops forever



thanks Julian, Alberto.
will try the your method additions Alberto.

thanks,

x

On 12/23/06, Alberto de Campo <decampo@xxxxxx> wrote:
>>I have always used clear but the other day I was snooping around and
>>James points it  right, I saw Julian doing stuff with makeEmpty in
>>JIT.
>
>
>I've implemented makeEmpty for Order, which I use it for, but not
>for Set / Dictionary. It is better to use clear, and I'll change it
>to clear in Order too, I think.
>

I tried these for a day, and they seem to work fine; please test:
---
        // IMO removeAll(nil) should remove all items, like the
        // other removeAll methods:
+ Collection {
                removeAll { | list | (list ?? { this.copy }).do { |
item | this.remove(item) } }
}

+ Dictionary {
                removeAll { | list | (list ?? { this.copy
}).keysValuesDo { | key | this.removeAt(key) } }
}

        // replacing makeEmpty:
+ Set {
        clear { array.fill; size=0 }
        makeEmpty { ^this.shouldNotImplement } // check to find other uses
}

+ Order {
        *new { arg size = 8;
                ^super.new.init(size)
        }

        init { arg size = 8;
                array = Array.new(size);
                indices = Array.new(size);
        }

        clear { arg func;
                var item;
                while { item = this.pop; item.notNil } { func.value(item) };
                ^this.init;
        }
        makeEmpty { ^this.shouldNotImplement }  // check to find other uses
}

+ PatternProxy {
        *removeAll {
                this.all.do { arg pat; pat.stop };
                this.all.clear;
        }
}

+ NodeProxy {
        removeAllToBundle { arg bundle;
                var dt, playing;
                dt = this.fadeTime;
                playing = this.isPlaying;
                objects.do { arg obj;
                                if(playing) { obj.stopToBundle(bundle, dt) };
                                obj.freeToBundle(bundle, dt);
                };
                objects.clear;
        }
}

+ SharedNodeProxy {
        removeAllToBundle { arg bundle;
                var dt, playing;
                dt = this.fadeTime;
                playing = this.isPlaying;
                if(playing) { this.stopAllToBundle(bundle) };
                objects.do { arg obj; obj.freeToBundle(bundle, dt) };
                objects.clear;
        }
}
---
--
--
Alberto de Campo
Bergstrasse 59/33
A-8020 Graz, Austria
e-mail : decampo@xxxxxx
--
_______________________________________________
sc-users mailing list
sc-users@xxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-users