3
Copyright (C) 2001 Stefan Westerfeld
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Library General Public
8
License as published by the Free Software Foundation; either
9
version 2 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Library General Public License for more details.
16
You should have received a copy of the GNU Library General Public License
17
along with this library; see the file COPYING.LIB. If not, write to
18
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
Boston, MA 02111-1307, USA.
25
#include "stdsynthmodule.h"
27
#include "miditimercommon.h"
28
#include "flowsystem.h"
35
class AudioMidiTimerCommon : public MidiTimerCommon,
36
public SynthModule_skel,
38
/* we are a SynthModule to get the timing */
41
AudioMidiTimerCommon();
42
virtual ~AudioMidiTimerCommon();
44
long samples; /* at most samplingRate, overflow goes in seconds */
48
// allocation: share one AudioMidiTimerCommon for everbody who needs one
49
static AudioMidiTimerCommon *subscribe();
58
void notify(const Notification& n);
60
void calculateBlock(unsigned long samples);
65
static AudioMidiTimerCommon *AudioMidiTimerCommon_the = 0;
67
AudioMidiTimerCommon::AudioMidiTimerCommon()
69
AudioMidiTimerCommon_the = this;
70
samples = seconds = 0;
73
AudioMidiTimerCommon::~AudioMidiTimerCommon()
75
AudioMidiTimerCommon_the = 0;
78
TimeStamp AudioMidiTimerCommon::time()
80
return TimeStamp(seconds,
81
(long)((float)samples / samplingRateFloat * 1000000.0));
84
void AudioMidiTimerCommon::notify(const Notification &)
89
void AudioMidiTimerCommon::calculateBlock(unsigned long s)
92
while(samples > samplingRate)
94
samples -= samplingRate;
102
NotificationManager::the()->send(n);
105
AudioMidiTimerCommon *AudioMidiTimerCommon::subscribe()
107
if(!AudioMidiTimerCommon_the)
109
new AudioMidiTimerCommon();
110
AudioMidiTimerCommon_the->_node()->start();
112
AudioMidiTimerCommon_the->refCount++;
113
return AudioMidiTimerCommon_the;
118
class AudioMidiTimer_impl : public AudioMidiTimer_skel {
120
AudioMidiTimerCommon *timer;
122
AudioMidiTimer_impl()
124
timer = AudioMidiTimerCommon::subscribe();
126
~AudioMidiTimer_impl()
128
timer->unsubscribe();
132
return timer->time();
134
void queueEvent(MidiPort port, const MidiEvent& event)
136
timer->queueEvent(port, event);
140
REGISTER_IMPLEMENTATION(AudioMidiTimer_impl);