13895766dSshatty // **************************************************************************** 23895766dSshatty // 33895766dSshatty // CMidiInQ.h 43895766dSshatty // 53895766dSshatty // This class manages MIDI input. 63895766dSshatty // 73895766dSshatty // Use a simple fixed size queue for storing MIDI data. 83895766dSshatty // 93895766dSshatty // Fill & drain pointers are maintained automatically whenever 103895766dSshatty // an Add or Get function succeeds. 113895766dSshatty // 123895766dSshatty // Set editor tabs to 3 for your viewing pleasure. 133895766dSshatty // 143895766dSshatty // ---------------------------------------------------------------------------- 153895766dSshatty // 16*626bc4beSJérôme Duval // This file is part of Echo Digital Audio's generic driver library. 17*626bc4beSJérôme Duval // Copyright Echo Digital Audio Corporation (c) 1998 - 2005 183895766dSshatty // All rights reserved 193895766dSshatty // www.echoaudio.com 203895766dSshatty // 21*626bc4beSJérôme Duval // This library is free software; you can redistribute it and/or 22*626bc4beSJérôme Duval // modify it under the terms of the GNU Lesser General Public 23*626bc4beSJérôme Duval // License as published by the Free Software Foundation; either 24*626bc4beSJérôme Duval // version 2.1 of the License, or (at your option) any later version. 253895766dSshatty // 26*626bc4beSJérôme Duval // This library is distributed in the hope that it will be useful, 27c2ddc71cSJérôme Duval // but WITHOUT ANY WARRANTY; without even the implied warranty of 28*626bc4beSJérôme Duval // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29*626bc4beSJérôme Duval // Lesser General Public License for more details. 303895766dSshatty // 31*626bc4beSJérôme Duval // You should have received a copy of the GNU Lesser General Public 32*626bc4beSJérôme Duval // License along with this library; if not, write to the Free Software 33*626bc4beSJérôme Duval // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 343895766dSshatty // 353895766dSshatty // **************************************************************************** 363895766dSshatty 373895766dSshatty // Prevent problems with multiple includes 383895766dSshatty #ifndef _MIDIQUEUEOBJECT_ 393895766dSshatty #define _MIDIQUEUEOBJECT_ 403895766dSshatty 41c2ddc71cSJérôme Duval #include "CMtcSync.h" 42c2ddc71cSJérôme Duval 43c2ddc71cSJérôme Duval typedef struct tMIDI_DATA 44c2ddc71cSJérôme Duval { 45c2ddc71cSJérôme Duval DWORD dwMidi; 46c2ddc71cSJérôme Duval LONGLONG llTimestamp; 47c2ddc71cSJérôme Duval } 48c2ddc71cSJérôme Duval MIDI_DATA; 49c2ddc71cSJérôme Duval 503895766dSshatty typedef MIDI_DATA *PMIDI_DATA; 513895766dSshatty 523895766dSshatty // 53c2ddc71cSJérôme Duval // Default to one MIDI input client 54c2ddc71cSJérôme Duval // 55c2ddc71cSJérôme Duval #ifndef MAX_MIDI_IN_CLIENTS 56c2ddc71cSJérôme Duval #define MAX_MIDI_IN_CLIENTS 1 57c2ddc71cSJérôme Duval #endif 58c2ddc71cSJérôme Duval 59c2ddc71cSJérôme Duval // 60c2ddc71cSJérôme Duval // MIDI in queue size 61c2ddc71cSJérôme Duval // 62c2ddc71cSJérôme Duval // Total buffer size in bytes will be MIDI_IN_Q_SIZE * sizeof(MIDI_DATA) 63c2ddc71cSJérôme Duval // 64c2ddc71cSJérôme Duval // Buffer size must be a power of 2. This is the default size; to change it, 65c2ddc71cSJérôme Duval // add #define MIDI_IN_Q_SIZE to your OsSupport??.h file 66c2ddc71cSJérôme Duval // 67c2ddc71cSJérôme Duval #ifndef MIDI_IN_Q_SIZE 68c2ddc71cSJérôme Duval #define MIDI_IN_Q_SIZE 128 69c2ddc71cSJérôme Duval #endif 70c2ddc71cSJérôme Duval 71c2ddc71cSJérôme Duval // 723895766dSshatty // Class used for simple MIDI byte queue 733895766dSshatty // 743895766dSshatty class CMidiInQ 753895766dSshatty { 763895766dSshatty public: 773895766dSshatty // 783895766dSshatty // Construction/destruction 793895766dSshatty // 803895766dSshatty CMidiInQ(); 813895766dSshatty ~CMidiInQ(); 823895766dSshatty 833895766dSshatty // 843895766dSshatty // Init 853895766dSshatty // 863895766dSshatty ECHOSTATUS Init(CEchoGals *pEG); 873895766dSshatty 883895766dSshatty // 893895766dSshatty // Get the oldest byte from the circular buffer 903895766dSshatty // 913895766dSshatty ECHOSTATUS GetMidi 923895766dSshatty ( 93c2ddc71cSJérôme Duval ECHOGALS_MIDI_IN_CONTEXT *pContext, 94c2ddc71cSJérôme Duval DWORD &dwMidiByte, 95c2ddc71cSJérôme Duval LONGLONG &llTimestamp 963895766dSshatty ); 973895766dSshatty 983895766dSshatty // 99c2ddc71cSJérôme Duval // Enable and disable MIDI input and MTC sync 1003895766dSshatty // 101c2ddc71cSJérôme Duval ECHOSTATUS Arm(ECHOGALS_MIDI_IN_CONTEXT *pContext); 102c2ddc71cSJérôme Duval ECHOSTATUS Disarm(ECHOGALS_MIDI_IN_CONTEXT *pContext); 103c2ddc71cSJérôme Duval ECHOSTATUS ArmMtcSync(); 104c2ddc71cSJérôme Duval ECHOSTATUS DisarmMtcSync(); 105c2ddc71cSJérôme Duval 106c2ddc71cSJérôme Duval // 107c2ddc71cSJérôme Duval // Get and set MTC base rate 108c2ddc71cSJérôme Duval // 109c2ddc71cSJérôme Duval ECHOSTATUS GetMtcBaseRate(DWORD *pdwBaseRate); 110c2ddc71cSJérôme Duval ECHOSTATUS SetMtcBaseRate(DWORD dwBaseRate); 111c2ddc71cSJérôme Duval 112c2ddc71cSJérôme Duval // 113c2ddc71cSJérôme Duval // If MTC sync is turned on, process received MTC data 114c2ddc71cSJérôme Duval // and update the sample rate 115c2ddc71cSJérôme Duval // 116c2ddc71cSJérôme Duval void ServiceMtcSync(); 1173895766dSshatty 1183895766dSshatty // 1193895766dSshatty // See if there has been any recent MIDI input activity 1203895766dSshatty // 1213895766dSshatty BOOL IsActive(); 1223895766dSshatty 1233895766dSshatty // 1243895766dSshatty // Reset the in/out ptrs 1253895766dSshatty // 126c2ddc71cSJérôme Duval void Reset(ECHOGALS_MIDI_IN_CONTEXT *pContext); 1273895766dSshatty 1283895766dSshatty // 1293895766dSshatty // Service a MIDI input interrupt 1303895766dSshatty // 1313895766dSshatty ECHOSTATUS ServiceIrq(); 1323895766dSshatty 1333895766dSshatty 1343895766dSshatty protected: 1353895766dSshatty 1363895766dSshatty // 1373895766dSshatty // Add a MIDI byte to the circular buffer 1383895766dSshatty // 1393895766dSshatty inline ECHOSTATUS AddMidi 1403895766dSshatty ( 141c2ddc71cSJérôme Duval DWORD dwMidiByte, 142c2ddc71cSJérôme Duval LONGLONG llTimestamp 1433895766dSshatty ); 1443895766dSshatty 1453895766dSshatty // 1463895766dSshatty // Parse MIDI time code data 1473895766dSshatty // 1483895766dSshatty DWORD MtcProcessData( DWORD dwMidiData ); 1493895766dSshatty 1503895766dSshatty // 1513895766dSshatty // Cleanup 1523895766dSshatty // 1533895766dSshatty void Cleanup(); 1543895766dSshatty 1553895766dSshatty // 1563895766dSshatty // Midi buffer management 1573895766dSshatty // 1583895766dSshatty PMIDI_DATA m_pBuffer; 159c2ddc71cSJérôme Duval DWORD m_dwFill; 160c2ddc71cSJérôme Duval DWORD m_dwBufferSizeMask; 161c2ddc71cSJérôme Duval DWORD m_dwNumClients; 1623895766dSshatty 1633895766dSshatty // 1643895766dSshatty // Most recent MIDI input time - used for activity detector 1653895766dSshatty // 1663895766dSshatty ULONGLONG m_ullLastActivityTime; 1673895766dSshatty 1683895766dSshatty // 1693895766dSshatty // MIDI time code 1703895766dSshatty // 1713895766dSshatty WORD m_wMtcState; 172c2ddc71cSJérôme Duval CMtcSync *m_pMtcSync; 1733895766dSshatty 1743895766dSshatty // 1753895766dSshatty // Other objects 1763895766dSshatty // 1773895766dSshatty CEchoGals *m_pEG; 1783895766dSshatty 1793895766dSshatty }; // class CMidiInQ 1803895766dSshatty 1813895766dSshatty typedef CMidiInQ * PCMidiInQ; 1823895766dSshatty 1833895766dSshatty #endif 1843895766dSshatty 1853895766dSshatty // *** CMidiInQ.H *** 186