123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- #include "stdafx.h"
- #include "resource.h"
- #include "Vstplug.h"
- #include "VSTEditor.h"
- OPENMPT_NAMESPACE_BEGIN
- #ifdef MPT_WITH_VST
- BEGIN_MESSAGE_MAP(COwnerVstEditor, CAbstractVstEditor)
- ON_WM_ERASEBKGND()
- ON_WM_PAINT()
-
-
- ON_MESSAGE(WM_USER + 4000 + WM_KEYDOWN - WM_KEYFIRST, &COwnerVstEditor::OnPreTranslateKeyDown)
- ON_MESSAGE(WM_USER + 4000 + WM_KEYUP - WM_KEYFIRST, &COwnerVstEditor::OnPreTranslateKeyUp)
- ON_MESSAGE(WM_USER + 4000 + WM_SYSKEYDOWN - WM_KEYFIRST, &COwnerVstEditor::OnPreTranslateSysKeyDown)
- ON_MESSAGE(WM_USER + 4000 + WM_SYSKEYUP - WM_KEYFIRST, &COwnerVstEditor::OnPreTranslateSysKeyUp)
- END_MESSAGE_MAP()
- void COwnerVstEditor::OnPaint()
- {
- CAbstractVstEditor::OnPaint();
- auto &plugin = static_cast<const CVstPlugin &>(m_VstPlugin);
- if(plugin.isBridged)
- {
-
-
-
- CRect rect;
- if(m_plugWindow.GetUpdateRect(&rect, FALSE))
- {
- CWnd *child = m_plugWindow.GetWindow(GW_CHILD | GW_HWNDFIRST);
- if(child)
- child->RedrawWindow(&rect, nullptr, RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_UPDATENOW);
- }
- } else
- {
-
- CRect rect;
- m_plugWindow.GetClientRect(rect);
- if(rect.Width() != m_width || rect.Height() != m_height)
- {
- SetSize(rect.Width(), rect.Height());
- }
- }
- }
- void COwnerVstEditor::UpdateParamDisplays()
- {
- CAbstractVstEditor::UpdateParamDisplays();
-
- static_cast<CVstPlugin &>(m_VstPlugin).Dispatch(Vst::effEditIdle, 0, 0, nullptr, 0.0f);
- }
- bool COwnerVstEditor::OpenEditor(CWnd *parent)
- {
- Create(IDD_PLUGINEDITOR, parent);
-
- m_plugWindow.Create(nullptr, WS_CHILD | WS_VISIBLE, CRect(0, 0, 100, 100), this);
-
- Vst::ERect rect{};
- Vst::ERect *pRect = nullptr;
- CVstPlugin &vstPlug = static_cast<CVstPlugin &>(m_VstPlugin);
- vstPlug.Dispatch(Vst::effEditGetRect, 0, 0, &pRect, 0);
- if(pRect) rect = *pRect;
- vstPlug.Dispatch(Vst::effEditOpen, 0, 0, m_plugWindow.m_hWnd, 0);
- vstPlug.Dispatch(Vst::effEditGetRect, 0, 0, &pRect, 0);
- if(pRect) rect = *pRect;
- if(rect.right > rect.left && rect.bottom > rect.top)
- {
-
- SetSize(rect.Width(), rect.Height());
- }
- vstPlug.Dispatch(Vst::effEditTop, 0,0, nullptr, 0.0f);
- vstPlug.Dispatch(Vst::effEditIdle, 0,0, nullptr, 0.0f);
-
- vstPlug.Dispatch(Vst::effSetEditKnobMode, 0, 2, nullptr, 0.0f);
- return CAbstractVstEditor::OpenEditor(parent);
- }
- void COwnerVstEditor::DoClose()
- {
-
- ShowWindow(SW_HIDE);
- if(m_isMinimized) OnNcLButtonDblClk(HTCAPTION, CPoint(0, 0));
- static_cast<CVstPlugin &>(m_VstPlugin).Dispatch(Vst::effEditClose, 0, 0, nullptr, 0.0f);
- CAbstractVstEditor::DoClose();
- }
- bool COwnerVstEditor::SetSize(int contentWidth, int contentHeight)
- {
- if(contentWidth < 0 || contentHeight < 0 || !m_hWnd)
- {
- return false;
- }
- m_width = contentWidth;
- m_height = contentHeight;
- CRect rcWnd, rcClient;
-
- GetWindowRect(&rcWnd);
- GetClientRect(&rcClient);
-
- WindowSizeAdjuster adjuster(*this);
- const int windowWidth = rcWnd.Width() - rcClient.Width() + contentWidth;
- const int windowHeight = rcWnd.Height() - rcClient.Height() + contentHeight;
- SetWindowPos(NULL, 0, 0,
- windowWidth, windowHeight,
- SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
- m_plugWindow.SetWindowPos(NULL, 0, 0,
- contentWidth, contentHeight,
- SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
- return true;
- }
- #endif
- OPENMPT_NAMESPACE_END
|