~ubuntu-branches/ubuntu/breezy/kdemultimedia/breezy

« back to all changes in this revision

Viewing changes to arts/midi/audiotimer.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-03-24 04:48:58 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050324044858-8ff88o9jxej6ii3d
Tags: 4:3.4.0-0ubuntu3
Add kubuntu_02_hide_arts_menu_entries.diff to hide artsbuilder and artscontrol k-menu entries

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
    /*
 
2
 
 
3
    Copyright (C) 2001-2002 Stefan Westerfeld
 
4
                            stefan@space.twc.de
 
5
 
 
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.
 
10
  
 
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.
 
15
   
 
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.
 
20
 
 
21
    */
 
22
 
 
23
#include "artsmidi.h"
 
24
#include "artsflow.h"
 
25
#include "stdsynthmodule.h"
 
26
#include "debug.h"
 
27
#include "miditimercommon.h"
 
28
#include "audiotimer.h"
 
29
#include "flowsystem.h"
 
30
 
 
31
using namespace std;
 
32
using namespace Arts;
 
33
 
 
34
static AudioTimer *AudioTimer_the = 0;
 
35
 
 
36
AudioTimer::AudioTimer()
 
37
{
 
38
        AudioTimer_the = this;
 
39
        samples = seconds = 0;
 
40
}
 
41
 
 
42
AudioTimer::~AudioTimer()
 
43
{
 
44
        AudioTimer_the = 0;
 
45
}
 
46
 
 
47
TimeStamp AudioTimer::time()
 
48
{
 
49
        return TimeStamp(seconds,
 
50
                                (long)((float)samples / samplingRateFloat * 1000000.0));
 
51
}
 
52
 
 
53
void AudioTimer::notify(const Notification &)
 
54
{
 
55
        list<AudioTimerCallback *>::iterator i;
 
56
        for(i = callbacks.begin(); i != callbacks.end(); i++)
 
57
                (*i)->updateTime();
 
58
}
 
59
 
 
60
void AudioTimer::calculateBlock(unsigned long s)
 
61
{
 
62
        samples += s;
 
63
        while(samples > samplingRate)
 
64
        {
 
65
                samples -= samplingRate;
 
66
                seconds++;
 
67
        }
 
68
        Notification n;
 
69
        n.receiver = this;
 
70
        n.ID = 0;
 
71
        n.data = 0;
 
72
        n.internal = 0;
 
73
        NotificationManager::the()->send(n);
 
74
}
 
75
 
 
76
AudioTimer *AudioTimer::subscribe()
 
77
{
 
78
        if(!AudioTimer_the)
 
79
        {
 
80
                new AudioTimer();
 
81
                AudioTimer_the->_node()->start();
 
82
        }
 
83
        else
 
84
        {
 
85
                AudioTimer_the->_copy();
 
86
        }
 
87
        return AudioTimer_the;
 
88
}
 
89
 
 
90
void AudioTimer::addCallback(AudioTimerCallback *callback)
 
91
{
 
92
        callbacks.push_back(callback);
 
93
}
 
94
 
 
95
void AudioTimer::removeCallback(AudioTimerCallback *callback)
 
96
{
 
97
        callbacks.remove(callback);
 
98
}