| 886 | |
| 887 | |
| 888 | void RemoteVstPlugin::process( const sampleFrame * _in, sampleFrame * _out ) |
| 889 | { |
| 890 | // first we gonna post all MIDI-events we enqueued so far |
| 891 | if( m_midiEvents.size() ) |
| 892 | { |
| 893 | // since MIDI-events are not received immediately, we |
| 894 | // have to have them stored somewhere even after |
| 895 | // dispatcher-call, so we create static copies of the |
| 896 | // data and post them |
| 897 | #define MIDI_EVENT_BUFFER_COUNT 1024 |
| 898 | static char eventsBuffer[sizeof( VstEvents ) + sizeof( VstMidiEvent * ) * MIDI_EVENT_BUFFER_COUNT]; |
| 899 | static VstMidiEvent vme[MIDI_EVENT_BUFFER_COUNT]; |
| 900 | |
| 901 | // first sort events chronologically, since some plugins |
| 902 | // (e.g. Sinnah) can hang if they're out of order |
| 903 | std::stable_sort( m_midiEvents.begin(), m_midiEvents.end(), |
| 904 | []( const VstMidiEvent &a, const VstMidiEvent &b ) |
| 905 | { |
| 906 | return a.deltaFrames < b.deltaFrames; |
| 907 | } ); |
| 908 | |
| 909 | VstEvents* events = (VstEvents *) eventsBuffer; |
| 910 | events->reserved = 0; |
| 911 | events->numEvents = m_midiEvents.size(); |
| 912 | |
| 913 | int idx = 0; |
| 914 | for( VstMidiEventList::iterator it = m_midiEvents.begin(); it != m_midiEvents.end(); ++it, ++idx ) |
| 915 | { |
| 916 | memcpy( &vme[idx], &*it, sizeof( VstMidiEvent ) ); |
| 917 | events->events[idx] = (VstEvent *) &vme[idx]; |
| 918 | } |
| 919 | |
| 920 | m_midiEvents.clear(); |
| 921 | pluginDispatch( effProcessEvents, 0, 0, events ); |
| 922 | } |
| 923 | |
| 924 | // now we're ready to fetch sound from VST-plugin |
| 925 | |
| 926 | if( !tryLockShm() ) |
| 927 | { |
| 928 | return; |
| 929 | } |
| 930 | |
| 931 | if( !isShmValid() ) |
| 932 | { |
| 933 | unlockShm(); |
| 934 | return; |
| 935 | } |
| 936 | |
| 937 | for( int i = 0; i < inputCount(); ++i ) |
| 938 | { |
| 939 | m_inputs[i] = &((float *) _in)[i * bufferSize()]; |
| 940 | } |
| 941 | |
| 942 | for( int i = 0; i < outputCount(); ++i ) |
| 943 | { |
| 944 | m_outputs[i] = &((float *) _out)[i * bufferSize()]; |
| 945 | memset( m_outputs[i], 0, bufferSize() * sizeof( float ) ); |