[Cs-dev] Score rewinding
Date | 2005-05-08 20:31 |
From | Michael Gogins |
Subject | [Cs-dev] Score rewinding |
The recent changes in score rewinding by Istvan Varga unfortunately do not work in the context of VST plugins. They cause the host to hang. Commenting out the calls enables the plugin to function again, but of course there is no Csound score rewinding. The purpose of these API calls is to enable Csound, functioning as a VST plugin, to run a Csound score in synchronization with other tracks that might be running in the host. When the host gets to the end of a loop and jumps back to the beginning, the plugin calls the following sequence. I have added more comments to elucidate the purpose of the calls. The purpose of the isScorePending and setScorePending calls is tell the API client whether or not Csound will synthesize pending Csound score events, and for the API client to tell Csound to synthesize pending Csound score events. This is necessary because in some contexts, we want Csound to continue to process real-time events (i.e., MIDI events coming in from the host) without processing score events. I would be happy to change the API so that the only API required is SetScoreOffsetSeconds, which would seek to the desired time in the score, but this API would have to be bulletproofed so that no bad side effects would occur no matter when it was called. void CsoundVST::synchronizeScore() { vstPriorSamplePosition = vstCurrentSamplePosition; VstTimeInfo *vstTimeInfo = getTimeInfo(0); vstSr = double(vstTimeInfo->sampleRate); vstCurrentSamplePosition = (int) vstTimeInfo->samplePos; vstCurrentSampleBlockStart = vstTimeInfo->samplePos / vstSr; // This is how the plugin detects that the host is at the beginning of the Csound score, // either because the performance has just started, or because the host has looped back to the start. if((vstCurrentSamplePosition && !vstPriorSamplePosition) || (vstCurrentSamplePosition < vstPriorSamplePosition)) { // Retuns true if a valid Csound performance is underway, false otherwise (i.e., // score and orchestra have successfully compiled and Csound is now capable of processing audio). if(getCppSound()->getIsGo()) { // Tells Csound that it should actually process score events. (If called with 0, // VST events would still be processed, but events from the sco file would not be processed.) getCppSound()->setScorePending(1); // Rewinds the score file to the beginning. getCppSound()->rewindScore(); // Jumps to the point in the score file that is closest in the time to the current performance // time in the host. This is what actually synchronizes the Csound score with the host tracks. getCppSound()->setScoreOffsetSeconds(vstCurrentSampleBlockStart); csound::System::inform("Score synchronized at %f...\n", vstCurrentSampleBlockStart); } } } ------------------------------------------------------- This SF.Net email is sponsored by: NEC IT Guy Games. Get your fingers limbered up and give it your best shot. 4 great events, 4 opportunities to win big! Highest score wins.NEC IT Guy Games. Play to win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20 _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2005-05-08 21:07 |
From | Istvan Varga |
Subject | Re: [Cs-dev] Score rewinding |
Michael Gogins wrote: > The recent changes in score rewinding by Istvan Varga unfortunately > do not work in the context of VST plugins. They cause the host to hang. I have fixed a bug a few minutes ago, although it resulted in a crash, not a hang, so it may be a different problem. > The purpose of the isScorePending and setScorePending calls is tell the > API client whether or not Csound will synthesize pending Csound score events, > and for the API client to tell Csound to synthesize pending Csound score events. So, does this mean that setScorePending is 1 normally (although it defaults to 0 at this time), and when zero, events from the score should be skipped ? Or delayed until pending is set to 1 again ? > I would be happy to change the API so that the only API required is > SetScoreOffsetSeconds, which would seek to the desired time in the > score, but this API would have to be bulletproofed so that no bad side > effects would occur no matter when it was called. Unfortunately it is SetScoreOffsetSeconds that is more problematic than rewinding the score (as the operation of the latter can be defined more exactly). It has the following limitations: * works by entering a special "fast forward" mode, when kperf() does not perform any notes, or do any audio I/O; also, note events are discarded. One major disadvantage is that seeking to the requested time is slow: while it is faster than normal performance, you may still need to wait a few seconds if minutes are skipped. Perhaps this is why it seems to "hang" ? * can only seek forward (otherwise you need to rewind first) * as notes that would start during the skipped period are removed, you can get unexpected results due to skipping global "always on" notes (for reverb etc.). A note that starts at time zero is not skipped, however. * should be called between csoundPreCompile and csoundCompile, or after csoundCompile before performance. Calling after csoundCreate will not work because either csoundPreCompile or csoundCompile would reset first. ------------------------------------------------------- This SF.Net email is sponsored by: NEC IT Guy Games. Get your fingers limbered up and give it your best shot. 4 great events, 4 opportunities to win big! Highest score wins.NEC IT Guy Games. Play to win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20 _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2005-05-08 21:30 |
From | Istvan Varga |
Subject | Re: [Cs-dev] Score rewinding |
vanDongen/Gilcher wrote: > I am very happy that Istvan has now implemented these functions that are > documented in the API, but have never worked before for an application that > just links to libcsound. I only implemented RewindScore and ScoreOffsetSeconds, and the latter is far from being perfect (as explained in earlier post). The "pending" interface is still only a stub. Rewinding the score should work now, however, unless I misunderstand how it is intended to be used. I was able to play both scores and MIDI files in a loop by rewinding after some amount of time. This code repeats notes between 10 and 25 seconds in an endless loop: /* initialise Csound library */ csoundInitialize(&argc, &argv); /* Create Csound. */ csound = csoundCreate(NULL); /* One complete performance cycle. */ result = csoundCompile(csound, argc, argv); csoundSetScoreOffsetSeconds(csound, FL(10.0)); if (!result) { while (csoundPerformKsmps(csound) == 0) { if (csoundGetScoreTime(csound) >= FL(25.0)) csoundRewindScore(csound); } } /* delete Csound instance */ csoundDestroy(csound); ------------------------------------------------------- This SF.Net email is sponsored by: NEC IT Guy Games. Get your fingers limbered up and give it your best shot. 4 great events, 4 opportunities to win big! Highest score wins.NEC IT Guy Games. Play to win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20 _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2005-05-08 23:15 |
From | vanDongen/Gilcher |
Subject | Re: [Cs-dev] Score rewinding |
Attachments | None |