2012-05-26 14:26:10 +02:00
|
|
|
//=============================================================================
|
|
|
|
// MuseScore
|
|
|
|
// Music Composition & Notation
|
|
|
|
//
|
|
|
|
// Copyright (C) 2007-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 "drumset.h"
|
|
|
|
#include "xml.h"
|
|
|
|
#include "note.h"
|
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
namespace Ms {
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
Drumset* smDrumset; // standard midi drumset
|
2014-08-14 13:40:24 +02:00
|
|
|
Drumset* gpDrumset; // guitar pro drumset
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// save
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2016-11-19 11:51:21 +01:00
|
|
|
void Drumset::save(XmlWriter& xml) const
|
2012-05-26 14:26:10 +02:00
|
|
|
{
|
|
|
|
for (int i = 0; i < 128; ++i) {
|
|
|
|
if (!isValid(i))
|
|
|
|
continue;
|
|
|
|
xml.stag(QString("Drum pitch=\"%1\"").arg(i));
|
2016-10-20 10:13:12 +02:00
|
|
|
xml.tag("head", NoteHead::group2name(noteHead(i)));
|
2012-05-26 14:26:10 +02:00
|
|
|
xml.tag("line", line(i));
|
|
|
|
xml.tag("voice", voice(i));
|
|
|
|
xml.tag("name", name(i));
|
|
|
|
xml.tag("stem", int(stemDirection(i)));
|
|
|
|
if (shortcut(i)) {
|
|
|
|
switch (shortcut(i)) {
|
|
|
|
case 'C':
|
|
|
|
case 'D':
|
|
|
|
case 'E':
|
|
|
|
case 'F':
|
|
|
|
case 'G':
|
|
|
|
case 'A':
|
|
|
|
case 'B':
|
|
|
|
{
|
|
|
|
char a[2];
|
|
|
|
a[0] = shortcut(i);
|
|
|
|
a[1] = 0;
|
|
|
|
xml.tag("shortcut", a);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2014-03-25 13:33:47 +01:00
|
|
|
qDebug("illegal drum shortcut");
|
2012-05-26 14:26:10 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xml.etag();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-20 10:13:12 +02:00
|
|
|
bool Drumset::readProperties(XmlReader& e, int pitch)
|
|
|
|
{
|
|
|
|
const QStringRef& tag(e.name());
|
|
|
|
if (tag == "head")
|
|
|
|
_drum[pitch].notehead = NoteHead::name2group(e.readElementText());
|
|
|
|
else if (tag == "line")
|
|
|
|
_drum[pitch].line = e.readInt();
|
|
|
|
else if (tag == "voice")
|
|
|
|
_drum[pitch].voice = e.readInt();
|
|
|
|
else if (tag == "name")
|
|
|
|
_drum[pitch].name = e.readElementText();
|
|
|
|
else if (tag == "stem")
|
|
|
|
_drum[pitch].stemDirection = Direction(e.readInt());
|
|
|
|
else if (tag == "shortcut") {
|
|
|
|
bool isNum;
|
|
|
|
QString val(e.readElementText());
|
|
|
|
int i = val.toInt(&isNum);
|
|
|
|
_drum[pitch].shortcut = isNum ? i : toupper(val[0].toLatin1());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// load
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2013-01-11 18:10:18 +01:00
|
|
|
void Drumset::load(XmlReader& e)
|
2012-05-26 14:26:10 +02:00
|
|
|
{
|
2013-01-11 18:10:18 +01:00
|
|
|
int pitch = e.intAttribute("pitch", -1);
|
2012-05-26 14:26:10 +02:00
|
|
|
if (pitch < 0 || pitch > 127) {
|
2014-03-25 13:33:47 +01:00
|
|
|
qDebug("load drumset: invalid pitch %d", pitch);
|
2012-05-26 14:26:10 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-01-11 18:10:18 +01:00
|
|
|
while (e.readNextStartElement()) {
|
2016-10-20 10:13:12 +02:00
|
|
|
if (readProperties(e, pitch))
|
|
|
|
;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// clear
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void Drumset::clear()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 128; ++i) {
|
|
|
|
_drum[i].name = "";
|
2014-06-25 21:18:26 +02:00
|
|
|
_drum[i].notehead = NoteHead::Group::HEAD_INVALID;
|
2012-05-26 14:26:10 +02:00
|
|
|
_drum[i].shortcut = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// nextPitch
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2015-02-04 19:51:24 +01:00
|
|
|
int Drumset::nextPitch(int ii) const
|
2012-05-26 14:26:10 +02:00
|
|
|
{
|
|
|
|
for (int i = ii + 1; i < 127; ++i) {
|
|
|
|
if (isValid(i))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
for (int i = 0; i <= ii; ++i) {
|
|
|
|
if (isValid(i))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// prevPitch
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2015-02-04 19:51:24 +01:00
|
|
|
int Drumset::prevPitch(int ii) const
|
2012-05-26 14:26:10 +02:00
|
|
|
{
|
|
|
|
for (int i = ii - 1; i >= 0; --i) {
|
|
|
|
if (isValid(i))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
for (int i = 127; i >= ii; --i) {
|
|
|
|
if (isValid(i))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// initDrumset
|
|
|
|
// initialize standard midi drumset
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void initDrumset()
|
|
|
|
{
|
|
|
|
smDrumset = new Drumset;
|
|
|
|
for (int i = 0; i < 128; ++i) {
|
2014-06-25 21:18:26 +02:00
|
|
|
smDrumset->drum(i).notehead = NoteHead::Group::HEAD_INVALID;
|
2012-05-26 14:26:10 +02:00
|
|
|
smDrumset->drum(i).line = 0;
|
|
|
|
smDrumset->drum(i).shortcut = 0;
|
|
|
|
smDrumset->drum(i).voice = 0;
|
2016-03-02 13:20:19 +01:00
|
|
|
smDrumset->drum(i).stemDirection = Direction::UP;
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
2016-03-02 13:20:19 +01:00
|
|
|
smDrumset->drum(35) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Acoustic Bass Drum"), NoteHead::Group::HEAD_NORMAL, 7, Direction::DOWN, 1);
|
|
|
|
smDrumset->drum(36) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Bass Drum 1"), NoteHead::Group::HEAD_NORMAL, 7, Direction::DOWN, 1, Qt::Key_B);
|
|
|
|
smDrumset->drum(37) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Side Stick"), NoteHead::Group::HEAD_CROSS, 3, Direction::UP);
|
|
|
|
smDrumset->drum(38) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Acoustic Snare"), NoteHead::Group::HEAD_NORMAL, 3, Direction::UP, 0, Qt::Key_A);
|
|
|
|
smDrumset->drum(40) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Electric Snare"), NoteHead::Group::HEAD_NORMAL, 3, Direction::UP);
|
|
|
|
smDrumset->drum(41) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Low Floor Tom"), NoteHead::Group::HEAD_NORMAL, 5, Direction::UP);
|
|
|
|
smDrumset->drum(42) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Closed Hi-Hat"), NoteHead::Group::HEAD_CROSS, -1, Direction::UP, 0, Qt::Key_G);
|
|
|
|
smDrumset->drum(43) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "High Floor Tom"), NoteHead::Group::HEAD_NORMAL, 5, Direction::DOWN, 1);
|
|
|
|
smDrumset->drum(44) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Pedal Hi-Hat"), NoteHead::Group::HEAD_CROSS, 9, Direction::DOWN, 1, Qt::Key_F);
|
|
|
|
smDrumset->drum(45) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Low Tom"), NoteHead::Group::HEAD_NORMAL, 2, Direction::UP);
|
|
|
|
smDrumset->drum(46) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Open Hi-Hat"), NoteHead::Group::HEAD_CROSS, 1, Direction::UP);
|
|
|
|
smDrumset->drum(47) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Low-Mid Tom"), NoteHead::Group::HEAD_NORMAL, 1, Direction::UP);
|
|
|
|
smDrumset->drum(48) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Hi-Mid Tom"), NoteHead::Group::HEAD_NORMAL, 0, Direction::UP);
|
|
|
|
smDrumset->drum(49) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Crash Cymbal 1"), NoteHead::Group::HEAD_CROSS, -2, Direction::UP, 0, Qt::Key_C);
|
|
|
|
smDrumset->drum(50) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "High Tom"), NoteHead::Group::HEAD_NORMAL, 0, Direction::UP, 0, Qt::Key_E);
|
|
|
|
smDrumset->drum(51) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Ride Cymbal 1"), NoteHead::Group::HEAD_CROSS, 0, Direction::UP, 0, Qt::Key_D);
|
|
|
|
smDrumset->drum(52) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Chinese Cymbal"), NoteHead::Group::HEAD_CROSS, -3, Direction::UP);
|
|
|
|
smDrumset->drum(53) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Ride Bell"), NoteHead::Group::HEAD_DIAMOND, 0, Direction::UP);
|
|
|
|
smDrumset->drum(54) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Tambourine"), NoteHead::Group::HEAD_DIAMOND, 2, Direction::UP);
|
|
|
|
smDrumset->drum(55) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Splash Cymbal"), NoteHead::Group::HEAD_CROSS, -3, Direction::UP);
|
2016-10-22 20:16:42 +02:00
|
|
|
smDrumset->drum(56) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Cowbell"), NoteHead::Group::HEAD_TRIANGLE_DOWN, 1, Direction::UP);
|
2016-03-02 13:20:19 +01:00
|
|
|
smDrumset->drum(57) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Crash Cymbal 2"), NoteHead::Group::HEAD_CROSS, -3, Direction::UP);
|
|
|
|
smDrumset->drum(59) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Ride Cymbal 2"), NoteHead::Group::HEAD_CROSS, 2, Direction::UP);
|
|
|
|
smDrumset->drum(63) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Open Hi Conga"), NoteHead::Group::HEAD_CROSS, 4, Direction::UP);
|
|
|
|
smDrumset->drum(64) = DrumInstrument(QT_TRANSLATE_NOOP("drumset", "Low Conga"), NoteHead::Group::HEAD_CROSS, 6, Direction::UP);
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
}
|
|
|
|
|