BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / drivers / audio / echo / generic / CEchoGalsMTC.cpp
blobb768caa487f434be12b482d43fe2a908174f05d2
1 // ****************************************************************************
2 //
3 // CEchoGalsMTC.cpp
4 //
5 // CEchoGalsMTC is used to add MIDI time code sync to the base
6 // CEchoGals class. CEchoGalsMTC derives from CEchoGals; CLayla and
7 // CLayla24 derive in turn from CEchoGalsMTC.
8 //
9 // Set editor tabs to 3 for your viewing pleasure.
10 //
11 // ----------------------------------------------------------------------------
13 // This file is part of Echo Digital Audio's generic driver library.
14 // Copyright Echo Digital Audio Corporation (c) 1998 - 2005
15 // All rights reserved
16 // www.echoaudio.com
18 // This library is free software; you can redistribute it and/or
19 // modify it under the terms of the GNU Lesser General Public
20 // License as published by the Free Software Foundation; either
21 // version 2.1 of the License, or (at your option) any later version.
23 // This library is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 // Lesser General Public License for more details.
28 // You should have received a copy of the GNU Lesser General Public
29 // License along with this library; if not, write to the Free Software
30 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 // ****************************************************************************
34 #include "CEchoGalsMTC.h"
37 //****************************************************************************
39 // Constructor and destructor
41 //****************************************************************************
43 CEchoGalsMTC::CEchoGalsMTC( PCOsSupport pOsSupport )
44 : CEchoGals( pOsSupport )
46 ECHO_DEBUGPRINTF( ( "CEchoGalsMTC::CEchoGalsMTC() is born!\n" ) );
48 m_wInputClock = ECHO_CLOCK_INTERNAL;
50 } // CEchoGalsMTC::CEchoGalsMTC()
53 CEchoGalsMTC::~CEchoGalsMTC()
55 ECHO_DEBUGPRINTF( ( "CEchoGalsMTC::~CEchoGalsMTC() is toast!\n" ) );
56 } // CEchoGalsMTC::~CEchoGalsMTC()
61 //****************************************************************************
63 // Input clock
65 //****************************************************************************
67 //============================================================================
69 // Set the input clock
71 // This needs to intercept the input clock value here since MTC sync is
72 // actually implemented in software
74 //============================================================================
76 ECHOSTATUS CEchoGalsMTC::SetInputClock(WORD wClock)
78 ECHOSTATUS Status;
80 Status = ECHOSTATUS_OK;
83 // Check for MTC clock
85 if (ECHO_CLOCK_MTC == wClock)
87 if (ECHO_CLOCK_MTC != m_wInputClock)
90 // Tell the MIDI input object to enable MIDI time code sync
92 Status = m_MidiIn.ArmMtcSync();
94 if (ECHOSTATUS_OK == Status)
97 // Store the current clock as MTC...
98 //
99 m_wInputClock = ECHO_CLOCK_MTC;
102 // but set the real clock to internal.
104 Status = CEchoGals::SetInputClock( ECHO_CLOCK_INTERNAL );
109 else
112 // Pass the clock setting to the base class
114 Status = CEchoGals::SetInputClock( wClock );
115 if (ECHOSTATUS_OK == Status)
117 WORD wOldClock;
118 DWORD dwRate;
121 // Get the base rate for MTC sync
123 m_MidiIn.GetMtcBaseRate( &dwRate );
126 // Make sure MTC sync is off
128 m_MidiIn.DisarmMtcSync();
131 // Store the new clock
133 wOldClock = m_wInputClock;
134 m_wInputClock = wClock;
137 // If the previous clock was MTC, re-set the sample rate
139 if (ECHO_CLOCK_MTC == wOldClock)
140 SetAudioSampleRate( dwRate );
144 return Status;
146 } // SetInputClock
149 //============================================================================
151 // Get the input clock
153 //============================================================================
155 ECHOSTATUS CEchoGalsMTC::GetInputClock(WORD &wClock)
157 wClock = m_wInputClock;
159 return ECHOSTATUS_OK;
163 //****************************************************************************
165 // Sample rate
167 //****************************************************************************
169 //============================================================================
171 // Set the sample rate
173 // Again, the rate needs to be intercepted here.
175 //============================================================================
177 ECHOSTATUS CEchoGalsMTC::SetAudioSampleRate( DWORD dwSampleRate )
179 ECHOSTATUS Status;
182 // Syncing to MTC?
184 if (ECHO_CLOCK_MTC == m_wInputClock)
187 // Test the rate
189 Status = QueryAudioSampleRate( dwSampleRate );
192 // Set the base rate if it's OK
194 if (ECHOSTATUS_OK == Status)
196 m_MidiIn.SetMtcBaseRate( dwSampleRate );
199 else
202 // Call the base class
204 Status = CEchoGals::SetAudioSampleRate( dwSampleRate );
207 return Status;
209 } // SetAudioSampleRate
212 //============================================================================
214 // Get the sample rate
216 //============================================================================
218 ECHOSTATUS CEchoGalsMTC::GetAudioSampleRate( PDWORD pdwSampleRate )
220 ECHOSTATUS Status;
222 if (NULL == pdwSampleRate)
223 return ECHOSTATUS_INVALID_PARAM;
226 // Syncing to MTC?
228 if (ECHO_CLOCK_MTC == m_wInputClock)
231 // Get the MTC base rate
233 Status = m_MidiIn.GetMtcBaseRate( pdwSampleRate );
235 else
238 // Call the base class
240 Status = CEchoGals::GetAudioSampleRate( pdwSampleRate );
243 return Status;
245 } // GetAudioSampleRate
250 //****************************************************************************
252 // Call this periodically to change the sample rate based on received MTC
253 // data
255 //****************************************************************************
257 void CEchoGalsMTC::ServiceMtcSync()
259 m_MidiIn.ServiceMtcSync();
263 // *** CEchoGalsMTC.cpp ***