/[svn]/linuxsampler/trunk/src/hostplugins/vst/PluginVst.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/hostplugins/vst/PluginVst.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1895 by persson, Sun May 3 12:15:40 2009 UTC revision 2165 by persson, Sun Feb 20 14:20:22 2011 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2   *                                                                         *   *                                                                         *
3   *   Copyright (C) 2008 Andreas Persson                                    *   *   Copyright (C) 2008 - 2011 Andreas Persson                             *
4   *                                                                         *   *                                                                         *
5   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
6   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 28  Line 28 
28    
29  #include "PluginVst.h"  #include "PluginVst.h"
30    
31    #ifndef CHANNELS
32    #define CHANNELS 32
33    #endif
34    
35  namespace {  namespace {
36    
37  #if defined(WIN32) && CONFIG_DEBUG_LEVEL >= 2  #if defined(WIN32) && CONFIG_DEBUG_LEVEL >= 2
# Line 39  namespace { Line 43  namespace {
43    
44      void log(const char* fmt, ...) {      void log(const char* fmt, ...) {
45          logmutex.Lock();          logmutex.Lock();
46          FILE* f = fopen("C:\\linuxsamplervst.log", "a");          FILE* f = fopen((String(getenv("TEMP")) + "\\linuxsamplervst.log").c_str(), "a");
47          va_list ap;          va_list ap;
48          va_start(ap, fmt);          va_start(ap, fmt);
49          vfprintf(f, fmt, ap);          vfprintf(f, fmt, ap);
# Line 82  namespace { Line 86  namespace {
86  #ifdef WIN32  #ifdef WIN32
87          // try to start the JSample Fantasia GUI as a separate process          // try to start the JSample Fantasia GUI as a separate process
88    
89          ProcessHandle = INVALID_HANDLE_VALUE;          // first check if it's already running
90            if (ProcessHandle != INVALID_HANDLE_VALUE) {
91                DWORD exitCode;
92                if (GetExitCodeProcess(ProcessHandle, &exitCode)) {
93                    if (exitCode == STILL_ACTIVE) return true;
94                }
95                free(Command);
96                CloseHandle(ProcessHandle);
97                ProcessHandle = INVALID_HANDLE_VALUE;
98            }
99    
100          // look for a Fantasia jar file in %programfiles%\LinuxSampler          // assume Fantasia is in the same directory or one directory above
101          if (const char* programfiles = getenv("PROGRAMFILES")) {          // the liblinuxsampler dll
102              String lspath = String(programfiles) + "\\LinuxSampler\\";          String lspath = LinuxSampler::Sampler::GetInstallDir();
103            if (!lspath.empty()) {
104                lspath += "\\";
105              WIN32_FIND_DATA fd;              WIN32_FIND_DATA fd;
106              HANDLE hFind = FindFirstFile((lspath + "Fantasia*.jar").c_str(), &fd);              HANDLE hFind = FindFirstFile((lspath + "Fantasia*.jar").c_str(), &fd);
107                if (hFind == INVALID_HANDLE_VALUE) {
108                    lspath += "..\\";
109                    hFind = FindFirstFile((lspath + "Fantasia*.jar").c_str(), &fd);
110                }
111              if (hFind != INVALID_HANDLE_VALUE) {              if (hFind != INVALID_HANDLE_VALUE) {
112                  String fantasia(fd.cFileName);                  String fantasia(fd.cFileName);
113                  FindClose(hFind);                  FindClose(hFind);
114    
115                  // start a java process                  // start a java process
116                  STARTUPINFO si;                  String path; // look in PATH first
117                  PROCESS_INFORMATION pi;                  for (int i = 0 ; i < 2 ; i++) { // two tries
118                  ZeroMemory(&si, sizeof(si));                      STARTUPINFO si;
119                  si.cb = sizeof(si);                      PROCESS_INFORMATION pi;
120                  ZeroMemory(&pi, sizeof(pi));                      ZeroMemory(&si, sizeof(si));
121                        si.cb = sizeof(si);
122                  Command = _tcsdup(TEXT((String("javaw -jar \"") + lspath + fantasia + "\" &").c_str()));                      ZeroMemory(&pi, sizeof(pi));
123                  CreateProcess(NULL, Command, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);  
124                  ProcessHandle = pi.hProcess;                      Command = _tcsdup(TEXT((String("\"") + path + "javaw\" -jar \"" +
125                                                lspath + fantasia + "\"").c_str()));
126                        if (CreateProcess(NULL, Command, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
127                            ProcessHandle = pi.hProcess;
128                            CloseHandle(pi.hThread);
129                            break;
130                        } else {
131                            free(Command);
132                            if (path.empty()) {
133                                // java wasn't found in PATH, try again
134                                // with an alternative directory
135                                char* windir = getenv("windir");
136                                if (!windir) break;
137    #ifdef _WIN64
138                                // LS plugin is 64 bit - look for 32 bit java
139                                path = String(windir) + "\\SysWOW64\\";
140    #else
141                                // LS plugin is 32 bit - look for 64 bit java
142                                path = String(windir) + "\\Sysnative\\";
143    #endif
144                            }
145                        }
146                    }
147              }              }
148          }          }
149  #endif  #endif
# Line 116  namespace { Line 157  namespace {
157          if (ProcessHandle != INVALID_HANDLE_VALUE) {          if (ProcessHandle != INVALID_HANDLE_VALUE) {
158              TerminateProcess(ProcessHandle, 0);              TerminateProcess(ProcessHandle, 0);
159              free(Command);              free(Command);
160                CloseHandle(ProcessHandle);
161              ProcessHandle = INVALID_HANDLE_VALUE;              ProcessHandle = INVALID_HANDLE_VALUE;
162          }          }
163  #endif  #endif
# Line 144  namespace { Line 186  namespace {
186          Programs = new LinuxSamplerVstProgram[NbPrograms];          Programs = new LinuxSamplerVstProgram[NbPrograms];
187          setProgram(0);          setProgram(0);
188          setNumInputs(0);          setNumInputs(0);
189          setNumOutputs(2);          setNumOutputs(CHANNELS);
190          canProcessReplacing();          canProcessReplacing();
191          isSynth();          isSynth();
192          programsAreChunks();          programsAreChunks();
# Line 159  namespace { Line 201  namespace {
201      void LinuxSamplerVst::resume() {      void LinuxSamplerVst::resume() {
202          dmsg(2, ("-->resume\n"));          dmsg(2, ("-->resume\n"));
203          if (!pAudioDevice) {          if (!pAudioDevice) {
204              Init(int(sampleRate), blockSize);              Init(int(sampleRate), blockSize, CHANNELS);
205    
206              if (!SavedChunk.empty()) {              if (!SavedChunk.empty()) {
207                  SetState(SavedChunk);                  SetState(SavedChunk);
# Line 168  namespace { Line 210  namespace {
210                  InitState();                  InitState();
211              }              }
212          } else {          } else {
213              Init(int(sampleRate), blockSize);              Init(int(sampleRate), blockSize, CHANNELS);
214          }          }
215            AudioEffectX::resume();
216          dmsg(2, ("<--resume\n"));          dmsg(2, ("<--resume\n"));
217      }      }
218    
# Line 200  namespace { Line 243  namespace {
243    
244      bool LinuxSamplerVst::getOutputProperties(VstInt32 index,      bool LinuxSamplerVst::getOutputProperties(VstInt32 index,
245                                                VstPinProperties* properties) {                                                VstPinProperties* properties) {
246          if (index < 2) {          if (index < CHANNELS) {
247              sprintf(properties->label, "LS %d", index + 1);              sprintf(properties->label, "LS %d", index + 1);
248              properties->flags = kVstPinIsActive | kVstPinIsStereo;              properties->flags = kVstPinIsActive | kVstPinIsStereo;
249              return true;              return true;
# Line 263  namespace { Line 306  namespace {
306      void LinuxSamplerVst::processReplacing(float** inputs, float** outputs,      void LinuxSamplerVst::processReplacing(float** inputs, float** outputs,
307                                             VstInt32 sampleFrames) {                                             VstInt32 sampleFrames) {
308          if (pAudioDevice) {          if (pAudioDevice) {
309              pAudioDevice->Channel(0)->SetBuffer(outputs[0]);              for (int i = 0 ; i < CHANNELS ; i++) {
310              pAudioDevice->Channel(1)->SetBuffer(outputs[1]);                  pAudioDevice->Channel(i)->SetBuffer(outputs[i]);
311                }
312              pAudioDevice->Render(sampleFrames);              pAudioDevice->Render(sampleFrames);
313          } else {          } else {
314              memset(outputs[0], 0, sampleFrames * sizeof(float));              for (int i = 0 ; i < CHANNELS ; i++) {
315              memset(outputs[1], 0, sampleFrames * sizeof(float));                  memset(outputs[i], 0, sampleFrames * sizeof(float));
316                }
317          }          }
318      }      }
319    

Legend:
Removed from v.1895  
changed lines
  Added in v.2165

  ViewVC Help
Powered by ViewVC