MuseScore/libmscore/instrument.cpp

1207 lines
36 KiB
C++
Raw Normal View History

2012-05-26 14:26:10 +02:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2008-2011 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#include "instrument_p.h"
#include "xml.h"
#include "drumset.h"
#include "articulation.h"
#include "utils.h"
#include "tablature.h"
#include "instrtemplate.h"
#include "mscore.h"
2012-05-26 14:26:10 +02:00
2013-05-13 18:49:17 +02:00
namespace Ms {
2012-05-26 14:26:10 +02:00
Instrument InstrumentList::defaultInstrument;
//---------------------------------------------------------
// write
//---------------------------------------------------------
void NamedEventList::write(Xml& xml, const QString& n) const
{
xml.stag(QString("%1 name=\"%2\"").arg(n).arg(name));
if (!descr.isEmpty())
xml.tag("descr", descr);
foreach(const MidiCoreEvent& e, events)
2013-04-25 10:52:02 +02:00
e.write(xml);
2012-05-26 14:26:10 +02:00
xml.etag();
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
2013-01-11 18:10:18 +01:00
void NamedEventList::read(XmlReader& e)
2012-05-26 14:26:10 +02:00
{
2013-01-11 18:10:18 +01:00
name = e.attribute("name");
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
2012-05-26 14:26:10 +02:00
if (tag == "program") {
MidiCoreEvent ev(ME_CONTROLLER, 0, CTRL_PROGRAM, e.intAttribute("value", 0));
events.push_back(ev);
2013-01-11 18:10:18 +01:00
e.skipCurrentElement();
2012-05-26 14:26:10 +02:00
}
else if (tag == "controller") {
MidiCoreEvent ev;
ev.setType(ME_CONTROLLER);
2013-04-08 10:31:17 +02:00
ev.setDataA(e.intAttribute("ctrl", 0));
ev.setDataB(e.intAttribute("value", 0));
events.push_back(ev);
2013-01-11 18:10:18 +01:00
e.skipCurrentElement();
2012-05-26 14:26:10 +02:00
}
else if (tag == "descr")
2013-01-11 18:10:18 +01:00
descr = e.readElementText();
2012-05-26 14:26:10 +02:00
else
2013-01-11 18:10:18 +01:00
e.unknown();
2012-05-26 14:26:10 +02:00
}
}
//---------------------------------------------------------
// operator
//---------------------------------------------------------
bool MidiArticulation::operator==(const MidiArticulation& i) const
{
return (i.name == name) && (i.velocity == velocity) && (i.gateTime == gateTime);
}
//---------------------------------------------------------
// Instrument
//---------------------------------------------------------
InstrumentData::InstrumentData()
{
Channel a;
a.name = "normal";
_channel.append(a);
_minPitchA = 0;
_maxPitchA = 127;
_minPitchP = 0;
_maxPitchP = 127;
_useDrumset = false;
_drumset = 0;
_tablature = 0;
}
InstrumentData::InstrumentData(const InstrumentData& i)
: QSharedData(i)
{
_longNames = i._longNames;
_shortNames = i._shortNames;
_trackName = i._trackName;
_minPitchA = i._minPitchA;
_maxPitchA = i._maxPitchA;
_minPitchP = i._minPitchP;
_maxPitchP = i._maxPitchP;
_transpose = i._transpose;
_useDrumset = i._useDrumset;
_drumset = 0;
_tablature = 0;
setDrumset(i._drumset);
setTablature(i._tablature);
_midiActions = i._midiActions;
_articulation = i._articulation;
_channel = i._channel;
}
//---------------------------------------------------------
// ~InstrumentData
//---------------------------------------------------------
InstrumentData::~InstrumentData()
{
delete _tablature;
delete _drumset;
}
//---------------------------------------------------------
// tablature
// If instrument has no tablature, return default
// (guitar) tablature
//---------------------------------------------------------
Tablature* InstrumentData::tablature() const
{
return _tablature ? _tablature : &emptyStringData;
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
2013-06-04 18:29:14 +02:00
// StaffNameDoc::write
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
2013-06-04 18:29:14 +02:00
void StaffNameDoc::write(Xml& xml, const char* tag) const
2012-05-26 14:26:10 +02:00
{
2013-06-04 18:29:14 +02:00
if (!name.isEmpty()) {
xml.stag(QString("%1 pos=\"%2\"").arg(tag).arg(pos));
xml.writeHtml(name.toHtml());
2012-05-26 14:26:10 +02:00
xml.etag();
}
2013-06-04 18:29:14 +02:00
}
//---------------------------------------------------------
// InstrumentData::write
//---------------------------------------------------------
void InstrumentData::write(Xml& xml) const
{
xml.stag("Instrument");
foreach(const StaffNameDoc& doc, _longNames)
doc.write(xml, "longName");
foreach(const StaffNameDoc& doc, _shortNames)
doc.write(xml, "shortName");
2012-05-26 14:26:10 +02:00
xml.tag("trackName", _trackName);
if (_minPitchP > 0)
xml.tag("minPitchP", _minPitchP);
if (_maxPitchP < 127)
xml.tag("maxPitchP", _maxPitchP);
if (_minPitchA > 0)
xml.tag("minPitchA", _minPitchA);
if (_maxPitchA < 127)
xml.tag("maxPitchA", _maxPitchA);
if (_transpose.diatonic)
xml.tag("transposeDiatonic", _transpose.diatonic);
if (_transpose.chromatic)
xml.tag("transposeChromatic", _transpose.chromatic);
if (_useDrumset) {
xml.tag("useDrumset", _useDrumset);
_drumset->save(xml);
}
if (_tablature)
_tablature->write(xml);
foreach(const NamedEventList& a, _midiActions)
a.write(xml, "MidiAction");
foreach(const MidiArticulation& a, _articulation)
a.write(xml);
foreach(const Channel& a, _channel)
a.write(xml);
xml.etag();
}
//---------------------------------------------------------
// InstrumentData::read
//---------------------------------------------------------
2013-01-11 18:10:18 +01:00
void InstrumentData::read(XmlReader& e)
2012-05-26 14:26:10 +02:00
{
int program = -1;
int bank = 0;
int chorus = 30;
int reverb = 30;
int volume = 100;
int pan = 60;
bool customDrumset = false;
_channel.clear();
2013-01-11 18:10:18 +01:00
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
2012-05-26 14:26:10 +02:00
if (tag == "longName") {
2013-01-11 18:10:18 +01:00
int pos = e.intAttribute("pos", 0);
2012-05-26 14:26:10 +02:00
QTextDocumentFragment longName = QTextDocumentFragment::fromHtml(Xml::htmlToString(e));
_longNames.append(StaffNameDoc(longName, pos));
}
else if (tag == "shortName") {
2013-01-11 18:10:18 +01:00
int pos = e.intAttribute("pos", 0);
2012-05-26 14:26:10 +02:00
QTextDocumentFragment shortName = QTextDocumentFragment::fromHtml(Xml::htmlToString(e));
_shortNames.append(StaffNameDoc(shortName, pos));
}
else if (tag == "trackName")
2013-01-11 18:10:18 +01:00
_trackName = e.readElementText();
2012-05-26 14:26:10 +02:00
else if (tag == "minPitch") { // obsolete
2013-01-11 18:10:18 +01:00
_minPitchP = _minPitchA = e.readInt();
2012-05-26 14:26:10 +02:00
}
else if (tag == "maxPitch") { // obsolete
2013-01-11 18:10:18 +01:00
_maxPitchP = _maxPitchA = e.readInt();
2012-05-26 14:26:10 +02:00
}
else if (tag == "minPitchA")
2013-01-11 18:10:18 +01:00
_minPitchA = e.readInt();
2012-05-26 14:26:10 +02:00
else if (tag == "minPitchP")
2013-01-11 18:10:18 +01:00
_minPitchP = e.readInt();
2012-05-26 14:26:10 +02:00
else if (tag == "maxPitchA")
2013-01-11 18:10:18 +01:00
_maxPitchA = e.readInt();
2012-05-26 14:26:10 +02:00
else if (tag == "maxPitchP")
2013-01-11 18:10:18 +01:00
_maxPitchP = e.readInt();
2012-05-26 14:26:10 +02:00
else if (tag == "transposition") { // obsolete
2013-01-11 18:10:18 +01:00
_transpose.chromatic = e.readInt();
_transpose.diatonic = chromatic2diatonic(_transpose.chromatic);
2012-05-26 14:26:10 +02:00
}
else if (tag == "transposeChromatic")
2013-01-11 18:10:18 +01:00
_transpose.chromatic = e.readInt();
2012-05-26 14:26:10 +02:00
else if (tag == "transposeDiatonic")
2013-01-11 18:10:18 +01:00
_transpose.diatonic = e.readInt();
2012-05-26 14:26:10 +02:00
else if (tag == "useDrumset") {
2013-01-11 18:10:18 +01:00
_useDrumset = e.readInt();
2012-05-26 14:26:10 +02:00
if (_useDrumset)
_drumset = new Drumset(*smDrumset);
}
else if (tag == "Drum") {
// if we see on of this tags, a custom drumset will
// be created
if (_drumset == 0)
_drumset = new Drumset(*smDrumset);
if (!customDrumset) {
_drumset->clear();
customDrumset = true;
}
_drumset->load(e);
}
else if (tag == "Tablature") {
_tablature = new Tablature();
_tablature->read(e);
}
else if (tag == "MidiAction") {
NamedEventList a;
a.read(e);
_midiActions.append(a);
}
else if (tag == "Articulation") {
MidiArticulation a;
a.read(e);
_articulation.append(a);
}
else if (tag == "Channel" || tag == "channel") {
Channel a;
a.read(e);
_channel.append(a);
}
else if (tag == "chorus") // obsolete
2013-01-11 18:10:18 +01:00
chorus = e.readInt();
2012-05-26 14:26:10 +02:00
else if (tag == "reverb") // obsolete
2013-01-11 18:10:18 +01:00
reverb = e.readInt();
2012-05-26 14:26:10 +02:00
else if (tag == "midiProgram") // obsolete
2013-01-11 18:10:18 +01:00
program = e.readInt();
2012-05-26 14:26:10 +02:00
else if (tag == "volume") // obsolete
2013-01-11 18:10:18 +01:00
volume = e.readInt();
2012-05-26 14:26:10 +02:00
else if (tag == "pan") // obsolete
2013-01-11 18:10:18 +01:00
pan = e.readInt();
2012-05-26 14:26:10 +02:00
else if (tag == "midiChannel") // obsolete
2013-01-17 20:20:41 +01:00
e.skipCurrentElement();
2012-05-26 14:26:10 +02:00
else
2013-01-11 18:10:18 +01:00
e.unknown();
2012-05-26 14:26:10 +02:00
}
if (_channel.isEmpty()) { // for backward compatibility
Channel a;
a.chorus = chorus;
a.reverb = reverb;
a.name = "normal";
a.program = program;
a.bank = bank;
a.volume = volume;
a.pan = pan;
_channel.append(a);
}
if (_useDrumset) {
if (_channel[0].bank == 0)
_channel[0].bank = 128;
_channel[0].updateInitList();
}
}
//---------------------------------------------------------
// action
//---------------------------------------------------------
NamedEventList* InstrumentData::midiAction(const QString& s, int channelIdx) const
{
// first look in channel list
foreach(const NamedEventList& a, _channel[channelIdx].midiActions) {
if (s == a.name)
return const_cast<NamedEventList*>(&a);
}
foreach(const NamedEventList& a, _midiActions) {
if (s == a.name)
return const_cast<NamedEventList*>(&a);
}
return 0;
}
//---------------------------------------------------------
// Channel
//---------------------------------------------------------
Channel::Channel()
{
for(int i = 0; i < A_INIT_COUNT; ++i)
init.push_back(MidiCoreEvent());
synti = "Fluid"; // default synthesizer
2012-05-26 14:26:10 +02:00
channel = -1;
program = -1;
bank = 0;
volume = 100;
pan = 64;
chorus = 0;
reverb = 0;
2012-05-26 14:26:10 +02:00
mute = false;
solo = false;
soloMute = false;
}
//---------------------------------------------------------
// write
//---------------------------------------------------------
void Channel::write(Xml& xml) const
{
if (name.isEmpty())
xml.stag("Channel");
else
xml.stag(QString("Channel name=\"%1\"").arg(name));
if (!descr.isEmpty())
xml.tag("descr", descr);
updateInitList();
foreach(const MidiCoreEvent& e, init) {
if (e.type() == ME_INVALID)
continue;
if (e.type() == ME_CONTROLLER) {
2013-04-08 10:31:17 +02:00
if (e.dataA() == CTRL_HBANK && e.dataB() == 0)
continue;
2013-04-08 10:31:17 +02:00
if (e.dataA() == CTRL_LBANK && e.dataB() == 0)
continue;
2013-04-08 10:31:17 +02:00
if (e.dataA() == CTRL_VOLUME && e.dataB() == 100)
continue;
2013-04-08 10:31:17 +02:00
if (e.dataA() == CTRL_PANPOT && e.dataB() == 64)
continue;
2013-04-08 10:31:17 +02:00
if (e.dataA() == CTRL_REVERB_SEND && e.dataB() == 0)
continue;
2013-04-08 10:31:17 +02:00
if (e.dataA() == CTRL_CHORUS_SEND && e.dataB() == 0)
continue;
}
2013-04-25 10:52:02 +02:00
e.write(xml);
2012-05-26 14:26:10 +02:00
}
if (!MScore::testMode)
2013-04-04 12:12:10 +02:00
// xml.tag("synti", ::synti->name(synti));
xml.tag("synti", synti);
2012-05-26 14:26:10 +02:00
if (mute)
xml.tag("mute", mute);
if (solo)
xml.tag("solo", solo);
foreach(const NamedEventList& a, midiActions)
a.write(xml, "MidiAction");
foreach(const MidiArticulation& a, articulation)
a.write(xml);
xml.etag();
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
2013-01-11 18:10:18 +01:00
void Channel::read(XmlReader& e)
2012-05-26 14:26:10 +02:00
{
2013-04-04 12:12:10 +02:00
// synti = 0;
2013-01-11 18:10:18 +01:00
name = e.attribute("name");
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
2012-05-26 14:26:10 +02:00
if (tag == "program") {
2013-01-11 18:10:18 +01:00
program = e.intAttribute("value", -1);
2012-05-26 14:26:10 +02:00
if (program == -1)
2013-01-11 18:10:18 +01:00
program = e.readInt();
2013-01-17 20:20:41 +01:00
else
e.readNext();
2012-05-26 14:26:10 +02:00
}
else if (tag == "controller") {
2013-01-11 18:10:18 +01:00
int value = e.intAttribute("value", 0);
int ctrl = e.intAttribute("ctrl", 0);
2012-05-26 14:26:10 +02:00
switch (ctrl) {
case CTRL_HBANK:
bank = (value << 7) + (bank & 0x7f);
break;
case CTRL_LBANK:
bank = (bank & ~0x7f) + (value & 0x7f);
break;
case CTRL_VOLUME:
volume = value;
break;
case CTRL_PANPOT:
pan = value;
break;
case CTRL_CHORUS_SEND:
chorus = value;
break;
case CTRL_REVERB_SEND:
reverb = value;
break;
default:
{
Event e(ME_CONTROLLER);
e.setOntime(-1);
e.setChannel(0);
2013-04-08 10:31:17 +02:00
e.setDataA(ctrl);
e.setDataB(value);
init.push_back(e);
2012-05-26 14:26:10 +02:00
}
break;
}
2013-01-17 20:20:41 +01:00
e.readNext();
2012-05-26 14:26:10 +02:00
}
else if (tag == "Articulation") {
MidiArticulation a;
a.read(e);
articulation.append(a);
}
else if (tag == "MidiAction") {
NamedEventList a;
a.read(e);
midiActions.append(a);
}
else if (tag == "synti")
synti = e.readElementText();
2013-01-11 18:10:18 +01:00
else if (tag == "descr")
descr = e.readElementText();
else if (tag == "mute")
mute = e.readInt();
else if (tag == "solo")
solo = e.readInt();
2012-05-26 14:26:10 +02:00
else
2013-01-11 18:10:18 +01:00
e.unknown();
2012-05-26 14:26:10 +02:00
}
updateInitList();
}
//---------------------------------------------------------
// updateInitList
//---------------------------------------------------------
void Channel::updateInitList() const
{
MidiCoreEvent e;
2012-05-26 14:26:10 +02:00
if (program != -1) {
e.setType(ME_CONTROLLER);
2013-04-08 10:31:17 +02:00
e.setDataA(CTRL_PROGRAM);
e.setDataB(program);
2012-05-26 14:26:10 +02:00
init[A_PROGRAM] = e;
}
2013-04-08 10:31:17 +02:00
e.setData(ME_CONTROLLER, CTRL_HBANK, (bank >> 7) & 0x7f);
2012-05-26 14:26:10 +02:00
init[A_HBANK] = e;
2013-04-08 10:31:17 +02:00
e.setData(ME_CONTROLLER, CTRL_LBANK, bank & 0x7f);
2012-05-26 14:26:10 +02:00
init[A_LBANK] = e;
2013-04-08 10:31:17 +02:00
e.setData(ME_CONTROLLER, CTRL_VOLUME, volume);
2012-05-26 14:26:10 +02:00
init[A_VOLUME] = e;
2013-04-08 10:31:17 +02:00
e.setData(ME_CONTROLLER, CTRL_PANPOT, pan);
2012-05-26 14:26:10 +02:00
init[A_PAN] = e;
2013-04-08 10:31:17 +02:00
e.setData(ME_CONTROLLER, CTRL_CHORUS_SEND, chorus);
2012-05-26 14:26:10 +02:00
init[A_CHORUS] = e;
2013-04-08 10:31:17 +02:00
e.setData(ME_CONTROLLER, CTRL_REVERB_SEND, reverb);
2012-05-26 14:26:10 +02:00
init[A_REVERB] = e;
}
//---------------------------------------------------------
// channelIdx
//---------------------------------------------------------
int InstrumentData::channelIdx(const QString& s) const
{
int idx = 0;
foreach(const Channel& a, _channel) {
if (a.name.isEmpty() && s == "normal")
return idx;
if (s == a.name)
return idx;
++idx;
}
return -1;
}
//---------------------------------------------------------
// write
//---------------------------------------------------------
void MidiArticulation::write(Xml& xml) const
{
if (name.isEmpty())
xml.stag("Articulation");
else
xml.stag(QString("Articulation name=\"%1\"").arg(name));
2012-05-26 14:26:10 +02:00
if (!descr.isEmpty())
xml.tag("descr", descr);
xml.tag("velocity", velocity);
xml.tag("gateTime", gateTime);
xml.etag();
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
2013-01-11 18:10:18 +01:00
void MidiArticulation::read(XmlReader& e)
2012-05-26 14:26:10 +02:00
{
2013-01-11 18:10:18 +01:00
name = e.attribute("name");
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
2012-05-26 14:26:10 +02:00
if (tag == "velocity") {
2013-01-11 18:10:18 +01:00
QString text(e.readElementText());
2012-05-26 14:26:10 +02:00
if (text.endsWith("%"))
text = text.left(text.size()-1);
velocity = text.toInt();
}
else if (tag == "gateTime") {
2013-01-11 18:10:18 +01:00
QString text(e.readElementText());
2012-05-26 14:26:10 +02:00
if (text.endsWith("%"))
text = text.left(text.size()-1);
gateTime = text.toInt();
}
else if (tag == "descr")
2013-01-11 18:10:18 +01:00
descr = e.readElementText();
2012-05-26 14:26:10 +02:00
else
2013-01-11 18:10:18 +01:00
e.unknown();
2012-05-26 14:26:10 +02:00
}
}
//---------------------------------------------------------
// updateVelocity
//---------------------------------------------------------
void InstrumentData::updateVelocity(int* velocity, int /*channelIdx*/, const QString& name)
{
foreach(const MidiArticulation& a, _articulation) {
if (a.name == name) {
*velocity = *velocity * a.velocity / 100;
break;
}
}
}
//---------------------------------------------------------
// updateGateTime
//---------------------------------------------------------
void InstrumentData::updateGateTime(int* gateTime, int /*channelIdx*/, const QString& name)
{
foreach(const MidiArticulation& a, _articulation) {
if (a.name == name) {
2012-11-21 15:57:35 +01:00
*gateTime = a.gateTime;
2012-05-26 14:26:10 +02:00
break;
}
}
}
//---------------------------------------------------------
// operator==
//---------------------------------------------------------
bool InstrumentData::operator==(const InstrumentData& i) const
{
int n = _longNames.size();
if (i._longNames.size() != n)
return false;
for (int k = 0; k < n; ++k) {
if (!(i._longNames[k] == _longNames[k]))
return false;
}
n = _shortNames.size();
if (i._shortNames.size() != n)
return false;
for (int k = 0; k < n; ++k) {
if (!(i._shortNames[k] == _shortNames[k].name))
return false;
}
return i._minPitchA == _minPitchA
&& i._maxPitchA == _maxPitchA
&& i._minPitchP == _minPitchP
&& i._maxPitchP == _maxPitchP
&& i._useDrumset == _useDrumset
2013-04-25 10:52:02 +02:00
&& i._midiActions == _midiActions
2012-05-26 14:26:10 +02:00
&& i._channel == _channel
&& i._articulation == _articulation
&& i._transpose.diatonic == _transpose.diatonic
&& i._transpose.chromatic == _transpose.chromatic
&& i._trackName == _trackName
&& i.tablature() == tablature();
;
}
//---------------------------------------------------------
// operator==
//---------------------------------------------------------
bool StaffNameDoc::operator==(const StaffNameDoc& i) const
{
return (i.pos == pos) && (i.name.toHtml() == name.toHtml());
}
//---------------------------------------------------------
// setUseDrumset
//---------------------------------------------------------
void InstrumentData::setUseDrumset(bool val)
{
_useDrumset = val;
if (val && _drumset == 0) {
_drumset = new Drumset(*smDrumset);
}
}
//---------------------------------------------------------
// setDrumset
//---------------------------------------------------------
void InstrumentData::setDrumset(Drumset* ds)
{
delete _drumset;
if (ds)
_drumset = new Drumset(*ds);
else
_drumset = 0;
}
//---------------------------------------------------------
// setTablature
//---------------------------------------------------------
void InstrumentData::setTablature(Tablature* t)
{
delete _tablature;
if (t)
_tablature = new Tablature(*t);
else
_tablature = 0;
}
//---------------------------------------------------------
// setLongName
//---------------------------------------------------------
void InstrumentData::setLongName(const QTextDocumentFragment& f)
{
_longNames.clear();
_longNames.append(StaffNameDoc(f, 0));
}
//---------------------------------------------------------
// setShortName
//---------------------------------------------------------
void InstrumentData::setShortName(const QTextDocumentFragment& f)
{
_shortNames.clear();
_shortNames.append(StaffNameDoc(f, 0));
}
//---------------------------------------------------------
// addLongName
//---------------------------------------------------------
void InstrumentData::addLongName(const StaffNameDoc& f)
{
_longNames.append(f);
}
//---------------------------------------------------------
// addShortName
//---------------------------------------------------------
void InstrumentData::addShortName(const StaffNameDoc& f)
{
_shortNames.append(f);
}
//---------------------------------------------------------
// Instrument
//---------------------------------------------------------
Instrument::Instrument()
{
d = new InstrumentData;
}
Instrument::Instrument(const Instrument& s)
: d(s.d)
{
}
Instrument::~Instrument()
{
}
//---------------------------------------------------------
// operator=
//---------------------------------------------------------
Instrument& Instrument::operator=(const Instrument& s)
{
d = s.d;
return *this;
}
//---------------------------------------------------------
// operator==
//---------------------------------------------------------
bool Instrument::operator==(const Instrument& s) const
{
return d->operator==(*s.d);
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
2013-01-11 18:10:18 +01:00
void Instrument::read(XmlReader& e)
2012-05-26 14:26:10 +02:00
{
d->read(e);
}
//---------------------------------------------------------
// write
//---------------------------------------------------------
void Instrument::write(Xml& xml) const
{
d->write(xml);
}
//---------------------------------------------------------
// midiAction
//---------------------------------------------------------
NamedEventList* Instrument::midiAction(const QString& s, int channel) const
{
return d->midiAction(s, channel);
}
//---------------------------------------------------------
// channelIdx
//---------------------------------------------------------
int Instrument::channelIdx(const QString& s) const
{
return d->channelIdx(s);
}
//---------------------------------------------------------
// updateVelocity
//---------------------------------------------------------
void Instrument::updateVelocity(int* velocity, int channel, const QString& name)
{
d->updateVelocity(velocity, channel, name);
}
//---------------------------------------------------------
// updateGateTime
//---------------------------------------------------------
void Instrument::updateGateTime(int* gateTime, int channel, const QString& name)
{
d->updateGateTime(gateTime, channel, name);
}
//---------------------------------------------------------
// minPitchP
//---------------------------------------------------------
int Instrument::minPitchP() const
{
return d->_minPitchP;
}
//---------------------------------------------------------
// maxPitchP
//---------------------------------------------------------
int Instrument::maxPitchP() const
{
return d->_maxPitchP;
}
//---------------------------------------------------------
// minPitchA
//---------------------------------------------------------
int Instrument::minPitchA() const
{
return d->_minPitchA;
}
//---------------------------------------------------------
// maxPitchA
//---------------------------------------------------------
int Instrument::maxPitchA() const
{
return d->_maxPitchA;
}
//---------------------------------------------------------
// setMinPitchP
//---------------------------------------------------------
void Instrument::setMinPitchP(int v)
{
d->setMinPitchP(v);
}
//---------------------------------------------------------
// setMaxPitchP
//---------------------------------------------------------
void Instrument::setMaxPitchP(int v)
{
d->setMaxPitchP(v);
}
//---------------------------------------------------------
// setMinPitchA
//---------------------------------------------------------
void Instrument::setMinPitchA(int v)
{
d->setMinPitchA(v);
}
//---------------------------------------------------------
// setMaxPitchA
//---------------------------------------------------------
void Instrument::setMaxPitchA(int v)
{
d->setMaxPitchA(v);
}
//---------------------------------------------------------
// transpose
//---------------------------------------------------------
Interval Instrument::transpose() const
{
return d->transpose();
}
//---------------------------------------------------------
// setTranspose
//---------------------------------------------------------
void Instrument::setTranspose(const Interval& v)
{
d->setTranspose(v);
}
//---------------------------------------------------------
// setDrumset
//---------------------------------------------------------
void Instrument::setDrumset(Drumset* ds)
{
d->setDrumset(ds);
}
//---------------------------------------------------------
// drumset
//---------------------------------------------------------
Drumset* Instrument::drumset() const
{
return d->drumset();
}
//---------------------------------------------------------
// useDrumset
//---------------------------------------------------------
bool Instrument::useDrumset() const
{
return d->useDrumset();
}
//---------------------------------------------------------
// setUseDrumset
//---------------------------------------------------------
void Instrument::setUseDrumset(bool val)
{
d->setUseDrumset(val);
}
//---------------------------------------------------------
// setAmateurPitchRange
//---------------------------------------------------------
void Instrument::setAmateurPitchRange(int a, int b)
{
d->setAmateurPitchRange(a, b);
}
//---------------------------------------------------------
// setProfessionalPitchRange
//---------------------------------------------------------
void Instrument::setProfessionalPitchRange(int a, int b)
{
d->setProfessionalPitchRange(a, b);
}
//---------------------------------------------------------
// channel
//---------------------------------------------------------
Channel& Instrument::channel(int idx)
{
return d->channel(idx);
}
//---------------------------------------------------------
// channel
//---------------------------------------------------------
const Channel& Instrument::channel(int idx) const
{
return d->channel(idx);
}
//---------------------------------------------------------
// midiActions
//---------------------------------------------------------
const QList<NamedEventList>& Instrument::midiActions() const
{
return d->midiActions();
}
//---------------------------------------------------------
// articulation
//---------------------------------------------------------
const QList<MidiArticulation>& Instrument::articulation() const
{
return d->articulation();
}
//---------------------------------------------------------
// channel
//---------------------------------------------------------
const QList<Channel>& Instrument::channel() const
{
return d->channel();
}
//---------------------------------------------------------
// setMidiActions
//---------------------------------------------------------
void Instrument::setMidiActions(const QList<NamedEventList>& l)
{
d->setMidiActions(l);
}
//---------------------------------------------------------
// setArticulation
//---------------------------------------------------------
void Instrument::setArticulation(const QList<MidiArticulation>& l)
{
d->setArticulation(l);
}
//---------------------------------------------------------
// setChannel
//---------------------------------------------------------
void Instrument::setChannel(const QList<Channel>& l)
{
d->setChannel(l);
}
//---------------------------------------------------------
// setChannel
//---------------------------------------------------------
void Instrument::setChannel(int i, const Channel& c)
{
d->setChannel(i, c);
}
//---------------------------------------------------------
// tablature
//---------------------------------------------------------
Tablature* Instrument::tablature() const
{
return d->tablature();
}
//---------------------------------------------------------
// setTablature
//---------------------------------------------------------
void Instrument::setTablature(Tablature* t)
{
d->setTablature(t);
}
//---------------------------------------------------------
// instrument
//---------------------------------------------------------
const Instrument& InstrumentList::instrument(int tick) const
{
if (empty())
return defaultInstrument;
2013-05-28 15:42:02 +02:00
auto i = upper_bound(tick);
2012-05-26 14:26:10 +02:00
if (i == begin())
return defaultInstrument;
--i;
return i->second;
}
//---------------------------------------------------------
// instrument
//---------------------------------------------------------
Instrument& InstrumentList::instrument(int tick)
{
if (empty())
return defaultInstrument;
2013-05-28 15:42:02 +02:00
auto i = upper_bound(tick);
2012-05-26 14:26:10 +02:00
if (i == begin())
return defaultInstrument;
--i;
return i->second;
}
//---------------------------------------------------------
// setInstrument
//---------------------------------------------------------
void InstrumentList::setInstrument(const Instrument& instr, int tick)
{
2013-05-28 15:42:02 +02:00
if (!insert({tick, instr}).second)
2012-05-26 14:26:10 +02:00
(*this)[tick] = instr;
}
//---------------------------------------------------------
// longName
//---------------------------------------------------------
const QList<StaffNameDoc>& Instrument::longNames() const
{
return d->_longNames;
}
//---------------------------------------------------------
// shortName
//---------------------------------------------------------
const QList<StaffNameDoc>& Instrument::shortNames() const
{
return d->_shortNames;
}
//---------------------------------------------------------
// longName
//---------------------------------------------------------
QList<StaffNameDoc>& Instrument::longNames()
{
return d->_longNames;
}
//---------------------------------------------------------
// setLongName
//---------------------------------------------------------
void Instrument::setLongName(const QTextDocumentFragment& f)
{
d->setLongName(f);
}
//---------------------------------------------------------
// addLongName
//---------------------------------------------------------
void Instrument::addLongName(const StaffNameDoc& f)
{
d->addLongName(f);
}
//---------------------------------------------------------
// addShortName
//---------------------------------------------------------
void Instrument::addShortName(const StaffNameDoc& f)
{
d->addShortName(f);
}
//---------------------------------------------------------
// setShortName
//---------------------------------------------------------
void Instrument::setShortName(const QTextDocumentFragment& f)
{
d->setShortName(f);
}
//---------------------------------------------------------
// shortName
//---------------------------------------------------------
QList<StaffNameDoc>& Instrument::shortNames()
{
return d->_shortNames;
}
//---------------------------------------------------------
// trackName
//---------------------------------------------------------
QString Instrument::trackName() const
{
return d->_trackName;
}
void Instrument::setTrackName(const QString& s)
{
d->_trackName = s;
}
//---------------------------------------------------------
// fromTemplate
//---------------------------------------------------------
Instrument Instrument::fromTemplate(const InstrumentTemplate* t)
{
Instrument instr;
instr.setAmateurPitchRange(t->minPitchA, t->maxPitchA);
instr.setProfessionalPitchRange(t->minPitchP, t->maxPitchP);
foreach(StaffName sn, t->longNames)
instr.addLongName(StaffNameDoc(sn.name, sn.pos));
2012-05-26 14:26:10 +02:00
foreach(StaffName sn, t->shortNames)
instr.addShortName(StaffNameDoc(sn.name, sn.pos));
2012-05-26 14:26:10 +02:00
instr.setTrackName(t->trackName);
instr.setTranspose(t->transpose);
if (t->useDrumset) {
instr.setUseDrumset(true);
instr.setDrumset(new Drumset(*((t->drumset) ? t->drumset : smDrumset)));
}
instr.setMidiActions(t->midiActions);
instr.setArticulation(t->articulation);
instr.setChannel(t->channel);
instr.setTablature(t->tablature ? new Tablature(*t->tablature) : 0);
return instr;
}
2013-05-13 18:49:17 +02:00
}