~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to arts/midi/midimanager_impl.cc

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
    /*
 
2
 
 
3
    Copyright (C) 2000 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 "midimanager_impl.h"
 
24
#include "midiclient_impl.h"
 
25
#include "debug.h"
 
26
 
 
27
using namespace Arts;
 
28
using namespace std;
 
29
 
 
30
static int cleanReference(const string& reference)
 
31
{
 
32
        Object test = Reference("global:"+reference);
 
33
        if(test.isNull())
 
34
        {
 
35
                Dispatcher::the()->globalComm().erase(reference);
 
36
                return 1;
 
37
        }
 
38
        else
 
39
                return 0;
 
40
}
 
41
 
 
42
MidiManager_impl::MidiManager_impl() : nextID(1)
 
43
{
 
44
        cleanReference("Arts_MidiManager");
 
45
        if(!ObjectManager::the()->addGlobalReference(Object::_from_base(_copy()),
 
46
                                        "Arts_MidiManager"))
 
47
        {
 
48
                arts_warning("can't register Arts::MidiManager");
 
49
        }
 
50
        else
 
51
        {
 
52
                arts_debug("Arts::MidiManager registered successfully.");
 
53
        }
 
54
}
 
55
 
 
56
vector<MidiClientInfo> *MidiManager_impl::clients()
 
57
{
 
58
        vector<MidiClientInfo> *result = new vector<MidiClientInfo>;
 
59
 
 
60
        list<MidiClient_impl *>::iterator i;
 
61
        for(i = _clients.begin(); i != _clients.end(); i++)
 
62
                result->push_back((*i)->info());
 
63
 
 
64
        return result;
 
65
}
 
66
 
 
67
MidiClient MidiManager_impl::addClient(MidiClientDirection direction,
 
68
                MidiClientType type, const string& title, const string& autoRestoreID)
 
69
{
 
70
        MidiClientInfo info;
 
71
 
 
72
        info.ID = nextID++;
 
73
        info.direction = direction;
 
74
        info.type = type;
 
75
        info.title = title;
 
76
        info.autoRestoreID = autoRestoreID;
 
77
 
 
78
        MidiClient_impl *impl = new MidiClient_impl(info, this);
 
79
        _clients.push_back(impl);
 
80
        return MidiClient::_from_base(impl);
 
81
}
 
82
 
 
83
void MidiManager_impl::removeClient(MidiClient_impl *client)
 
84
{
 
85
        _clients.remove(client);
 
86
}
 
87
 
 
88
MidiClient_impl *MidiManager_impl::findClient(long clientID)
 
89
{
 
90
        list<MidiClient_impl *>::iterator i;
 
91
 
 
92
        for(i = _clients.begin(); i != _clients.end(); i++)
 
93
        {
 
94
                if((*i)->ID() == clientID)
 
95
                        return (*i);
 
96
        }
 
97
        return 0;
 
98
}
 
99
 
 
100
 
 
101
void MidiManager_impl::connect(long clientID, long destinationID)
 
102
{
 
103
        MidiClient_impl *src = findClient(clientID);
 
104
        MidiClient_impl *dest = findClient(destinationID);
 
105
 
 
106
        arts_return_if_fail(src);
 
107
        arts_return_if_fail(dest);
 
108
        src->connect(dest);
 
109
}
 
110
 
 
111
void MidiManager_impl::disconnect(long clientID, long destinationID)
 
112
{
 
113
        MidiClient_impl *src = findClient(clientID);
 
114
        MidiClient_impl *dest = findClient(destinationID);
 
115
 
 
116
        arts_return_if_fail(src);
 
117
        arts_return_if_fail(dest);
 
118
        src->disconnect(dest);
 
119
}
 
120
 
 
121
namespace Arts { REGISTER_IMPLEMENTATION(MidiManager_impl); }