Update of /cvsroot/pure-data/externals/grill/vst/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3520/src
Modified Files: editor.h editorwin.hpp main.cpp vstedit.cpp vsthost.cpp vsthost.h vstmaster.cpp vstparam.cpp Log Message: much cleaner Window GUI code fixed bug with param method updated build system minimal feedback attribute for parameter reporting clean handling of plugin deletion (potentially open editor window etc.) updated for new flext function naming names containing spaces are now correctly dumped added event processing (like Midi in) more consistent MIDI functionality trying to catch crashing plugins
Index: vsthost.h =================================================================== RCS file: /cvsroot/pure-data/externals/grill/vst/src/vsthost.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** vsthost.h 13 Mar 2005 05:02:28 -0000 1.5 --- vsthost.h 16 Mar 2005 04:59:35 -0000 1.6 *************** *** 41,57 **** };
class VSTPlugin: public flext { public:
static void Setup();
VSTPlugin(Responder *resp); ~VSTPlugin();
! bool Instance(const char *plug,const char *subplug = NULL); void Free(); - void DspInit(float samplerate,int blocksize);
////////////////////////////////////////////////////////////////////////////// --- 41,65 ---- };
+ class VSTPlugin: public flext { public: + static VSTPlugin *New(Responder *resp); + static void Delete(VSTPlugin *p);
static void Setup();
+ bool Instance(const char *plug,const char *subplug = NULL); + void DspInit(float samplerate,int blocksize); + + private: VSTPlugin(Responder *resp); ~VSTPlugin();
! static ThrCond thrcond; ! static void worker(thr_params *p); ! void Free();
////////////////////////////////////////////////////////////////////////////// *************** *** 120,151 **** public: void SetPos(int x,int y,bool upd = true); void SetX(int x,bool upd = true) { SetPos(x,posy,upd); } void SetY(int y,bool upd = true) { SetPos(posx,y,upd); } int GetX() const { return posx; } int GetY() const { return posy; } void SetCaption(bool b); bool GetCaption() const { return caption; } void SetTitle(const char *t); const char *GetTitle() const { return title.c_str(); }
void Edit(bool open);
! void StartEditing(WHandle h ); void StopEditing(); bool IsEdited() const { return hwnd != NULL; } WHandle EditorHandle() const { return hwnd; }
void GetEditorRect(ERect &er) const { ERect *r; Dispatch(effEditGetRect,0,0,&r); er = *r; } void EditorIdle() { Dispatch(effEditIdle); }
! void Visible(bool vis); ! bool IsVisible() const;
void Paint(ERect &r) const { Dispatch(effEditDraw,0,0,&r); }
private: ! int posx,posy; // Window position bool caption; // Window border std::string title; // Window title
--- 128,170 ---- public: void SetPos(int x,int y,bool upd = true); + void SetSize(int x,int y,bool upd = true); void SetX(int x,bool upd = true) { SetPos(x,posy,upd); } void SetY(int y,bool upd = true) { SetPos(posx,y,upd); } + void SetW(int x,bool upd = true) { SetSize(x,sizey,upd); } + void SetH(int y,bool upd = true) { SetSize(sizex,y,upd); } int GetX() const { return posx; } int GetY() const { return posy; } + int GetW() const { return sizex; } + int GetH() const { return sizey; } void SetCaption(bool b); bool GetCaption() const { return caption; } + void SetHandle(bool h); + bool GetHandle() const { return handle; } void SetTitle(const char *t); const char *GetTitle() const { return title.c_str(); }
+ void ToFront();
void Edit(bool open);
! void StartEditing(WHandle h); void StopEditing(); bool IsEdited() const { return hwnd != NULL; } WHandle EditorHandle() const { return hwnd; } + void EditingEnded() { hwnd = NULL; thrcond.Signal(); }
void GetEditorRect(ERect &er) const { ERect *r; Dispatch(effEditGetRect,0,0,&r); er = *r; } void EditorIdle() { Dispatch(effEditIdle); }
! void Visible(bool vis,bool upd = true); ! bool IsVisible() const { return visible; }
void Paint(ERect &r) const { Dispatch(effEditDraw,0,0,&r); }
private: ! bool visible; ! int posx,posy,sizex,sizey; // Window position bool caption; // Window border + bool handle; // Window handle (like taskbar button) std::string title; // Window title
*************** *** 154,198 **** public: enum { ! MIDI_NOTEON = 144, ! MIDI_NOTEOFF = 128, ! MIDI_POLYAFTERTOUCH = 160, ! MIDI_CONTROLCHANGE = 176, ! MIDI_PROGRAMCHANGE = 192, ! MIDI_AFTERTOUCH = 208, ! MIDI_PITCHBEND = 224 };
bool AddMIDI(unsigned char data0,unsigned char data1 = 0,unsigned char data2 = 0);
static int range(int value,int mn = 0,int mx = 127) { return value < mn?mn:(value > mx?mx:value); }
! bool AddNoteOn(unsigned char note,unsigned char speed,unsigned char midichannel = 0) { ! return AddMIDI((char)MIDI_NOTEON|midichannel,note,speed); }
! bool AddNoteOff(unsigned char note,unsigned char midichannel = 0) { ! return AddMIDI((char)MIDI_NOTEOFF|midichannel,note,0); } void AddControlChange(int control,int value) { ! AddMIDI(MIDI_CONTROLCHANGE+(midichannel&0xf),range(control),range(value)); }
void AddProgramChange(int value) { ! AddMIDI(MIDI_PROGRAMCHANGE+(midichannel&0xf),range(value),0); }
void AddPitchBend(int value) { ! AddMIDI(MIDI_PITCHBEND+(midichannel&0xf),((value>>7)&127),(value&127)); }
void AddAftertouch(int value) { ! AddMIDI((char)MIDI_AFTERTOUCH|midichannel,range(value)); }
--- 173,229 ---- public: enum { ! MIDI_NOTEOFF = 0x80, ! MIDI_NOTEON = 0x90, ! MIDI_POLYAFTERTOUCH = 0xa0, ! MIDI_CONTROLCHANGE = 0xb0, ! MIDI_PROGRAMCHANGE = 0xc0, ! MIDI_AFTERTOUCH = 0xd0, ! MIDI_PITCHBEND = 0xe0, ! MIDI_SYSEX = 0xf0, };
+ void SetEvents(bool ev) { dumpevents = ev; } + bool GetEvents() const { return dumpevents; } + bool AddMIDI(unsigned char data0,unsigned char data1 = 0,unsigned char data2 = 0);
static int range(int value,int mn = 0,int mx = 127) { return value < mn?mn:(value > mx?mx:value); }
! void SetChannel(int channel) { midichannel = range(channel,0,0xf); } ! int GetChannel() const { return midichannel; } ! ! bool AddNoteOn(unsigned char note,unsigned char speed /*,unsigned char midichannel = 0*/) { ! return AddMIDI(MIDI_NOTEON+midichannel,note,speed); }
! bool AddNoteOff(unsigned char note /*,unsigned char midichannel = 0*/) { ! return AddMIDI(MIDI_NOTEOFF+midichannel,note,0); } void AddControlChange(int control,int value) { ! AddMIDI(MIDI_CONTROLCHANGE+midichannel,range(control),range(value)); }
void AddProgramChange(int value) { ! AddMIDI(MIDI_PROGRAMCHANGE+midichannel,range(value),0); }
void AddPitchBend(int value) { ! AddMIDI(MIDI_PITCHBEND+midichannel,((value>>7)&127),(value&127)); }
void AddAftertouch(int value) { ! AddMIDI(MIDI_AFTERTOUCH+midichannel,range(value)); ! } ! ! void AddPolyAftertouch(unsigned char note,int value) ! { ! AddMIDI(MIDI_POLYAFTERTOUCH+midichannel,note,range(value)); }
*************** *** 206,209 **** --- 237,241 ----
char midichannel; + bool dumpevents;
//////////////////////////////////////////////////////////////////////////////
Index: vstparam.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/vst/src/vstparam.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** vstparam.cpp 11 Mar 2005 04:58:01 -0000 1.1 --- vstparam.cpp 16 Mar 2005 04:59:36 -0000 1.2 *************** *** 17,20 **** --- 17,21 ---- // cast to unsigned char since isspace functions don't want characters like 0x80 = -128 if(isspace(((unsigned char *)txt)[i])) txt[i] = 0; + else break; }
Index: vstedit.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/vst/src/vstedit.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** vstedit.cpp 11 Mar 2005 04:58:01 -0000 1.1 --- vstedit.cpp 16 Mar 2005 04:59:35 -0000 1.2 *************** *** 28,32 **** FLEXT_ASSERT(h != NULL); Dispatch(effEditOpen,0,0,hwnd = h); - // Dispatch(effEditTop);
TitleEditor(this,title.c_str()); --- 28,31 ---- *************** *** 35,76 **** void VSTPlugin::StopEditing() { ! if(Is()) { ! Dispatch(effEditClose); ! hwnd = NULL; ! } }
! void VSTPlugin::Visible(bool vis) { ! if(Is() && IsEdited()) ShowEditor(this,vis); }
! bool VSTPlugin::IsVisible() const ! { ! return Is() && IsEdited() && IsEditorShown(this); }
! ! void VSTPlugin::SetPos(int x,int y,bool upd) { ! if(Is()) { ! posx = x; posy = y; ! if(upd && IsEdited()) MoveEditor(this,posx,posy); ! } }
void VSTPlugin::SetCaption(bool c) { ! if(Is()) { ! caption = c; ! if(IsEdited()) CaptionEditor(this,c); ! } }
void VSTPlugin::SetTitle(const char *t) { ! if(Is()) { ! title = t; ! if(IsEdited()) TitleEditor(this,t); } } --- 34,82 ---- void VSTPlugin::StopEditing() { ! if(Is() && IsEdited()) ! Dispatch(effEditClose); }
! void VSTPlugin::Visible(bool vis,bool upd) { ! visible = vis; ! if(upd && Is() && IsEdited()) ShowEditor(this,vis); }
! void VSTPlugin::SetPos(int x,int y,bool upd) ! { ! posx = x; posy = y; ! if(upd && Is() && IsEdited()) MoveEditor(this,posx,posy); }
! void VSTPlugin::SetSize(int x,int y,bool upd) { ! sizex = x; sizey = y; ! if(upd && Is() && IsEdited()) SizeEditor(this,sizex,sizey); }
void VSTPlugin::SetCaption(bool c) { ! caption = c; ! if(Is() && IsEdited()) CaptionEditor(this,c); ! } ! ! void VSTPlugin::SetHandle(bool h) ! { ! handle = h; ! if(Is() && IsEdited()) HandleEditor(this,h); }
void VSTPlugin::SetTitle(const char *t) { ! title = t; ! if(Is() && IsEdited()) TitleEditor(this,t); ! } ! ! void VSTPlugin::ToFront() ! { ! if(Is() && IsEdited()) { ! FrontEditor(this); ! Dispatch(effEditTop,0,0,vendorname); } }
Index: vstmaster.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/vst/src/vstmaster.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** vstmaster.cpp 13 Mar 2005 05:02:28 -0000 1.3 --- vstmaster.cpp 16 Mar 2005 04:59:35 -0000 1.4 *************** *** 17,21 **** void VSTPlugin::ProcessEvent(const VstEvent &ev) { ! if(!responder) return;
if(ev.type == kVstMidiType) { --- 17,21 ---- void VSTPlugin::ProcessEvent(const VstEvent &ev) { ! if(!responder && dumpevents) return;
if(ev.type == kVstMidiType) {
Index: vsthost.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/vst/src/vsthost.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** vsthost.cpp 13 Mar 2005 05:02:28 -0000 1.5 --- vsthost.cpp 16 Mar 2005 04:59:35 -0000 1.6 *************** *** 9,13 ****
#include "vsthost.h" !
const t_symbol --- 9,15 ----
#include "vsthost.h" ! #include "editor.h" ! #include <exception> ! #include "flcontainers.h"
const t_symbol *************** *** 23,28 **** --- 25,44 ---- *VSTPlugin::sym_midi[8];
+ + class DelPlugin + : public Fifo::Cell + { + public: + DelPlugin(VSTPlugin *p): plug(p) {} + VSTPlugin *plug; + }; + + static TypedLifo<DelPlugin> todel; + flext::ThrCond VSTPlugin::thrcond; + void VSTPlugin::Setup() { + LaunchThread(worker); + sym_param = flext::MakeSymbol("param"); sym_event = flext::MakeSymbol("event"); *************** *** 35,46 **** sym_ev_ = flext::MakeSymbol("???");
! sym_midi[0] = flext::MakeSymbol("noteon"); ! sym_midi[1] = flext::MakeSymbol("noteoff"); ! sym_midi[2] = flext::MakeSymbol("polyafter"); ! sym_midi[3] = flext::MakeSymbol("cntl"); sym_midi[4] = flext::MakeSymbol("progchg"); ! sym_midi[5] = flext::MakeSymbol("chnafter"); ! sym_midi[6] = flext::MakeSymbol("pitchbend"); ! sym_midi[7] = sym__; }
--- 51,62 ---- sym_ev_ = flext::MakeSymbol("???");
! sym_midi[0] = flext::MakeSymbol("noteoff"); ! sym_midi[1] = flext::MakeSymbol("note"); ! sym_midi[2] = flext::MakeSymbol("atouch"); ! sym_midi[3] = flext::MakeSymbol("ctlchg"); sym_midi[4] = flext::MakeSymbol("progchg"); ! sym_midi[5] = flext::MakeSymbol("atouch"); ! sym_midi[6] = flext::MakeSymbol("pbend"); ! sym_midi[7] = flext::MakeSymbol("sysex"); }
*************** *** 49,54 **** , effect(NULL),pluginmain(NULL),audiomaster(NULL) , responder(resp) ! , posx(0),posy(0),caption(true) ! , midichannel(0),eventqusz(0) , paramnamecnt(0) , transchg(true) --- 65,71 ---- , effect(NULL),pluginmain(NULL),audiomaster(NULL) , responder(resp) ! , posx(0),posy(0),sizex(0),sizey(0) ! , visible(true),caption(true),handle(false) ! , midichannel(0),eventqusz(0),dumpevents(false) , paramnamecnt(0) , transchg(true) *************** *** 68,72 **** --- 85,137 ---- }
+ VSTPlugin *VSTPlugin::New(Responder *resp) + { + FLEXT_ASSERT(resp); + return new VSTPlugin(resp); + } + + void VSTPlugin::Delete(VSTPlugin *p) + { + FLEXT_ASSERT(p); + + // tell plugin to close editor! + StopEditor(p); + // transfer to deletion thread + todel.Push(new DelPlugin(p)); + thrcond.Signal(); + } + + void VSTPlugin::worker(thr_params *) + { + TypedLifo<DelPlugin> tmp; + bool again = false; + for(;;) { + // wait for signal + if(again) { + thrcond.TimedWait(0.01); + again = false; + } + else + thrcond.Wait(); + + DelPlugin *p; + while((p = todel.Pop()) != NULL) { + // see if editing has stopped + if(p && p->plug->hwnd == NULL) { + // yes, it is now safe to delete the plug + delete p->plug; + delete p; + } + else { + tmp.Push(p); + again = true; + } + }
+ // put back remaining entries + while((p = tmp.Pop()) != NULL) todel.Push(p); + } + } + #if FLEXT_OS == FLEXT_OS_MAC OSStatus FSPathMakeFSSpec(const UInt8 *path,FSSpec *spec,Boolean *isDirectory) /* can be NULL */ *************** *** 209,215 ****
//This calls the "main" function and receives the pointer to the AEffect structure. ! effect = pluginmain(audiomaster); ! if(!effect || effect->magic != kEffectMagic) { ! post("VST plugin : Unable to create effect"); effect = NULL; return false; --- 274,288 ----
//This calls the "main" function and receives the pointer to the AEffect structure. ! try { effect = pluginmain(audiomaster); } ! catch(exception &e) { ! flext::post("vst~ - caught exception while instantiating plugin: %s",e.what()); ! } ! catch(...) { ! flext::post("vst~ - caught exception while instantiating plugin"); ! } ! ! if(!effect) ! return false; ! else if(effect->magic != kEffectMagic) { effect = NULL; return false; *************** *** 220,225 **** bool VSTPlugin::Instance(const char *name,const char *subname) { ! bool ok = effect != NULL;
if(!ok && dllname != name) { FreePlugin(); --- 293,302 ---- bool VSTPlugin::Instance(const char *name,const char *subname) { ! bool ok = false; ! FLEXT_ASSERT(effect == NULL);
+ try { + + /* if(!ok && dllname != name) { FreePlugin(); *************** *** 227,230 **** --- 304,309 ---- ok = NewPlugin(name) && InstPlugin(); } + */ + ok = NewPlugin(name) && InstPlugin();
if(ok && subname && *subname && Dispatch(effGetPlugCategory) == kPlugCategShell) { *************** *** 295,318 **** }
if(!ok) Free(); return ok; }
! void VSTPlugin::Free() // Called also in destruction { ! if(effect) { ! Edit(false);
! // shut down plugin ! Dispatch(effMainsChanged, 0, 0); ! Dispatch(effClose); ! }
! // \TODO ! // Here, we really have to wait until the editor thread has terminated ! // otherwise WM_DESTROY etc. messages may still be pending ! // in other words: this is a design flaw ! // There should be a data stub accessible from the plugin object and the thread ! // holding the necessary data, so that both can operate independently
FreePlugin(); --- 374,405 ---- }
+ } + catch(exception &e) { + flext::post("vst~ - caught exception while loading plugin: %s",e.what()); + ok = false; + } + catch(...) { + flext::post("vst~ - Caught exception while loading plugin"); + ok = false; + } + if(!ok) Free(); return ok; }
! void VSTPlugin::Free() { ! // This should only also in destruction
! try { ! if(effect) { ! FLEXT_ASSERT(!IsEdited());
! // shut down plugin ! Dispatch(effMainsChanged, 0, 0); ! Dispatch(effClose); ! } ! } ! catch(...) {}
FreePlugin(); *************** *** 321,329 **** void VSTPlugin::DspInit(float sr,int blsz) { ! // sample rate and block size must _first_ be set ! Dispatch(effSetSampleRate,0,0,NULL,samplerate = sr); ! Dispatch(effSetBlockSize, 0,blsz); ! // then signal that mains have changed! ! Dispatch(effMainsChanged,0,1); }
--- 408,424 ---- void VSTPlugin::DspInit(float sr,int blsz) { ! try { ! // sample rate and block size must _first_ be set ! Dispatch(effSetSampleRate,0,0,NULL,samplerate = sr); ! Dispatch(effSetBlockSize, 0,blsz); ! // then signal that mains have changed! ! Dispatch(effMainsChanged,0,1); ! } ! catch(exception &e) { ! flext::post("vst~ - caught exception while initializing dsp: %s",e.what()); ! } ! catch(...) { ! flext::post("vst~ - caught exception while initializing dsp"); ! } }
Index: editorwin.hpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/vst/src/editorwin.hpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** editorwin.hpp 11 Mar 2005 04:58:01 -0000 1.2 --- editorwin.hpp 16 Mar 2005 04:59:35 -0000 1.3 *************** *** 3,7 **** based on the work of Jarno Seppänen and Mark Williamson
! Copyright (c)2003-2004 Thomas Grill (xovo@gmx.net) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution. --- 3,7 ---- based on the work of Jarno Seppänen and Mark Williamson
! Copyright (c)2003-2005 Thomas Grill (gr@grrrr.org) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution. *************** *** 38,47 **** plug->StartEditing(hwnd); break; case WM_CLOSE: #ifdef FLEXT_LOGGING flext::post("WM_CLOSE"); #endif ! // plug could already have been unloaded... ! plug->StopEditing(); // this sets plug->hwnd = NULL DestroyWindow(hwnd); break; --- 38,48 ---- plug->StartEditing(hwnd); break; + case WM_CLOSE: #ifdef FLEXT_LOGGING flext::post("WM_CLOSE"); #endif ! plug->StopEditing(); ! DestroyWindow(hwnd); break; *************** *** 58,62 **** --- 59,82 ---- plug->EditorIdle(); break; + #if 0 + case WM_WINDOWPOSCHANGED: { + // ignore after WM_CLOSE so that x,y positions are preserved + if(!plug->IsEdited()) break; + + WINDOWPOS *w = (WINDOWPOS *)lp;
+ WINDOWINFO winfo; + winfo.cbSize = sizeof(winfo); + GetWindowInfo(hwnd,&winfo); + int cpx = winfo.rcWindow.left-winfo.rcClient.left; + int cpy = winfo.rcWindow.top-winfo.rcClient.top; + int csx = winfo.rcWindow.right-winfo.rcClient.right-cpx; + int csy = winfo.rcWindow.bottom-winfo.rcClient.bottom-cpy; + // send normalized coordinates to plugin + plug->SetPos(w->x+cpx,w->y+cpy,false); + plug->SetSize(w->cx+csx,w->cy+csy,false); + return 0; + } + #else case WM_MOVE: { // ignore after WM_CLOSE so that x,y positions are preserved *************** *** 66,75 **** short x = reinterpret_cast<short &>(wx),y = reinterpret_cast<short &>(wy); // x and y are the coordinates of the client rect (= actual VST interface) ! plug->SetPos(x,y,false); ! #ifdef FLEXT_LOGGING ! flext::post("WM_MOVE x/y=%i/%i",x,y); ! #endif break; }
#if 0 // NOT needed for Windows --- 86,119 ---- short x = reinterpret_cast<short &>(wx),y = reinterpret_cast<short &>(wy); // x and y are the coordinates of the client rect (= actual VST interface) ! ! WINDOWINFO winfo; ! winfo.cbSize = sizeof(winfo); ! GetWindowInfo(hwnd,&winfo); ! int px = winfo.rcWindow.left-winfo.rcClient.left; ! int py = winfo.rcWindow.top-winfo.rcClient.top; ! // send normalized coordinates to plugin ! plug->SetPos(x+px,y+py,false); ! break; ! } ! ! case WM_SIZE: { ! if(!plug->IsEdited()) break; ! ! WORD wx = LOWORD(lp),wy = HIWORD(lp); ! short x = reinterpret_cast<short &>(wx),y = reinterpret_cast<short &>(wy); ! // x and y are the coordinates of the client rect (= actual VST interface) ! ! WINDOWINFO winfo; ! winfo.cbSize = sizeof(winfo); ! GetWindowInfo(hwnd,&winfo); ! int px = winfo.rcWindow.left-winfo.rcClient.left; ! int py = winfo.rcWindow.top-winfo.rcClient.top; ! int sx = winfo.rcWindow.right-winfo.rcClient.right-px; ! int sy = winfo.rcWindow.bottom-winfo.rcClient.bottom-py; ! // send normalized coordinates to plugin ! plug->SetSize(x+sx,y+sy,false); break; } + #endif
#if 0 // NOT needed for Windows *************** *** 87,100 **** } #endif ! ! #if 0 //def FLEXT_LOGGING ! case WM_SIZE: { ! WORD wx = LOWORD(lp),wy = HIWORD(lp); ! short x = reinterpret_cast<short &>(wx),y = reinterpret_cast<short &>(wy); ! // x and y are the coordinates of the client rect (= actual VST interface) ! flext::post("WM_SIZE x/y=%i/%i",x,y); ! break; ! } ! #endif
default: --- 131,137 ---- } #endif ! case WM_SHOWWINDOW: ! plug->Visible(wp != FALSE,false); ! break;
default: *************** *** 108,127 **** }
! static void windowsize(HWND wnd,int x,int y,int w,int h,bool caption,LONG flags = 0) { ! WINDOWINFO winfo; winfo.cbSize = sizeof(winfo); GetWindowInfo(wnd,&winfo);
! int cy = caption?GetSystemMetrics(SM_CYCAPTION):0;
! SetWindowPos(wnd,HWND_TOP, ! x-(winfo.rcClient.left-winfo.rcWindow.left), ! y-(winfo.rcClient.top-winfo.rcWindow.top), ! w+winfo.cxWindowBorders*2, ! h+cy+winfo.cyWindowBorders*2, ! flags ! );
}
--- 145,167 ---- }
! static void windowsize(HWND wnd,int x,int y,int w,int h) { ! // pre correction ! WINDOWINFO winfo; winfo.cbSize = sizeof(winfo); GetWindowInfo(wnd,&winfo); + int sx1 = (winfo.rcWindow.right-winfo.rcClient.right)-(winfo.rcWindow.left-winfo.rcClient.left); + int sy1 = (winfo.rcWindow.bottom-winfo.rcClient.bottom)-(winfo.rcWindow.top-winfo.rcClient.top);
! // First reflect new state in flags ! SetWindowPos(wnd,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED);
! // post correction ! GetWindowInfo(wnd,&winfo); ! int sx2 = (winfo.rcWindow.right-winfo.rcClient.right)-(winfo.rcWindow.left-winfo.rcClient.left); ! int sy2 = (winfo.rcWindow.bottom-winfo.rcClient.bottom)-(winfo.rcWindow.top-winfo.rcClient.top);
+ // set pos, size and flags + SetWindowPos(wnd,NULL,x,y,w+sx2-sx1,h+sy2-sy1,SWP_NOZORDER); }
*************** *** 138,149 **** mapmutex.Unlock();
- char tmp[256]; sprintf(tmp,"vst~ - %s",plug->GetName());
! HWND wnd = CreateWindow( WCLNAME,tmp, ! (plug->GetCaption()?WS_BORDER|WS_CAPTION:0)|WS_POPUP|WS_SYSMENU|WS_MINIMIZEBOX, ! CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT, NULL,NULL, hinstance,NULL --- 178,193 ---- mapmutex.Unlock();
char tmp[256]; sprintf(tmp,"vst~ - %s",plug->GetName());
! // Get size from plugin ! ERect r; ! plug->GetEditorRect(r); ! ! HWND wnd = CreateWindowEx( ! plug->GetHandle()?WS_EX_APPWINDOW:WS_EX_TOOLWINDOW, WCLNAME,tmp, ! WS_POPUP|WS_SYSMENU|WS_MINIMIZEBOX, // no border for the beginning to set proper coordinates ! plug->GetX(),plug->GetY(),r.right-r.left,r.bottom-r.top, NULL,NULL, hinstance,NULL *************** *** 153,184 **** FLEXT_LOG1("wnd == NULL: %i",GetLastError()); else { ! // plug->Dispatch(effEditOpen , 0 , 0 , wnd, 0.0f ); // Done in WNDPROC!! ! /* ! CString str = theApp->GetProfileString( "VSTPos" , plug->GetName() , "10,10"); ! int idx = str.Find(","); ! CString x = str.Left( idx ); ! CString y = str.Right( idx ); ! printf(" index is %d left is %s and right is %s" , idx , x , y); ! */
! // plug->Dispatch(effEditTop,0,0, 0,0.0f); ! // printf("Dispatched to the top\n");
! SetTimer(wnd,0,TIMER_INTERVAL,NULL);
! ERect r; ! plug->GetEditorRect(r); ! windowsize(wnd,plug->GetX(),plug->GetY(),r.right-r.left,r.bottom-r.top,plug->GetCaption(),SWP_SHOWWINDOW); ! #ifdef FLEXT_LOGGING ! flext::post("Editor rect left/top=%i/%i, right/bottom=%i/%i",r.left,r.top,r.right,r.bottom); ! #endif
! // SetFocus();
! // Message pump MSG msg; BOOL bRet; while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0) { ! if (bRet == -1) { // handle the error and possibly exit FLEXT_LOG1("GetMessage error: %i",GetLastError()); --- 197,224 ---- FLEXT_LOG1("wnd == NULL: %i",GetLastError()); else { ! // idle timer ! SetTimer(wnd,0,TIMER_INTERVAL,NULL);
! // set caption style ! CaptionEditor(plug,plug->GetCaption());
! if(plug->IsVisible()) { ! SetForegroundWindow(wnd); ! ShowWindow(wnd,1);
! // notify plugin ! // plug->Dispatch(effEditTop,0,0,0,0); ! } ! else ! ShowWindow(wnd,0);
! try ! {
! // Message loop MSG msg; BOOL bRet; while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0) { ! if(bRet == -1) { // handle the error and possibly exit FLEXT_LOG1("GetMessage error: %i",GetLastError()); *************** *** 189,195 **** } } - }
! // UnregisterClass(wcx.lpszClassName,hinstance);
mapmutex.Lock(); --- 229,244 ---- } }
! } ! ! catch(exception &e) { ! flext::post("vst~ - exception caught, exiting: %s",e.what()); ! } ! catch(...) { ! flext::post("vst~ - exception caught, exiting"); ! } ! ! if(plug) plug->EditingEnded(); ! }
mapmutex.Lock(); *************** *** 236,240 **** #endif PostMessage(p->EditorHandle(),WM_CLOSE,0,0); ! flext::StopThread(threadfun,reinterpret_cast<flext::thr_params *>(p)); #ifdef FLEXT_LOGGING flext::post("Stop editor 2"); --- 285,289 ---- #endif PostMessage(p->EditorHandle(),WM_CLOSE,0,0); ! // flext::StopThread(threadfun,reinterpret_cast<flext::thr_params *>(p)); #ifdef FLEXT_LOGGING flext::post("Stop editor 2"); *************** *** 250,268 **** { HWND wnd = p->EditorHandle(); ! ! WINDOWINFO winfo; ! winfo.cbSize = sizeof(winfo); ! GetWindowInfo(wnd,&winfo); ! ! SetWindowPos(wnd,NULL, ! x-(winfo.rcClient.left-winfo.rcWindow.left),y-(winfo.rcClient.top-winfo.rcWindow.top), ! 0,0, ! SWP_NOSIZE|SWP_NOZORDER ! ); }
void SizeEditor(VSTPlugin *p,int x,int y) { ! SetWindowPos(p->EditorHandle(),NULL,0,0,x,y,SWP_NOMOVE|SWP_NOZORDER); }
--- 299,314 ---- { HWND wnd = p->EditorHandle(); ! SetWindowPos(wnd,NULL,x,y,0,0,SWP_NOSIZE|SWP_NOZORDER); }
void SizeEditor(VSTPlugin *p,int x,int y) { ! HWND wnd = p->EditorHandle(); ! SetWindowPos(wnd,NULL,0,0,x,y,SWP_NOMOVE|SWP_NOZORDER); ! } ! ! void FrontEditor(VSTPlugin *p) ! { ! SetForegroundWindow(p->EditorHandle()); }
*************** *** 275,284 **** if(ns != style) { SetWindowLong(wnd,GWL_STYLE,ns); ! ! ERect r; plug->GetEditorRect(r); ! windowsize(wnd,plug->GetX(),plug->GetY(),r.right-r.left,r.bottom-r.top,c,SWP_FRAMECHANGED); } }
void TitleEditor(VSTPlugin *p,const char *t) { --- 321,337 ---- if(ns != style) { SetWindowLong(wnd,GWL_STYLE,ns); ! windowsize(wnd,plug->GetX(),plug->GetY(),plug->GetW(),plug->GetH()); } }
+ void HandleEditor(VSTPlugin *plug,bool h) + { + HWND wnd = plug->EditorHandle(); + bool v = plug->IsVisible(); + if(v) ShowWindow(wnd,FALSE); + SetWindowLong(wnd,GWL_EXSTYLE,h?WS_EX_APPWINDOW:WS_EX_TOOLWINDOW); + if(v) ShowWindow(wnd,TRUE); + } + void TitleEditor(VSTPlugin *p,const char *t) { *************** *** 286,291 **** --- 339,346 ---- }
+ /* bool IsEditorShown(const VSTPlugin *p) { return IsWindowVisible(p->EditorHandle()) != FALSE; } + */ \ No newline at end of file
Index: main.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/vst/src/main.cpp,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** main.cpp 13 Mar 2005 05:02:27 -0000 1.24 --- main.cpp 16 Mar 2005 04:59:35 -0000 1.25 *************** *** 27,31 ****
! #define VST_VERSION "0.1.0pre21"
--- 27,31 ----
! #define VST_VERSION "0.1.0pre23"
*************** *** 65,74 **** --- 65,81 ---- void mg_winx(int &x) const { x = plug?plug->GetX():0; } void mg_winy(int &y) const { y = plug?plug->GetY():0; } + void mg_winw(int &x) const { x = plug?plug->GetW():0; } + void mg_winh(int &y) const { y = plug?plug->GetH():0; } void ms_winx(int x) { if(plug) plug->SetX(x); } void ms_winy(int y) { if(plug) plug->SetY(y); } + void ms_winw(int x) { if(plug) plug->SetW(x); } + void ms_winh(int y) { if(plug) plug->SetH(y); } void ms_wincaption(bool c) { if(plug) plug->SetCaption(c); } void mg_wincaption(bool &c) const { c = plug && plug->GetCaption(); } + void ms_winhandle(bool c) { if(plug) plug->SetHandle(c); } + void mg_winhandle(bool &c) const { c = plug && plug->GetHandle(); } void ms_wintitle(const AtomList &t); void mg_wintitle(AtomList &t) const { if(plug) { t(1); SetString(t[0],plug->GetTitle()); } } + void m_winfront() const { if(plug) plug->ToFront(); }
void mg_chnsin(int &c) const { c = plug?plug->GetNumInputs():0; } *************** *** 99,109 **** void m_ptexts(int argc,const t_atom *argv);
! // void m_control(const t_symbol *ctrl_name,int ctrl_value); ! void m_pitchbend(int ctrl_value) { if(plug) plug->AddPitchBend(ctrl_value ); } ! void m_programchange(int ctrl_value) { if(plug) plug->AddProgramChange(ctrl_value ); } ! void m_aftertouch(int ctrl_value) { if(plug) plug->AddAftertouch(ctrl_value ); } ! void m_ctrlchange(int control,int ctrl_value) { if(plug) plug->AddControlChange(control,ctrl_value ); } void m_note(int note,int vel); void m_noteoff(int note) { m_note(note,0); }
void mg_playing(bool &p) { p = plug && plug->GetPlaying(); } --- 106,122 ---- void m_ptexts(int argc,const t_atom *argv);
! void mg_channel(int &chn) const { chn = plug?plug->GetChannel():0; } ! void ms_channel(int chn) { if(plug) plug->SetChannel(chn); } ! void m_note(int note,int vel); void m_noteoff(int note) { m_note(note,0); } + void m_programchange(int ctrl_value) { if(plug) plug->AddProgramChange(ctrl_value); } + void m_ctrlchange(int control,int ctrl_value) { if(plug) plug->AddControlChange(control,ctrl_value); } + void m_aftertouch(int ctrl_value) { if(plug) plug->AddAftertouch(ctrl_value); } + void m_polyaftertouch(int note,int ctrl_value) { if(plug) plug->AddPolyAftertouch(note,ctrl_value); } + void m_pitchbend(int ctrl_value) { if(plug) plug->AddPitchBend(ctrl_value); } + + void mg_dumpevents(bool &ev) const { ev = plug?plug->GetEvents():false; } + void ms_dumpevents(bool ev) { if(plug) plug->SetEvents(ev); }
void mg_playing(bool &p) { p = plug && plug->GetPlaying(); } *************** *** 141,145 **** VSTPlugin *plug; std::string plugname,subplug; ! bool echoparam,visible,bypass,mute; int paramnames;
--- 154,158 ---- VSTPlugin *plug; std::string plugname,subplug; ! bool visible,bypass,mute; int paramnames;
*************** *** 172,181 **** FLEXT_ATTRVAR_B(mute)
! // FLEXT_CALLBACK_2(m_control,t_symptr,int) ! FLEXT_CALLBACK_I(m_pitchbend) ! FLEXT_CALLBACK_I(m_aftertouch) ! FLEXT_CALLBACK_I(m_programchange) FLEXT_CALLBACK_II(m_ctrlchange)
FLEXT_CALLVAR_I(mg_program,ms_program) FLEXT_CALLBACK_V(mg_progname) --- 185,199 ---- FLEXT_ATTRVAR_B(mute)
! FLEXT_CALLVAR_I(mg_channel,ms_channel) ! FLEXT_CALLBACK_II(m_note) ! FLEXT_CALLBACK_I(m_noteoff) FLEXT_CALLBACK_II(m_ctrlchange) + FLEXT_CALLBACK_I(m_aftertouch) + FLEXT_CALLBACK_II(m_polyaftertouch) + FLEXT_CALLBACK_I(m_pitchbend) + + FLEXT_CALLVAR_B(mg_dumpevents,ms_dumpevents)
+ FLEXT_CALLBACK_I(m_programchange) FLEXT_CALLVAR_I(mg_program,ms_program) FLEXT_CALLBACK_V(mg_progname) *************** *** 191,202 **** FLEXT_CALLBACK_V(m_ptexts)
- FLEXT_CALLBACK_II(m_note) - FLEXT_CALLBACK_I(m_noteoff) - - FLEXT_ATTRVAR_B(echoparam) FLEXT_CALLVAR_I(mg_winx,ms_winx) FLEXT_CALLVAR_I(mg_winy,ms_winy) FLEXT_CALLVAR_B(mg_wincaption,ms_wincaption) FLEXT_CALLVAR_V(mg_wintitle,ms_wintitle)
FLEXT_CALLGET_I(mg_chnsin) --- 209,220 ---- FLEXT_CALLBACK_V(m_ptexts)
FLEXT_CALLVAR_I(mg_winx,ms_winx) FLEXT_CALLVAR_I(mg_winy,ms_winy) + FLEXT_CALLVAR_I(mg_winw,ms_winw) + FLEXT_CALLVAR_I(mg_winh,ms_winh) FLEXT_CALLVAR_B(mg_wincaption,ms_wincaption) + FLEXT_CALLVAR_B(mg_winhandle,ms_winhandle) FLEXT_CALLVAR_V(mg_wintitle,ms_wintitle) + FLEXT_CALLBACK(m_winfront)
FLEXT_CALLGET_I(mg_chnsin) *************** *** 251,260 **** FLEXT_CADDMETHOD_(c,0,"print",m_print);
! FLEXT_CADDMETHOD_II(c,0,"note",m_note); FLEXT_CADDMETHOD_I(c,0,"noteoff",m_noteoff); ! // FLEXT_CADDMETHOD_2(c,0,"control",m_control,t_symptr,int); ! FLEXT_CADDMETHOD_(c,0,"pbend",m_pitchbend); ! FLEXT_CADDMETHOD_(c,0,"atouch",m_aftertouch); FLEXT_CADDMETHOD_II(c,0,"ctlchg",m_ctrlchange);
FLEXT_CADDMETHOD_(c,0,"progchg",m_programchange); --- 269,281 ---- FLEXT_CADDMETHOD_(c,0,"print",m_print);
! FLEXT_CADDATTR_VAR(c,"channel",mg_channel,ms_channel); FLEXT_CADDMETHOD_I(c,0,"noteoff",m_noteoff); ! FLEXT_CADDMETHOD_II(c,0,"note",m_note); ! FLEXT_CADDMETHOD_II(c,0,"patouch",m_polyaftertouch); FLEXT_CADDMETHOD_II(c,0,"ctlchg",m_ctrlchange); + FLEXT_CADDMETHOD_(c,0,"atouch",m_aftertouch); + FLEXT_CADDMETHOD_(c,0,"pbend",m_pitchbend); + + FLEXT_CADDATTR_VAR(c,"events",mg_dumpevents,ms_dumpevents);
FLEXT_CADDMETHOD_(c,0,"progchg",m_programchange); *************** *** 271,279 **** FLEXT_CADDMETHOD_(c,0,"getptext",m_ptexts);
- FLEXT_CADDATTR_VAR1(c,"echo",echoparam); FLEXT_CADDATTR_VAR(c,"x",mg_winx,ms_winx); FLEXT_CADDATTR_VAR(c,"y",mg_winy,ms_winy); ! FLEXT_CADDATTR_VAR(c,"caption",mg_wincaption,ms_wincaption); FLEXT_CADDATTR_VAR(c,"title",mg_wintitle,ms_wintitle);
FLEXT_CADDATTR_GET(c,"ins",mg_chnsin); --- 292,303 ---- FLEXT_CADDMETHOD_(c,0,"getptext",m_ptexts);
FLEXT_CADDATTR_VAR(c,"x",mg_winx,ms_winx); FLEXT_CADDATTR_VAR(c,"y",mg_winy,ms_winy); ! FLEXT_CADDATTR_VAR(c,"w",mg_winw,ms_winw); ! FLEXT_CADDATTR_VAR(c,"h",mg_winh,ms_winh); FLEXT_CADDATTR_VAR(c,"title",mg_wintitle,ms_wintitle); + FLEXT_CADDATTR_VAR(c,"caption",mg_wincaption,ms_wincaption); + FLEXT_CADDATTR_VAR(c,"handle",mg_winhandle,ms_winhandle); + FLEXT_CADDMETHOD_(c,0,"front",m_winfront);
FLEXT_CADDATTR_GET(c,"ins",mg_chnsin); *************** *** 319,323 **** blsz(0), vstfun(NULL),vstin(NULL),vstout(NULL),tmpin(NULL),tmpout(NULL), ! echoparam(false),bypass(false),mute(false),paramnames(0) { #if FLEXT_OS == FLEXT_OS_WIN --- 343,347 ---- blsz(0), vstfun(NULL),vstin(NULL),vstout(NULL),tmpin(NULL),tmpout(NULL), ! bypass(false),mute(false),paramnames(0) { #if FLEXT_OS == FLEXT_OS_WIN *************** *** 347,353 **** { if(plug) { - plug->Edit(false); ClearBuf(); // needs valid plug ! delete plug; plug = NULL; } } --- 371,377 ---- { if(plug) { ClearBuf(); // needs valid plug ! VSTPlugin::Delete(plug); ! plug = NULL; } } *************** *** 441,453 **** }
! bool vst::LoadPlug() { if(plug) ClearPlug();
! plug = new VSTPlugin(this);
// try loading the dll from the raw filename ! bool ok = plug->Instance(plugname.c_str(),subplug.c_str()); if(ok) FLEXT_LOG("raw filename loaded fine"); --- 465,479 ---- }
! // \todo this should be in the background, because it can take some time ! // ideally vst would get a response from VSTPlugin when readily, loaded and ! // vst would dump out a respective signal to the patcher bool vst::LoadPlug() { if(plug) ClearPlug();
! VSTPlugin *p = VSTPlugin::New(this);
// try loading the dll from the raw filename ! bool ok = p->Instance(plugname.c_str(),subplug.c_str()); if(ok) FLEXT_LOG("raw filename loaded fine"); *************** *** 469,473 **** dllname += name;
! ok = plug->Instance(dllname.c_str()); } #endif --- 495,499 ---- dllname += name;
! ok = p->Instance(dllname.c_str()); } #endif *************** *** 498,502 **** FLEXT_LOG1("trying %s",(const char *)realpath.c_str());
! ok = plug->Instance(realpath.c_str()); if(ok) { FLEXT_LOG("plugin loaded via VST_PATH"); --- 524,528 ---- FLEXT_LOG1("trying %s",(const char *)realpath.c_str());
! ok = p->Instance(realpath.c_str()); if(ok) { FLEXT_LOG("plugin loaded via VST_PATH"); *************** *** 506,510 ****
tok = strtok( NULL , ";" ); ! if(!tok) post("%s - couldn't find plugin",thisName()); }
--- 532,536 ----
tok = strtok( NULL , ";" ); ! // if(!tok) post("%s - couldn't find plugin",thisName()); }
*************** *** 515,522 **** if(!ok) { post("%s - unable to load plugin '%s'",thisName(),plugname.c_str()); ! ClearPlug(); } ! else InitPlug();
return ok; --- 541,550 ---- if(!ok) { post("%s - unable to load plugin '%s'",thisName(),plugname.c_str()); ! VSTPlugin::Delete(p); } ! else { ! plug = p; InitPlug(); + }
return ok; *************** *** 675,704 **** }
- - #if 0 - - void vst::m_control(const t_symbol *ctrl_name,int ctrl_value) - { - if(!plug) return; - - int parm_num = 0; - - if (!*GetString(ctrl_name) || !strlen(GetString(ctrl_name))) { - error ("plugin~: control messages must have a name and a value"); - return; - } - //parm_num = vst_tilde_get_parm_number (x, ctrl_name->s_name); - //if (parm_num) - //{ - //vst_tilde_set_control_input_by_index (x, parm_num - 1, ctrl_value); - //} - //else - //{ - //vst_tilde_set_control_input_by_name (x, ctrl_name->s_name, ctrl_value); - //} - } - - #endif - void vst::mg_progname(int argc,const t_atom *argv) const { --- 703,706 ---- *************** *** 789,794 ****
if ( header ) { ! post("VST~ plugin: %s " , plug->GetName() ); ! post("made by: %s " , plug->GetVendorName() ); post("parameters %d\naudio: %d in(s)/%d out(s) \nLoaded from library "%s".\n", plug->GetNumParams(), --- 791,796 ----
if ( header ) { ! post("VST~ plugin: %s ", plug->GetName() ); ! post("made by: %s ", plug->GetVendorName() ); post("parameters %d\naudio: %d in(s)/%d out(s) \nLoaded from library "%s".\n", plug->GetNumParams(), *************** *** 869,878 **** if(!plug || pnum < 0 || pnum >= plug->GetNumParams()) return;
! float xval = plug->GetParamValue( pnum ); // if(xval <= 1.0f) // What's that???? if(true) { plug->SetParamFloat( pnum, val ); ! if(echoparam) display_parameter(pnum , true ); } else --- 871,880 ---- if(!plug || pnum < 0 || pnum >= plug->GetNumParams()) return;
! // float xval = plug->GetParamValue( pnum ); // if(xval <= 1.0f) // What's that???? if(true) { plug->SetParamFloat( pnum, val ); ! // if(echoparam) display_parameter(pnum , true ); } else
Index: editor.h =================================================================== RCS file: /cvsroot/pure-data/externals/grill/vst/src/editor.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** editor.h 20 Dec 2004 05:11:55 -0000 1.2 --- editor.h 16 Mar 2005 04:59:35 -0000 1.3 *************** *** 3,7 **** based on the work of Jarno Seppänen and Mark Williamson
! Copyright (c)2003-2004 Thomas Grill (xovo@gmx.net) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution. --- 3,7 ---- based on the work of Jarno Seppänen and Mark Williamson
! Copyright (c)2003-2005 Thomas Grill (gr@grrrr.org) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution. *************** *** 21,25 **** void TitleEditor(VSTPlugin *p,const char *t); void CaptionEditor(VSTPlugin *p,bool c); ! bool IsEditorShown(const VSTPlugin *p);
#endif // __EDITOR_H --- 21,26 ---- void TitleEditor(VSTPlugin *p,const char *t); void CaptionEditor(VSTPlugin *p,bool c); ! void HandleEditor(VSTPlugin *p,bool h); ! void FrontEditor(VSTPlugin *p);
#endif // __EDITOR_H