1 //=============================================================================
2 //  MuseScore
3 //  Music Composition & Notation
4 //
5 //  Copyright (C) 2002-2011 Werner Schweer
6 //
7 //  This program is free software; you can redistribute it and/or modify
8 //  it under the terms of the GNU General Public License version 2
9 //  as published by the Free Software Foundation and appearing in
10 //  the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __DRUMSET_H__
14 #define __DRUMSET_H__
15 
16 #include "mscore.h"
17 #include "tremolo.h"
18 #include "note.h"
19 #include "sym.h"
20 
21 namespace Ms {
22 
23 class XmlWriter;
24 
25 struct DrumInstrumentVariant {
26       int pitch;
27       QString articulationName;
28       TremoloType tremolo;
DrumInstrumentVariantDrumInstrumentVariant29       DrumInstrumentVariant() {
30             pitch = INVALID_PITCH;
31             tremolo = TremoloType::INVALID_TREMOLO;
32             articulationName = "";
33       }
34 };
35 
36 //---------------------------------------------------------
37 //   DrumInstrument
38 //---------------------------------------------------------
39 
40 struct DrumInstrument {
41       QString name;
42 
43       // if notehead = HEAD_CUSTOM, custom, use noteheads
44       NoteHead::Group notehead; ///< notehead symbol set
45       SymId noteheads[int(NoteHead::Type::HEAD_TYPES)] = { SymId::noteheadWhole, SymId::noteheadHalf, SymId::noteheadBlack, SymId::noteheadDoubleWhole  };
46 
47       int line;                 ///< place notehead onto this line
48       Direction stemDirection;
49       int voice;
50       char shortcut;            ///< accelerator key (CDEFGAB)
51       QList<DrumInstrumentVariant> variants;
52 
DrumInstrumentDrumInstrument53       DrumInstrument() {}
54       DrumInstrument(const char* s, NoteHead::Group nh, int l, Direction d,
55          int v = 0, char sc = 0)
nameDrumInstrument56          : name(s), notehead(nh), line(l), stemDirection(d), voice(v), shortcut(sc) {}
addVariantDrumInstrument57       void addVariant(DrumInstrumentVariant v) { variants.append(v); }
58       };
59 
60 static const int DRUM_INSTRUMENTS = 128;
61 
62 //---------------------------------------------------------
63 //   Drumset
64 //    defines noteheads and line position for all
65 //    possible midi notes in a drumset
66 //---------------------------------------------------------
67 
68 class Drumset {
69       DrumInstrument _drum[DRUM_INSTRUMENTS];
70 
71    public:
isValid(int pitch)72       bool isValid(int pitch) const             { return !_drum[pitch].name.isEmpty(); }
noteHead(int pitch)73       NoteHead::Group noteHead(int pitch) const { return _drum[pitch].notehead;       }
noteHeads(int pitch,NoteHead::Type t)74       SymId noteHeads(int pitch, NoteHead::Type t) const  { return _drum[pitch].noteheads[int(t)];      }
line(int pitch)75       int line(int pitch) const                 { return _drum[pitch].line;           }
voice(int pitch)76       int voice(int pitch) const                { return _drum[pitch].voice;          }
stemDirection(int pitch)77       Direction stemDirection(int pitch) const  { return _drum[pitch].stemDirection;  }
name(int pitch)78       const QString& name(int pitch) const      { return _drum[pitch].name;           }
shortcut(int pitch)79       int shortcut(int pitch) const             { return _drum[pitch].shortcut;       }
variants(int pitch)80       QList<DrumInstrumentVariant> variants(int pitch) const   { return _drum[pitch].variants; }
81 
82       void save(XmlWriter&) const;
83       void load(XmlReader&);
84       bool readProperties(XmlReader&, int);
85       void clear();
86       int nextPitch(int) const;
87       int prevPitch(int) const;
drum(int i)88       DrumInstrument& drum(int i) { return _drum[i]; }
drum(int i)89       const DrumInstrument& drum(int i) const { return _drum[i]; }
90       DrumInstrumentVariant findVariant(int pitch, const QVector<Articulation*> articulations, Tremolo* tremolo) const;
91       };
92 
93 extern Drumset* smDrumset;
94 extern Drumset* gpDrumset;
95 extern void initDrumset();
96 
97 
98 }     // namespace Ms
99 #endif
100 
101