|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
global variable woes and ghost synthsHi list
I have been trying to create a gui for my granular synth. I recently come across a strange thing when I try to change the window envelope my synth uses by sending the number of the buffer containing the window. The odd thing is when I create the synth by hand, I am able to do this. But it doesn't work when the synth is created by my gui. The code is identical in both conditions: startButton.action = {|view| if (view.value == 1) { o = Synth ("rainer1", [\stuff, stuffControl.value,\envbuf,-1])} { o.free; o = nil}; }; and o= Synth("rainer1", [\stuff, 231, \envbuf, -1]); Well they seem pretty identical to me (syntax-wise) However, only the latter seems to work. Sending o.set([\envbuf, 2]); returns nil for the first case, which is the problem. If I didn't manually create the synth beforehand, "o" returns nil. If I did, it returns a reference to the old synth, ignoring my gui-created synth As far as I can understand, the two cases are not actually the same because It seems to me that the first method is not referenced the same way as the second method. I assumed this wouldn't happen since they both use a global variable. Any thoughts about a possible solution? |
|
|
Re: global variable woes and ghost synthsOk, I don't know why that post did not attract any kind of attention but I still want to give an update in case somebody would like to help
I tried creating the synth from gui with s.doWhenBooted({s.sendSynthDef("rainer")}) and then o = Synth.tail (s, "rainer", [... which did not help When I query the server with s.queryAllNodes, I see the same thing as a manually created synth. However, .trace method doesn't work with the gui created synth but it does with the manually created one. I am getting more and more confused with this. Does anybody have a clue? Ali
|
|
|
Re: global variable woes and ghost synthsPossibly no one has responded because there's not enough info here to
reproduce your problem. The code you've posted works as expected for me on both Linux and Mac (including running "o.trace" on the GUI-created Synth), so you probably need to show more context to reveal the trouble. I suspect that you have a variable "o" declared locally in a scope where your button's action is defined. That would hide the global "o" and create the behavior you are seeing. If I've guessed correctly, this is a danger of using global variables (in any programming language), not a subtlety of the interaction between Synths and GUIs in SuperCollider. Hope this helps, Russell Johnston gimbal wrote: > Ok, I don't know why that post did not attract any kind of attention but I > still want to give an update in case somebody would like to help > > I tried creating the synth from gui with > s.doWhenBooted({s.sendSynthDef("rainer")}) and then o = Synth.tail (s, > "rainer", [... > which did not help > > When I query the server with s.queryAllNodes, I see the same thing as a > manually created synth. > However, .trace method doesn't work with the gui created synth but it does > with the manually created one. > I am getting more and more confused with this. Does anybody have a clue? > Ali > > > > gimbal wrote: >> Hi list >> I have been trying to create a gui for my granular synth. I recently come >> across a strange thing when I try to change the window envelope my synth >> uses by sending the number of the buffer containing the window. >> The odd thing is when I create the synth by hand, I am able to do this. >> But >> it doesn't work when the synth is created by my gui. >> The code is identical in both conditions: >> >> startButton.action = {|view| >> if (view.value == 1) { >> o = Synth ("rainer1", [\stuff, stuffControl.value,\envbuf,-1])} >> { o.free; o = nil}; >> }; >> >> and >> >> o= Synth("rainer1", [\stuff, 231, \envbuf, -1]); >> >> Well they seem pretty identical to me (syntax-wise) >> However, only the latter seems to work. >> Sending o.set([\envbuf, 2]); returns nil for the first case, which is the >> problem. >> >> If I didn't manually create the synth beforehand, "o" returns nil. If I >> did, >> it returns a reference to the old synth, ignoring my gui-created synth >> >> As far as I can understand, the two cases are not actually the same >> because >> It seems to me that the first method is not referenced the same way as the >> second method. I assumed this wouldn't happen since they both use a global >> variable. >> Any thoughts about a possible solution? >> >> > _______________________________________________ sc-users mailing list info (subscribe and unsubscribe): http://swiki.hfbk-hamburg.de:8888/MusicTechnology/880 archive: http://www.listarc.bham.ac.uk/marchives/sc-users/ search: http://www.listarc.bham.ac.uk/lists/sc-users/search/ |
|
|
|
|
|
Re: global variable woes and ghost synths > I think this is the case, yes. But I don't understand how one can hide
> the scope of a global variable. I didn't know that was possible. Is > there a way to not do this? Just don't declare the variable (note that I'm still only assuming this is your problem since I can't see it). Since the helpfile on scope pretty much assumes that you already understand the basic idea of block scoping (it mostly explains closures), here's a simple example: // Global variable "v" is magically pre-declared by the language. v = 1; v.postln; // this will display "1" // Note: be sure to execute parenthesized sections as blocks ( var v; // local declaration creates new variable, hiding global "v" v = 2; v.postln; // this will display "2" (value of local variable) ) v.postln; // still displays "1" (global variable is unchanged) ( v = 2; // no declaration, so we're using the global variable v.postln; // obviously this displays "2" ) v.postln; // now this displays "2" as well > I mean, I have to use a global variable in my button's function. So what > can be an alternative? Perhaps you already know this, but the standard software engineering answer is: "write a class to encapsulate your data." In SC this means recompiling the library, however, so it's not very convenient for interactive work (and of course you still need a variable somewhere to hold an instance of the class). For trying something out on the fly, it seems reasonable to use a builtin one-letter global as you are doing, just make sure not to hide it with a "var" declaration. A more robust approach is to create a distinctive variable name in the top-level environment by using a leading tilde in the variable name (e.g. "~guiRainerSynth"). For immediate practical purposes this is still a global variable, but read up on "Environment" in the help files for details. Also check out Nick Collins' fine tutorial, which covers this and many other fun things. ( var win, but; win = GUI.window.new("Example", Rect(0,0,120,60)); but = GUI.button.new(win, Rect(20,20,80,20)); but.states = [ ["push me"] ]; but.action = { ~guiDefaultSynth = Synth(\default); }; win.front; ) ~guiDefaultSynth.set([\freq, 220]); Ali Bilgin Arslan wrote: > Thanks for the reply > > On Wed, Jul 16, 2008 at 12:40 AM, Russell Johnston > <russell@... <mailto:russell@...>> wrote: > > Possibly no one has responded because there's not enough info here > to reproduce your problem. The code you've posted works as expected > for me on both Linux and Mac (including running "o.trace" on the > GUI-created Synth), so you probably need to show more context to > reveal the trouble. > > I suspect that you have a variable "o" declared locally in a scope > where your button's action is defined. That would hide the global > "o" and create the behavior you are seeing. > > > I think this is the case, yes. But I don't understand how one can hide > the scope of a global variable. I didn't know that was possible. Is > there a way to not do this? > I mean, I have to use a global variable in my button's function. So what > can be an alternative? > > There is another thing that I don't quite follow. I use many sliders and > rangers that operate on the same synth with the same fashion, but they > work fine. They all use the same .set method but apparently it doesn't > work for passing the name (or the number) of the buffer for some reason. > > It might be good to just post the code but doing this with a code in > THAT shape would be like an insult : ) it is terribly messy and I have > yet to develop a indentation style of my own. Otherwise i would have > done it beforehand. > I'll try to recreate the error in another code but i appreciate any > other suggestions until that time. > > > If I've guessed correctly, this is a danger of using global > variables (in any programming language), not a subtlety of the > interaction between Synths and GUIs in SuperCollider. > > Hope this helps, > Russell Johnston > > gimbal wrote: > > Ok, I don't know why that post did not attract any kind of > attention but I > still want to give an update in case somebody would like to help > > I tried creating the synth from gui with > s.doWhenBooted({s.sendSynthDef("rainer")}) and then o = > Synth.tail (s, > "rainer", [... > which did not help > When I query the server with s.queryAllNodes, I see the same > thing as a > manually created synth. > However, .trace method doesn't work with the gui created synth > but it does > with the manually created one. > I am getting more and more confused with this. Does anybody have > a clue? > Ali > > > > gimbal wrote: > > Hi list > I have been trying to create a gui for my granular synth. I > recently come > across a strange thing when I try to change the window > envelope my synth > uses by sending the number of the buffer containing the window. > The odd thing is when I create the synth by hand, I am able > to do this. > But > it doesn't work when the synth is created by my gui. > The code is identical in both conditions: > > startButton.action = {|view| > if (view.value == 1) { > o = Synth ("rainer1", [\stuff, > stuffControl.value,\envbuf,-1])} > { o.free; o = nil}; > }; > > and > > o= Synth("rainer1", [\stuff, 231, \envbuf, -1]); > > Well they seem pretty identical to me (syntax-wise) > However, only the latter seems to work. > Sending o.set([\envbuf, 2]); returns nil for the first case, > which is the > problem. > > If I didn't manually create the synth beforehand, "o" > returns nil. If I > did, > it returns a reference to the old synth, ignoring my > gui-created synth > > As far as I can understand, the two cases are not actually > the same > because > It seems to me that the first method is not referenced the > same way as the > second method. I assumed this wouldn't happen since they > both use a global > variable. > Any thoughts about a possible solution? > > > > > _______________________________________________ sc-users mailing list info (subscribe and unsubscribe): http://swiki.hfbk-hamburg.de:8888/MusicTechnology/880 archive: http://www.listarc.bham.ac.uk/marchives/sc-users/ search: http://www.listarc.bham.ac.uk/lists/sc-users/search/ |
| Free Forum Powered by Nabble | Forum Help |