Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.08 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "MachinePattern.h"
  4.  
  5. using namespace System;
  6. using namespace System::Windows::Controls;
  7. using namespace System::Windows::Threading;
  8. using namespace System::Windows::Interop;
  9. using namespace System::Runtime::InteropServices;
  10. using namespace Pianoroll::GUI;
  11.  
  12.  
  13. ref class ManagedGUI : public IGUICallbacks
  14. {
  15. public:
  16.     ManagedGUI(NativeData *pnd)
  17.     {
  18.         pnd->TargetMac = NULL;
  19.         this->pnd = pnd;
  20.         Control = gcnew Pianoroll::GUI::Editor(this);
  21.     }
  22.  
  23.     virtual void WriteDC(String ^text)
  24.     {
  25. #ifdef _DEBUG
  26.         const char* str2 = (char*)(void*)Marshal::StringToHGlobalAnsi(text);
  27.         pnd->pCB->WriteLine(str2);
  28.         Marshal::FreeHGlobal((System::IntPtr)(void*)str2);
  29. #endif
  30.     }
  31.  
  32.     virtual int GetPlayPosition()
  33.     {
  34.         return pnd->PlayPos;
  35.     }
  36.  
  37.     virtual bool GetPlayNotesState()
  38.     {
  39.         return pnd->pCB->GetPlayNotesState();
  40.     }
  41.  
  42.  
  43.     virtual void MidiNote(int note, int velocity)
  44.     {
  45.         if (pnd->TargetMac == NULL)
  46.             return;
  47.  
  48.         pnd->pCB->SendMidiNote(pnd->TargetMac, 0, note, velocity);
  49.         (pnd->pMI->*pnd->recordCallback)(note, velocity);
  50.     }
  51.  
  52.     virtual int GetBaseOctave()
  53.     {
  54.         return pnd->pCB->GetBaseOctave();
  55.     }
  56.  
  57.     virtual bool IsMidiNoteImplemented()
  58.     {
  59.         return pnd->pCB->MachineImplementsFunction(pnd->TargetMac, 12, false);
  60.     }
  61.  
  62.     virtual void GetGUINotes()
  63.     {
  64.         vector<NoteToGUI> e;
  65.  
  66.         ::EnterCriticalSection(&pnd->PatternCS);
  67.         e = pnd->notesToGUI;
  68.         pnd->notesToGUI.clear();
  69.         ::LeaveCriticalSection(&pnd->PatternCS);
  70.        
  71.         for (int i = 0; i < (int)e.size(); i++)
  72.             Control->MidiNote(e[i].e.D1, e[i].e.D2, e[i].FromUser);
  73.  
  74.     }
  75.  
  76.     virtual void GetRecordedNotes()
  77.     {
  78.         vector<pair<int, MTEvent>> e;
  79.  
  80.         ::EnterCriticalSection(&pnd->PatternCS);
  81.         e = pnd->recNotesToGUI;
  82.         pnd->recNotesToGUI.clear();
  83.         ::LeaveCriticalSection(&pnd->PatternCS);
  84.        
  85.         for (int i = 0; i < (int)e.size(); i++)
  86.             Control->AddRecordedNote(NoteEvent(e[i].first, e[i].second.Length, e[i].second.D1, e[i].second.D2));
  87.  
  88.     }
  89.  
  90.     virtual int GetStateFlags()
  91.     {
  92.         return pnd->pCB->GetStateFlags();
  93.     }
  94.  
  95.     virtual bool TargetSet() { return pnd->TargetMac != NULL; }
  96.  
  97.     virtual void SetStatusBarText(int pane, String ^text)
  98.     {
  99.         const char *s = (char*)(void*)Marshal::StringToHGlobalAnsi(text);
  100.         pnd->pCB->SetPatternEditorStatusText(pane, s);
  101.         Marshal::FreeHGlobal((System::IntPtr)(void*)s);
  102.     }
  103.  
  104.     virtual void PlayNoteEvents(IEnumerable<NoteEvent> ^notes)
  105.     {
  106.         if (!pnd->pCB->GetPlayNotesState())
  107.             return;
  108.  
  109.         MapIntToMTEvent n;
  110.  
  111.         for each (NoteEvent e in notes)
  112.             n[pair<int, int>(e.Time, e.Note)] = MTEvent(e.Note, e.Velocity, e.Length);
  113.  
  114.         pnd->playingNoteSet->Play(n);
  115.     }
  116.  
  117.     virtual bool IsEditorWindowVisible()
  118.     {
  119.         HWND hwnd = (HWND)HS->Handle.ToPointer();
  120.         HDC hdc = ::GetDC(hwnd);
  121.         RECT r;
  122.         bool visible = ::GetClipBox(hdc, &r) != NULLREGION;
  123.         ::ReleaseDC(hwnd, hdc);
  124.         return visible;
  125.     }
  126.  
  127.     virtual String ^GetThemePath()
  128.     {
  129.         return gcnew String(pnd->pCB->GetThemePath());
  130.     }
  131.  
  132. public:
  133.     void SetEditorPattern(CMachinePattern *p)
  134.     {
  135.         pEditorPattern = p;
  136.         Control->Pattern = p != NULL ? p->MPattern : nullptr;
  137.     }
  138.  
  139.     void SetTargetMachine(CMachine *pmac)
  140.     {
  141.         pnd->TargetMac = pmac;
  142.         Control->TargetMachineChanged();
  143.     }
  144.  
  145.  
  146.  
  147. public:
  148.     HwndSource ^HS;
  149.     Editor ^Control;
  150.     CMachinePattern *pEditorPattern;
  151.     NativeData *pnd;
  152.  
  153.  
  154. };
  155.  
  156.  
  157. class GUI
  158. {
  159. public:
  160.     gcroot<ManagedGUI ^> MGUI;
  161.     HWND Window;
  162.  
  163.     // these wrappers are here to keep Pianoroll.cpp completely unmanaged
  164.  
  165.     void MachineDestructor()
  166.     {
  167.         MGUI->Control->MachineDestructor();
  168.     }
  169.  
  170.     void SetEditorPattern(CMachinePattern *pmp)
  171.     {
  172.         MGUI->SetEditorPattern(pmp);
  173.     }
  174.  
  175.     void SetTargetMachine(CMachine *pmac)
  176.     {
  177.         MGUI->SetTargetMachine(pmac);
  178.     }
  179.  
  180.     void ShowHelp()
  181.     {
  182.         MGUI->Control->ShowHelp();
  183.     }
  184.  
  185.     void SetBaseOctave(int bo)
  186.     {
  187.         MGUI->Control->SetBaseOctave(bo);
  188.     }
  189.  
  190.     int GetEditorPatternPosition()
  191.     {
  192.         return MGUI->Control->GetEditorPatternPosition();
  193.     }
  194.  
  195.     void Update()
  196.     {
  197.         MGUI->Control->Update();
  198.     }
  199.  
  200.     void ThemeChanged()
  201.     {
  202.         MGUI->Control->ThemeChanged();
  203.     }
  204. };
  205.  
  206. extern void CreateGUI(GUI &gui, HWND parent, NativeData *pnd);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement