summaryrefslogtreecommitdiff
path: root/attic/muse_qt4_evolution/muse/midiedit/drummap.cpp
blob: 978c7dab27ecb4642d795687e925bfd1dafa2427 (plain)
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
//=============================================================================
//  MusE
//  Linux Music Editor
//  $Id:$
//
//  Copyright (C) 2002-2006 by Werner Schweer and others
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License version 2.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================

#include "drummap.h"
#include "al/xml.h"

static const int DEFAULT_QUANT = 16;
static const int DEFAULT_LEN   = 32;
static const int DEFAULT_CHANNEL = -1;
static const int DEFAULT_LV1   = 70;
static const int DEFAULT_LV2   = 90;
static const int DEFAULT_LV3   = 110;
static const int DEFAULT_LV4   = 127;

//---------------------------------------------------------
//    GM default drum map
//---------------------------------------------------------

DrumMap gmDrumMap("generic");
DrumMap noDrumMap("no-map");

//---------------------------------------------------------
//   DrumMap
//---------------------------------------------------------

DrumMap::DrumMap(const QString& s)
      {
      _name = s;
      for (int i = 0; i < DRUM_MAPSIZE; ++i) {
            map[i].name    = "?";
            map[i].enote   = i;
            map[i].anote   = i;
            map[i].quant   = DEFAULT_QUANT;
            map[i].len     = DEFAULT_LEN;
            map[i].channel = DEFAULT_CHANNEL;
            map[i].lv1     = DEFAULT_LV1;
            map[i].lv2     = DEFAULT_LV2;
            map[i].lv3     = DEFAULT_LV3;
            map[i].lv4     = DEFAULT_LV4;
            map[i].mute    = false;
            }
      init();
      }

//---------------------------------------------------------
//   initGm
//---------------------------------------------------------

void DrumMap::initGm()
      {
      static const char* gmNames[] = {
            "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
            "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat",
            "High Floor Tom", "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom",
            "Hi-Mid Tom", "Crash Cymbal 1", "High Tom", "Ride Cymbal 1",
            "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
            "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2",
            "Hi Bongo", "Low Bongo", "Mute Hi Conga", "Open Hi Conga",
            "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
            "Low Agogo", "Cabasa", "Maracas", "Short Whistle",
            "Long Whistle", "Short Guiro", "Long Guiro", "Claves",
            "Hi Wood Block", "Low Wood Block", "Mute Cuica",
            "Open Cuica", "Mute Triangle", "Open Triangle", 0
            };
      init();
      int idx = 0;
      const char** p = &gmNames[0];
      int val = 35;
      for (; *p; ++p, ++val, ++idx) {
            map[idx].name  = *p;
            map[idx].enote = val;
            map[idx].anote = val;
            _inmap[int(map[idx].enote)] = idx;
            _outmap[int(map[idx].anote)] = idx;
            }
      }

//---------------------------------------------------------
//   init
//    populate Inmap and Outmap
//---------------------------------------------------------

void DrumMap::init()
      {
      memset(_inmap, 0, sizeof(_inmap));
      memset(_outmap, 0, sizeof(_outmap));
      for (int i = 0; i < DRUM_MAPSIZE; ++i) {
            _inmap[int(map[i].enote)] = i;
            _outmap[int(map[i].anote)] = i;
            }
      }

//---------------------------------------------------------
//   writeDrumMap
//---------------------------------------------------------

void DrumMap::write(Xml& xml)
      {
      xml.stag("drummap");
      for (int i = 0; i < DRUM_MAPSIZE; ++i) {
            DrumMapEntry* dm = &map[i];
            dm->write(xml);
            }
      xml.etag("drummap");
      }

//---------------------------------------------------------
//   write
//---------------------------------------------------------

void DrumMapEntry::write(Xml& xml)
      {
      xml.stag("entry");
      xml.tag("name", name);
      if (quant != DEFAULT_QUANT)
            xml.tag("quant", quant);
      if (len != DEFAULT_LEN)
            xml.tag("len", len);
      if (channel != DEFAULT_CHANNEL)
            xml.tag("channel", channel);
      if (lv1 != DEFAULT_LV1)
            xml.tag("lv1", lv1);
      if (lv2 != DEFAULT_LV2)
            xml.tag("lv2", lv2);
      if (lv3 != DEFAULT_LV3)
            xml.tag("lv3", lv3);
      if (lv4 != DEFAULT_LV4)
            xml.tag("lv4", lv4);
      xml.tag("enote", enote);
      if (anote != enote)
            xml.tag("anote", anote);
      xml.etag("entry");
      }

//---------------------------------------------------------
//   read
//---------------------------------------------------------

void DrumMapEntry::read(QDomNode n)
      {
      anote = -1;
      for (QDomNode node = n.firstChild(); !node.isNull(); node = node.nextSibling()) {
            QDomElement e = node.toElement();
            QString tag(e.tagName());
            QString s(e.text());
            if (tag == "name")
                  name = s;
            else if (tag == "quant")
                  quant = s.toInt();
            else if (tag == "len")
                  len = s.toInt();
            else if (tag == "channel")
                  channel = s.toInt();
            else if (tag == "lv1")
                  lv1 = s.toInt();
            else if (tag == "lv2")
                  lv2 = s.toInt();
            else if (tag == "lv3")
                  lv3 = s.toInt();
            else if (tag == "lv4")
                  lv4 = s.toInt();
            else if (tag == "enote")
                  enote = s.toInt();
            else if (tag == "anote")
                  anote = s.toInt();
            else if (tag == "mute")
                  mute = s.toInt();
            else {
                  printf("read Drummap Entry: unknown tag %s\n", tag.toLatin1().data());
                  break;
                  }
            }
      if (anote == -1)
            anote = enote;
      }

//---------------------------------------------------------
//   readDrummap
//---------------------------------------------------------

void DrumMap::read(QDomNode node)
      {
      init();
      int idx = 0;
      for (; !node.isNull(); node = node.nextSibling()) {
            QDomElement e = node.toElement();
            QString tag(e.tagName());

            if (tag == "entry") {
                  QDomNode entryNode = node.firstChild();
                  map[idx].read(entryNode);
            	_inmap[int(map[idx].enote)]  = idx;
            	_outmap[int(map[idx].anote)] = idx;
                  ++idx;
                  }
            else {
                  printf("read Drummap: unknown tag %s\n", tag.toLatin1().data());
                  break;
                  }
            }
      }