How can I open and completely close patches under program control?
I'm trying to use the ;max object to open and close patchers using openfile and closefile but I don't see any obvious (i.e., non-hacky) way to keep track of the fileref parameter. I had tried using the same fileref name for every file but discovered that if I tried to close a patch that wasn't open, it seems to generate an exception with an error showing up in the max window.
Is there an elegant way to keep track of this kind of thing?
bang->[pcontrol] ?
Apparently not. The problem with control is that patchers dnt actually get closed and so when you open them gain, the loadbang doesn't trigger and so reopening a patch doesn't reinitialize it. The ones I'm closing can also have some resources in them and so need to be freed properly between use. (e.g, VST objects need to go away)
initialisation is something which is intended only to happen after _loading
a patcher. when you want a reinitialisation for every _open, you need to do
that yourself anyway.
the inlet of [loadbang] might be your friend here.
one alternative is to delete and open a file from disk via script-create.
-110
Yes, I know that --- that's the point --- I want the patch to be unloaded completely (as if I closed the window with the mouse) and reloaded again as if it was the first time.
This can be done with the ;max mechanism but the problem is keeping track of the file reference so that I know how to close the patch again.
I found that if I attempt 'closefile' where the fileref is wrong, Max seems to stop as opposed to just registering an error and continuing. Otherwise, I could just have openfile A1, openfile A2, openfile A3.... and if I do a closefile A2 and file A2 wasn't open, it would be a no-op instead of an error.
The purpose by the way is to be able to process incoming MIDI Program Changes to load a particular patch. When I subsequently send in a new MIDI Program Change, that patch has to be completely closed before the new one gets opened.
This question has now been answered in another thread and I thank everyone for the suggestions.
See https://cycling74.com/forums/im-having-some-trouble-using-pcontrol
fpr such small patches i would eveentually not close and open thembut just
run them in parallel anc control the route my data goes with a [gate].
I'm not sure what you consider to be small patches --- bascially, I have been reimplementing the MIDI functionality of Apple MainStage. Each main patcher represents an individual MainStage patch. For example, here's a simple one.
I'm in the middle of writing up a complete description of this work as I'm not the only one having trouble with MainStage. See http://deskew.com/blog/replacing-apple-mainstage-with-a-custom-maxmsp-implementation-part-1.html for more info.