1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
/*
Rosegarden
A sequencer and musical notation editor.
This program is Copyright 2000-2008
Guillaume Laurent <glaurent@telegraph-road.org>,
Chris Cannam <cannam@all-day-breakfast.com>,
Richard Bown <bownie@bownie.com>
The moral right of the authors to claim authorship of this work
has been asserted.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version. See the file
COPYING included with this distribution for more information.
*/
#include "SoftSynthDevice.h"
#include "Instrument.h"
#include "MidiTypes.h"
#include <cstdio>
#include <cstdlib>
#include <sstream>
namespace Rosegarden
{
ControlList
SoftSynthDevice::m_controlList;
SoftSynthDevice::SoftSynthDevice() :
Device(0, "Default Soft Synth Device", Device::SoftSynth)
{
checkControlList();
}
SoftSynthDevice::SoftSynthDevice(DeviceId id, const std::string &name) :
Device(id, name, Device::SoftSynth)
{
checkControlList();
}
SoftSynthDevice::SoftSynthDevice(const SoftSynthDevice &dev) :
Device(dev.getId(), dev.getName(), dev.getType()),
Controllable()
{
// Copy the instruments
//
InstrumentList insList = dev.getAllInstruments();
InstrumentList::iterator iIt = insList.begin();
for (; iIt != insList.end(); iIt++)
m_instruments.push_back(new Instrument(**iIt));
}
SoftSynthDevice::~SoftSynthDevice()
{
}
void
SoftSynthDevice::checkControlList()
{
// Much as MidiDevice::generateDefaultControllers
static std::string controls[][9] = {
{ "Pan", Rosegarden::Controller::EventType, "<none>", "0", "127", "64", "10", "2", "0" },
{ "Chorus", Rosegarden::Controller::EventType, "<none>", "0", "127", "0", "93", "3", "1" },
{ "Volume", Rosegarden::Controller::EventType, "<none>", "0", "127", "0", "7", "1", "2" },
{ "Reverb", Rosegarden::Controller::EventType, "<none>", "0", "127", "0", "91", "3", "3" },
{ "Sustain", Rosegarden::Controller::EventType, "<none>", "0", "127", "0", "64", "4", "-1" },
{ "Expression", Rosegarden::Controller::EventType, "<none>", "0", "127", "100", "11", "2", "-1" },
{ "Modulation", Rosegarden::Controller::EventType, "<none>", "0", "127", "0", "1", "4", "-1" },
{ "PitchBend", Rosegarden::PitchBend::EventType, "<none>", "0", "16383", "8192", "1", "4", "-1" }
};
if (m_controlList.empty()) {
for (unsigned int i = 0; i < sizeof(controls) / sizeof(controls[0]); ++i) {
Rosegarden::ControlParameter con(controls[i][0],
controls[i][1],
controls[i][2],
atoi(controls[i][3].c_str()),
atoi(controls[i][4].c_str()),
atoi(controls[i][5].c_str()),
Rosegarden::MidiByte(atoi(controls[i][6].c_str())),
atoi(controls[i][7].c_str()),
atoi(controls[i][8].c_str()));
m_controlList.push_back(con);
}
}
}
const ControlParameter *
SoftSynthDevice::getControlParameter(int index) const
{
if (index >= 0 && ((unsigned int)index) < m_controlList.size())
return &m_controlList[index];
return 0;
}
const ControlParameter *
SoftSynthDevice::getControlParameter(const std::string &type,
Rosegarden::MidiByte controllerValue) const
{
ControlList::iterator it = m_controlList.begin();
for (; it != m_controlList.end(); ++it)
{
if (it->getType() == type)
{
// Return matched on type for most events
//
if (type != Rosegarden::Controller::EventType)
return &*it;
// Also match controller value for Controller events
//
if (it->getControllerValue() == controllerValue)
return &*it;
}
}
return 0;
}
std::string
SoftSynthDevice::toXmlString()
{
std::stringstream ssiDevice;
InstrumentList::iterator iit;
ssiDevice << " <device id=\"" << m_id
<< "\" name=\"" << m_name
<< "\" type=\"softsynth\">" << std::endl;
for (iit = m_instruments.begin(); iit != m_instruments.end(); ++iit)
ssiDevice << (*iit)->toXmlString();
ssiDevice << " </device>"
#if (__GNUC__ < 3)
<< std::endl << std::ends;
#else
<< std::endl;
#endif
return ssiDevice.str();
}
// Add to instrument list
//
void
SoftSynthDevice::addInstrument(Instrument *instrument)
{
m_instruments.push_back(instrument);
}
}
|