[r12986]: branches / edit_controllers / rosegarden / src / base / ControlParameter.cpp Maximize Restore History

Download this file

ControlParameter.cpp    166 lines (139 with data), 4.9 kB

  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
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Rosegarden
A sequencer and musical notation editor.
Copyright 2000-2012 the Rosegarden development team.
See the AUTHORS file for more details.
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 <sstream>
#include <cstdio>
#include "ControlParameter.h"
#include "base/MidiTypes.h"
#include "gui/rulers/ControllerEventAdapter.h"
namespace Rosegarden
{
ControlParameter::ControlParameter():
m_name("<unnamed>"),
m_type(Rosegarden::Controller::EventType),
m_description("<none>"),
m_min(0),
m_max(127),
m_default(0),
m_controllerValue(0),
m_colourIndex(0),
m_ipbPosition(-1) // doesn't appear on IPB by default
{
}
ControlParameter::ControlParameter(const std::string &name,
const std::string &type,
const std::string &description,
int min,
int max,
int def,
MidiByte controllerValue,
unsigned int colour,
int ipbPosition):
m_name(name),
m_type(type),
m_description(description),
m_min(min),
m_max(max),
m_default(def),
m_controllerValue(controllerValue),
m_colourIndex(colour),
m_ipbPosition(ipbPosition)
{
}
ControlParameter::ControlParameter(const ControlParameter &control):
XmlExportable(),
m_name(control.getName()),
m_type(control.getType()),
m_description(control.getDescription()),
m_min(control.getMin()),
m_max(control.getMax()),
m_default(control.getDefault()),
m_controllerValue(control.getControllerValue()),
m_colourIndex(control.getColourIndex()),
m_ipbPosition(control.getIPBPosition())
{
}
ControlParameter&
ControlParameter::operator=(const ControlParameter &control)
{
m_name = control.getName();
m_type = control.getType();
m_description = control.getDescription();
m_min = control.getMin();
m_max = control.getMax();
m_default = control.getDefault();
m_controllerValue = control.getControllerValue();
m_colourIndex = control.getColourIndex();
m_ipbPosition = control.getIPBPosition();
return *this;
}
bool ControlParameter::operator==(const ControlParameter &control)
{
return m_type == control.getType() &&
m_controllerValue == control.getControllerValue() &&
m_min == control.getMin() &&
m_max == control.getMax();
}
bool operator<(const ControlParameter &a, const ControlParameter &b)
{
if (a.m_type != b.m_type)
return a.m_type < b.m_type;
else if (a.m_controllerValue != b.m_controllerValue)
return a.m_controllerValue < b.m_controllerValue;
else
return false;
}
std::string
ControlParameter::toXmlString()
{
std::stringstream control;
control << " <control name=\"" << encode(m_name)
<< "\" type=\"" << encode(m_type)
<< "\" description=\"" << encode(m_description)
<< "\" min=\"" << m_min
<< "\" max=\"" << m_max
<< "\" default=\"" << m_default
<< "\" controllervalue=\"" << int(m_controllerValue)
<< "\" colourindex=\"" << m_colourIndex
<< "\" ipbposition=\"" << m_ipbPosition;
control << "\"/>" << std::endl;
return control.str();
}
// Return a new event setting our controller to VALUE at TIME
// @author Tom Breton (Tehom)
Event *
ControlParameter::
newEvent(timeT time, int value) const
{
Event *event = new Event (getType(), time);
ControllerEventAdapter(event).setValue(value);
if (getType() == Controller::EventType) {
event->set<Int>(Controller::NUMBER, m_controllerValue);
}
return event;
}
// This exists to support calling PitchBendSequenceDialog because some
// calls to PitchBendSequenceDialog always pitchbend rather than
// getting a ControlParameter from a ruler or device. This can't be
// just a static member of ControlParameter, in order to prevent the
// "static initialization order fiasco".
const ControlParameter&
ControlParameter::
getPitchBend(void)
{
static const ControlParameter
pitchBend(
"PitchBend", Rosegarden::PitchBend::EventType, "<none>",
0, 16383, 8192, MidiByte(1), 4, -1);
return pitchBend;
}
}