Problem getting VST to work (in certain cases)
I’ve been building a collection of patchers to emulate the behavior of apps like MainStage….it has been going very well and I recently added VST support into the mix.
Basically, I have individual patchers that represent songs and they contain abstractions that do things like send program changes to external devices upon being loaded, manage splits, layers, velocity maps, etc. I can either double-click one of these top-level patchers or I can use a separate always-open patcher that receives MIDI program changes which then uses [pcontrol] to first close the currently top-level patcher and then opens the new patcher.
This has been working beautifully with MIDI. However, when I added in [vst~] to the mix (no pun intended), I discovered that everything works perfectly fine if I double-click a top-level patcher but if I use the [pcontrol] mechanism to load the same top-level patcher, I get no sound. I know that MIDI events are still being sent into the [vst~] and I know that the DSP processing is still enabled.
Any insights? This is driving me nuts.
Some more clues —- I’m using an ezdac~ for audio output.
Although it continues to show as ON (as I said above),
if I toggle it manually with the DSP Status dialog or by manually sending a ‘stop’ and ‘start’ message), audio immediately starts to work again.
However, if I send the ‘stop’ and ‘start’ programatically, after sending the ‘load’ message, it still does not work.
However again, if I insert a [delay 1000] object in between, so that the ‘stop’ and ‘start’ get sent after a 1 second delay, they work fine.
So there’s some funky asynchronous behavior with pcontrol and the ezdac (or audio processing in general) that requires a reset.
Still looking for insights — I can certainly workaround this problem now with a [delay] but such things always make me nervous — who knows how long the delay actually needs to be, etc….race conditions, blah blah blah.
I have to say I’m a little discouraged by the lack of responses. Is this really stuff that nobody knows the answer to? Hard to believe.
Can you show us a small example patch which demonstrates what you are trying to do?
Well, here’s a stripped down version with most stuff removed to avoid distraction….probably won’t actually work but will give the idea of what I’m trying to do.
First I have a patcher called GenericVST that looks something like the following:
----------begin_max5_patcher---------- 1193.3oc4Y0ziaaCD8r8uBBsHHWb2HR8oaOEfdNsMsnWBBBjsosYg0GUjZqS CR+sWwgR1J1VxzV1DxHGVIKJthy73adbFxuLdj0rzsTtE5GQe.MZzWFOZDzj rgQUOOxJNZ67MQbnaVwTNOZE0Zh5cB5VAz9S35lRKDanBwmynpuqkE5iUuJK RLeMKY0mxoyEp2h88e1dBhPBk2bHO6MAgK+8t+G1B36m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szaQB6uKnL4IIZe7gIBFMHqdv4WCdtr8ucZf mVjOudvpOMYzdeeAkWl.9tL29v9sfDg20o0rEKnIMCqhYKxRKmApLhVNuScs I4AInmMQLlMIOb4FPPG1jswroCFtSaSxphMnMo0b2Ajt6NNoCL4ZTSRmYNGi ZQRotyRvkm5oAEBb0QbBrIygSxJWOOaxrBAdZIDDXVbRCSxvnDQG1jY0Av5v vIlkgSzggaVXxQKXJb3ASdlkgqyDmYW68f3oAgMcP7TK1jYC5b0wlvCOsIb3 vapiXV5juNq95FN7RC2uOq+V9vWG++HoFykC -----------end_max5_patcher-----------
Then I can create a patcher that represents a VST with a specfic patch — that becomes an "instrument". Here’s one that would use the ACE vst with a "Strings" sound that is saved in a patcher called "Strings"
----------begin_max5_patcher---------- 583.3oc0V1ziaBCDF9L7q.4yoqvlOJzaQUU8VUU2p1CUqVwGNItBrQfQMsq1 +60XCjcSIDGhfs6EGwfSdeelwyD+foAHlsGWArdm0OrLLdvzvPFpIfQ6yFf7 n8IYQUxsAHzLLGrR8FVMW7D+2EX0OA.XcW6qJh3I6Hzs2WhS3p2hfN2XuxBF 327Axqas+6PRkRvh+4a76jfVmKkTpt8gfJokQgsQSX44XpTLvWV+cPSzGMMa VVM+zA87Tz4dd5btR59LQHeLlltzLhzmQzUx35MbbImUmraggLzWaFgWIieh wEceS.u3ZNmQOIewQzsixn+aavxWAmc25PH5NHhvgQbBjPw+RHSmHb7dUlon DWHNeaELwZnGTBUn6y4bvlQ6NM1vnbZTNVc9qjDkMJ7Mauh7G41gnarm+bBg 1eldntSajDWWjDdG2wnFENmTaubTGZK6Wc70AZm+2ftJijhK6ztWhdEF4X+l LVjX9Hunl+TqNTJxUlhBQGZ2gtmHEACl4F9bbUUzV7+TmukKJzaqlV+tZdVn b0MPM+9D7coGAPuPc6hpapbN9UNjGEJGAN5PdH7UxHvOho3RRx2t8qVqe+G. mk8.0Ygw+C.uKDd+oNTPJNHiPO9J2R.Zh+7LREqtLoqb2dqXqCHjhq3DZDmH tIvg8HnwxqeO6HooX5SuURNIsfIFo1ZAq6Fr5nqibzzQNKliPZ5Hzh4HnlNB tbNR2xl8xYIcxRtKpkb0vQGkIm81MaM7DZY8TyMFNqmNx3WlmDO7n4eAVeQy yC -----------end_max5_patcher-----------
Then I can create a top level patch that would contain the patcher called "Strings" and some other patchers that represent inputs from my MIDI keyboards.
So for example, here is a real top level patcher that loads (ultimately) a vst that sounds like a harmonica and it is played from a Yamaha An1X controller.
----------begin_max5_patcher---------- 1502.3oc4Zs0aaaCE9YmeEDtulEHp6Z6obAEKXqsYHcaOTTTPKQayAYRCIpj 3Uz+6iWjrcbrnkbrUrvdHxHRxhemOeNemKTe+rACGwdBmOD7yfu.FL36mMXf 5TxSLn7+GLbF5o3TTt51FFylMCS4COWeMN9It57Wyn7LVJfOECFSnnTvM2eG .UjPXfGI7ofeixF4AXiU2wkeD9T0iHkPwwrBp543Tdx4Hd7TBcx2xvwbM978 suv5bfMT8AzyR9ga3EVfuV9kHIJnvF8O+jsS0ier.XTzLr5RWlQPoUWgVLiP SwbkgAW61yI+q51Uqzx6kUvqtYK4I+wYmIOb9qj39ybAcLliy3rh3o.NCjv. HPJgKVNvbhfG.ywzDAYrUFy1.iY4H4nHq0HLG2ZHLXegvDdZiISJxvJOoXFM mkRRPbbBXbl.Lf4HJNEjPxmmhVzVurvnPIME52.mLXugytW3.A9vs2bK3tL1 jLzLv0SQzIXo61mP4KxAiYYfKiiYYIDDEjKXpjKZcDpsJzzwInAjWzoF2QwO Jv0KntKkRXepXImtE6NvWaoAJmFenRlxZ6lcXKMa62HyNOFIjerDqU.v2E3X WcG5kiuXNVa7CGtzL2B03FpUqszZPVdl3FXPKIG+1PNv8gbJlMBmUqoSjgZf giDgRMgE7TRK5vhZ4.2iYbg8dvAyv44nI3W5gf4feEkMiQIwn8y6HLzQmRW4 VDpnGXchsdGyHG3ALxQUcipbmeGMBmNb21ui1xgNl7L7f8DESAATpYNuf+Wr zhYXCbfmUjxpcUxlPaeS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bezC6Z.jB6VHE1je4fNcKlbaBO0spSQvSPdJpAXJpa4IXSTLCc O87mf9cJljdJt6RDua+kyqArj2IXMAa.7iNO0HuotMYGrI0y40okoX2PDY0o Hx9jiibZ.hb1SDI9meb1+AvHYT6K -----------end_max5_patcher-----------
So here’s the problem. If I open the above patcher by double-clicking on the file name, everything works perfectly fine every time. However, if I open the above patch by sending a ‘load filename’ message to a [pcontrol] then I get no audio. If I subsequently send messages manually to ‘stop’ then ‘start’ the DSP processing, it works again. However, if I send those messages as part of a patch, for example, after it returns from the ‘plug’ message, it does not work unless I add significant delays before the ‘stop/start’ messages are sent and even then it doesn’t always work.
Incidentally, at this point (after a load but with no sound) if I play a few notes on my keyboard and THEN restart the DSP processing, all those notes come out instantly in a burst and then everything works fine until the next time.
Note that there’s a description of my overall design in a couple of my blog entries, including lots of pictures so you can get a better idea of what I’m doing.
Thanks in advance for any suggestions as to what is going wrong here.
There seem to be several issues
1) pcontrol seems asynchronous, that is, if I send a message through it, it returns immediately so messages intended to be sent after the patch is loaded are being sent too early
2) the loading of [vst~] seems asynchronous. Again, if I send a ‘plug’ message to it, it returns immediately.
Any way to detect that a vst has in fact finished loading?
This thread may be helpful
Thanks — I’ll try those suggestions — however, they’re still stopgaps because I still don’t understand the underlying problem, i.e., why does the DSP stuff have to be restarted when a vst is loaded via pcontrol?
"Any way to detect that a vst has in fact finished loading?"
no, i´d wish.
but what you can do is to call it every 250 ms and ask for the number of
parameters – when there is an answer, its there. ^^
btw, your delay solution is not perfect, you may know that. it is on the one
hand not sure that 1000 ms will always be enough, but on the other hand
you put the loadbang to high priority this way, which could stop working
in certain situations.
Yes, I’ve already discovered that the delay solution isn’t reliable — but I didn’t really expect it to work well, as I indicated in my initial posting.
I am having better luck with the deferlow though I don’t quite understand exactly why it helps.
I understand technically what it’s supposed to do but since I don’t understand why the regular Max "ordering" is not apparently being obeyed, it’s a bit murky. Note: I understand things like blocking vs. non-blocking calls and it would seem that the pcontrol system is using "post" rather than "send" messages but I don’t understand WHY it was done that way as it completely breaks the Max semantics of right-to-left depth first algorithm.
It’s a matter of event priorities, explained in this article
Thanks — that’s very helpful.
So, I seem to have pretty dependable solution now, using deferlow. However, in the context of the scheduling article above, I still don’t quite understand what’s going on.
First of all, I’m not using overdrive at this time so (according to the article, there should only be one thread). So that doesn’t explain how a call to pcontrol could return immediately unless the pcontrol call is using ‘post’ rather than ‘send’ to the OS in which case it’s not obvious why deferlow will always work as one doesn’t know when new Max events will be inserted into the Max thread as a consequence of the pcontrol call.
It also doesn’t explain why opening a patcher with a vst through pcontrol requires the ezdac to be restarted in the first place.
Any more insights? I realize I seem to have a working solution (at least on this particular computer) but it’s still unclear to me how much of this is timing dependent and could break once other people try to use it on computers with different speeds.
"It also doesn’t explain why opening a patcher with a vst through pcontrol requires the ezdac to be restarted in the first place."
This looks like a bug. Maybe you can isolate and demonstrate the issue with a small patch.
Yep — I hacked a quick small test, and it fails precisely as described. Attached is an archive with the two patchers.
To reproduce the problem:
(I’m assuming that anyone trying this will edit the audio output and MIDI devices and VSTs in these patchers to match their own environments)
1) Open the StandaloneAudioOutputDevice and leave it open. Note the "load StandaloneVSTTest" piece on the bottom left but don’t touch it yet.
2) Open the StandaloneVSTTest directly from the finder. If you play keys on your keyboard, you should hear basic sound. If you close this and open it a few times, it should work perfectly well each time.
3) Close the StandaloneVSTTest patcher. Now, click on the "load StandaloneVSTTest" message in the other patcher. The StandaloneVSTTest will open but you won’t hear anything when you play keys. Now turn the DSP processing off and on again (either from the DSP Status object or just by clicking the "Manual restart" [bang] and everything will work fine.
I’d be very interested to know if anyone else can reproduce this issue
Did anyone try to reproduce this issue?
I can verify. This should be fixed in the next release.