From 1bb7720c5b187fd69d79ed437e52aed592ea94e1 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Wed, 25 Aug 2004 02:42:06 +0000 Subject: "" svn path=/trunk/; revision=1976 --- externals/grill/vst/src/Editor.h | 2 + externals/grill/vst/src/EditorWin.cpp | 122 ++++++++++++++++++++++++++-------- externals/grill/vst/src/VstHost.cpp | 61 ++++++++++++++--- externals/grill/vst/src/VstHost.h | 8 ++- externals/grill/vst/src/main.cpp | 14 +++- 5 files changed, 167 insertions(+), 40 deletions(-) (limited to 'externals/grill/vst/src') diff --git a/externals/grill/vst/src/Editor.h b/externals/grill/vst/src/Editor.h index e3f9a3d6..ad03f59c 100644 --- a/externals/grill/vst/src/Editor.h +++ b/externals/grill/vst/src/Editor.h @@ -18,6 +18,8 @@ void StopEditor(VSTPlugin *p); void ShowEditor(VSTPlugin *p,bool show); void MoveEditor(VSTPlugin *p,int x,int y); void SizeEditor(VSTPlugin *p,int x,int y); +void TitleEditor(VSTPlugin *p,const char *t); +void CaptionEditor(VSTPlugin *p,bool c); bool IsEditorShown(const VSTPlugin *p); #endif // __EDITOR_H diff --git a/externals/grill/vst/src/EditorWin.cpp b/externals/grill/vst/src/EditorWin.cpp index 9a79c391..82ab55ba 100644 --- a/externals/grill/vst/src/EditorWin.cpp +++ b/externals/grill/vst/src/EditorWin.cpp @@ -35,18 +35,24 @@ static LRESULT CALLBACK wndproc(HWND hwnd,UINT msg,WPARAM wp,LPARAM lp) LRESULT res = 0; -// post("Message %x",msg); switch(msg) { -// case WM_NCREATE: res = TRUE; break; case WM_CREATE: // Initialize the window. plug->StartEditing(hwnd); break; case WM_CLOSE: - plug->StopEditing(); +#ifdef FLEXT_DEBUG + flext::post("WM_CLOSE"); +#endif + // plug could already have been unloaded... + plug->StopEditing(); // this sets plug->hwnd = NULL DestroyWindow(hwnd); break; case WM_DESTROY: +#ifdef FLEXT_DEBUG + flext::post("WM_DESTROY"); +#endif + // stop editor thread PostQuitMessage(0); break; case WM_TIMER: @@ -56,8 +62,16 @@ static LRESULT CALLBACK wndproc(HWND hwnd,UINT msg,WPARAM wp,LPARAM lp) plug->EditorIdle(); break; case WM_MOVE: { - WORD x = LOWORD(lp),y = HIWORD(lp); - plug->SetPos(reinterpret_cast(x),reinterpret_cast(y),false); + // ignore after WM_CLOSE so that x,y positions are preserved + if(!plug->IsEdited()) break; + + WORD wx = LOWORD(lp),wy = HIWORD(lp); + short x = reinterpret_cast(wx),y = reinterpret_cast(wy); + // x and y are the coordinates of the client rect (= actual VST interface) + plug->SetPos(x,y,false); +#ifdef FLEXT_DEBUG + flext::post("WM_MOVE x/y=%i/%i",x,y); +#endif break; } /* @@ -69,17 +83,40 @@ static LRESULT CALLBACK wndproc(HWND hwnd,UINT msg,WPARAM wp,LPARAM lp) break; } */ -/* - case WM_SIZE: - // Set the size and position of the window. +#if 0 //def FLEXT_DEBUG + case WM_SIZE: { + WORD wx = LOWORD(lp),wy = HIWORD(lp); + short x = reinterpret_cast(wx),y = reinterpret_cast(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: res = DefWindowProc(hwnd,msg,wp,lp); } return res; } +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 + ); + +} + static void threadfun(flext::thr_params *p) { flext::RelPriority(-2); @@ -98,7 +135,7 @@ static void threadfun(flext::thr_params *p) HWND wnd = CreateWindow( WCLNAME,tmp, - WS_BORDER|WS_CAPTION|/*WS_THICKFRAME|*/WS_POPUP|WS_SYSMENU|WS_MINIMIZEBOX, + (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 @@ -121,24 +158,13 @@ static void threadfun(flext::thr_params *p) SetTimer(wnd,0,TIMER_INTERVAL,NULL); - WINDOWINFO winfo; - winfo.cbSize = sizeof(winfo); - GetWindowInfo(wnd,&winfo); - TITLEBARINFO tinfo; - tinfo.cbSize = sizeof(tinfo); - GetTitleBarInfo(wnd,&tinfo); - ERect r; plug->GetEditorRect(r); - SetWindowPos(wnd,HWND_TOP, - r.left, - r.top, - (r.right-r.left)+winfo.cxWindowBorders*2, - (r.bottom-r.top)+(tinfo.rcTitleBar.bottom-tinfo.rcTitleBar.top)+winfo.cyWindowBorders*2, - SWP_SHOWWINDOW - ); - - + windowsize(wnd,plug->GetX(),plug->GetY(),r.right-r.left,r.bottom-r.top,plug->GetCaption(),SWP_SHOWWINDOW); +#ifdef FLEXT_DEBUG + flext::post("Editor rect left/top=%i/%i, right/bottom=%i/%i",r.left,r.top,r.right,r.bottom); +#endif + // SetFocus(); // Message pump @@ -186,13 +212,25 @@ void SetupEditor() void StartEditor(VSTPlugin *p) { +#ifdef FLEXT_DEBUG + flext::post("Start editor 1"); +#endif flext::LaunchThread(threadfun,reinterpret_cast(p)); +#ifdef FLEXT_DEBUG + flext::post("Start editor 2"); +#endif } void StopEditor(VSTPlugin *p) { +#ifdef FLEXT_DEBUG + flext::post("Stop editor 1"); +#endif PostMessage(p->EditorHandle(),WM_CLOSE,0,0); flext::StopThread(threadfun,reinterpret_cast(p)); +#ifdef FLEXT_DEBUG + flext::post("Stop editor 2"); +#endif } void ShowEditor(VSTPlugin *p,bool show) @@ -202,8 +240,17 @@ void ShowEditor(VSTPlugin *p,bool show) void MoveEditor(VSTPlugin *p,int x,int y) { - // the client region must be taken into account -// SetWindowPos(p->EditorHandle(),NULL,x,y,0,0,SWP_NOSIZE|SWP_NOZORDER); + 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) @@ -211,6 +258,25 @@ void SizeEditor(VSTPlugin *p,int x,int y) SetWindowPos(p->EditorHandle(),NULL,0,0,x,y,SWP_NOMOVE|SWP_NOZORDER); } +void CaptionEditor(VSTPlugin *plug,bool c) +{ + HWND wnd = plug->EditorHandle(); + LONG ns,style = GetWindowLong(wnd,GWL_STYLE); + if(c) ns = style|WS_BORDER|WS_CAPTION; + else ns = style&~(WS_BORDER|WS_CAPTION); + 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) +{ + SetWindowText(p->EditorHandle(),t); +} + bool IsEditorShown(const VSTPlugin *p) { return IsWindowVisible(p->EditorHandle()) != FALSE; diff --git a/externals/grill/vst/src/VstHost.cpp b/externals/grill/vst/src/VstHost.cpp index bd686716..30b8ba36 100644 --- a/externals/grill/vst/src/VstHost.cpp +++ b/externals/grill/vst/src/VstHost.cpp @@ -13,14 +13,12 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include -static VstTimeInfo _timeInfo; - typedef AEffect *(VSTCALLBACK *PVSTMAIN)(audioMasterCallback audioMaster); VSTPlugin::VSTPlugin(): h_dll(NULL),hwnd(NULL),_pEffect(NULL), - posx(0),posy(0), + posx(0),posy(0),caption(true), _midichannel(0),queue_size(0), paramnamecnt(0) {} @@ -32,7 +30,11 @@ VSTPlugin::~VSTPlugin() int VSTPlugin::Instance(const char *dllname) { - h_dll = LoadLibrary(dllname); +#ifdef FLEXT_DEBUG + flext::post("New Plugin 1 - %x",this); +#endif + + h_dll = LoadLibrary(dllname); if(!h_dll) return VSTINSTANCE_ERR_NO_VALID_FILE; @@ -88,11 +90,23 @@ int VSTPlugin::Instance(const char *dllname) strcpy(_sProductName,str1.c_str()); } + if(*_sProductName) { + char tmp[256]; + sprintf(tmp,"vst~ - %s",_sProductName); + title = tmp; + } + else + title = "vst~"; + *_sVendorName = 0; Dispatch( effGetVendorString, 0, 0, &_sVendorName, 0.0f); _sDllName = dllname; +#ifdef FLEXT_DEBUG + flext::post("New Plugin 2 - %x",this); +#endif + return VSTINSTANCE_NO_ERROR; } @@ -131,9 +145,25 @@ void VSTPlugin::Free() // Called also in destruction Dispatch(effMainsChanged, 0, 0); Dispatch(effClose); +#ifdef FLEXT_DEBUG + flext::post("Free Plugin 1 - %x",this); +#endif + _pEffect = NULL; + + // \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 + if(h_dll) { FreeLibrary(h_dll); h_dll = NULL; } - } + +#ifdef FLEXT_DEBUG + flext::post("Free Plugin 2 - %x",this); +#endif + } } void VSTPlugin::DspInit(float samplerate,int blocksize) @@ -246,8 +276,10 @@ void VSTPlugin::StartEditing(WHandle h) void VSTPlugin::StopEditing() { - Dispatch(effEditClose); - hwnd = NULL; + if(Is()) { + Dispatch(effEditClose); + hwnd = NULL; + } } void VSTPlugin::Visible(bool vis) @@ -359,12 +391,25 @@ void VSTPlugin::SetPos(int x,int y,bool upd) } } +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); + } +} void VSTPlugin::processReplacing( float **inputs, float **outputs, long sampleframes ) { _pEffect->processReplacing( _pEffect , inputs , outputs , sampleframes ); - } void VSTPlugin::process( float **inputs, float **outputs, long sampleframes ) diff --git a/externals/grill/vst/src/VstHost.h b/externals/grill/vst/src/VstHost.h index 00b5164f..6fa2008b 100644 --- a/externals/grill/vst/src/VstHost.h +++ b/externals/grill/vst/src/VstHost.h @@ -130,6 +130,10 @@ public: 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(); } protected: @@ -175,7 +179,9 @@ protected: void SendMidi(); char _midichannel; - int posx,posy; + int posx,posy; // Window position + bool caption; // Window border + std::string title; // Window title }; #endif diff --git a/externals/grill/vst/src/main.cpp b/externals/grill/vst/src/main.cpp index 00804e53..fa405686 100644 --- a/externals/grill/vst/src/main.cpp +++ b/externals/grill/vst/src/main.cpp @@ -19,7 +19,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include -#define VST_VERSION "0.1.0pre14" +#define VST_VERSION "0.1.0pre15" class vst: @@ -50,6 +50,10 @@ protected: V mg_winy(I &y) const { y = plug?plug->GetY():0; } V ms_winx(I x) { if(plug) plug->SetX(x); } V ms_winy(I y) { if(plug) plug->SetY(y); } + V ms_wincaption(bool c) { if(plug) plug->SetCaption(c); } + V mg_wincaption(bool &c) const { c = plug && plug->GetCaption(); } + V ms_wintitle(const t_symbol *t) { if(plug) plug->SetTitle(GetString(t)); } + V mg_wintitle(const t_symbol *&t) const { t = plug?MakeSymbol(plug->GetTitle()):sym__; } V mg_chnsin(I &c) const { c = plug?plug->GetNumInputs():0; } V mg_chnsout(I &c) const { c = plug?plug->GetNumOutputs():0; } @@ -143,6 +147,8 @@ private: 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_S(mg_wintitle,ms_wintitle) FLEXT_CALLGET_I(mg_chnsin) FLEXT_CALLGET_I(mg_chnsout) @@ -201,6 +207,8 @@ V vst::Setup(t_classid c) 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); FLEXT_CADDATTR_GET(c,"outs",mg_chnsout); @@ -246,8 +254,8 @@ vst::~vst() V vst::ClearPlug() { if(plug) { - ms_edit(false); - ClearBuf(); + plug->Edit(false); + ClearBuf(); // needs valid plug delete plug; plug = NULL; } } -- cgit v1.2.1