1 /******************************************************************************\
2  * Copyright (c) 2004-2019
3  *
4  * Author(s):
5  *  Volker Fischer
6  *
7  ******************************************************************************
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License as published by the Free Software
11  * Foundation; either version 2 of the License, or (at your option) any later
12  * version.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License along with
20  * this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
22  *
23 \******************************************************************************/
24 
25 #include "vstmain.h"
26 
27 /* Implementation *************************************************************/
28 // this function is required for host to get plugin
createEffectInstance(audioMasterCallback AudioMaster)29 AudioEffect* createEffectInstance ( audioMasterCallback AudioMaster ) { return new CLlconVST ( AudioMaster ); }
30 
CLlconVST(audioMasterCallback AudioMaster)31 CLlconVST::CLlconVST ( audioMasterCallback AudioMaster ) :
32     AudioEffectX ( AudioMaster, 1, 0 ), // 1 program with no parameters (=0)
33     Client ( LLCON_DEFAULT_PORT_NUMBER )
34 {
35     // stereo input/output
36     setNumInputs ( 2 );
37     setNumOutputs ( 2 );
38 
39     setUniqueID ( 'Llco' );
40 
41     // capabilities of llcon VST plugin
42     canProcessReplacing(); // supports replacing output
43 
44     // set default program name
45     GetName ( strProgName );
46 
47     // we want a single shot timer to shut down the connection if no
48     // processing is done anymore (VST host has stopped the stream)
49     TimerOnOff.setSingleShot ( true );
50     TimerOnOff.setInterval ( VST_STOP_TIMER_INTERVAL );
51 
52     // connect timer event
53     connect ( &TimerOnOff, SIGNAL ( timeout() ), this, SLOT ( OnTimerOnOff() ) );
54 
55     // clang-format off
56 // TODO settings
57 Client.SetServerAddr ( DEFAULT_SERVER_ADDRESS );
58     // clang-format on
59 }
60 
GetName(char * cName)61 bool CLlconVST::GetName ( char* cName )
62 {
63     // this name is used for program name, effect name, product string and
64     // vendor string
65     vst_strncpy ( cName, "Llcon", kVstMaxEffectNameLen );
66     return true;
67 }
68 
OnTimerOnOff()69 void CLlconVST::OnTimerOnOff()
70 {
71     // stop client since VST host seems to have stopped
72     Client.Stop();
73 }
74 
processReplacing(float ** pvIn,float ** pvOut,VstInt32 iNumSamples)75 void CLlconVST::processReplacing ( float** pvIn, float** pvOut, VstInt32 iNumSamples )
76 {
77     int i, j;
78 
79     // reset stop timer
80     TimerOnOff.start();
81 
82     // check if client is running, if not, start it
83     if ( !Client.IsRunning() )
84     {
85         // set buffer size and start
86         Client.GetSound()->SetMonoBufferSize ( iNumSamples );
87         Client.Start();
88     }
89 
90     // get pointers to actual buffers
91     float* pfIn0  = pvIn[0];
92     float* pfIn1  = pvIn[1];
93     float* pfOut0 = pvOut[0];
94     float* pfOut1 = pvOut[1];
95 
96     // copy input data
97     for ( i = 0, j = 0; i < iNumSamples; i++, j += 2 )
98     {
99         Client.GetSound()->vecsTmpAudioSndCrdStereo[j]     = pfIn0[i];
100         Client.GetSound()->vecsTmpAudioSndCrdStereo[j + 1] = pfIn1[i];
101     }
102 
103     // call processing callback function
104     Client.GetSound()->VSTProcessCallback();
105 
106     // copy output data
107     for ( i = 0, j = 0; i < iNumSamples; i++, j += 2 )
108     {
109         pfOut0[i] = Client.GetSound()->vecsTmpAudioSndCrdStereo[j];
110         pfOut1[i] = Client.GetSound()->vecsTmpAudioSndCrdStereo[j + 1];
111     }
112 }
113