ScummVM API documentation
Part.h
1 /* Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Dean Beeler, Jerome Fisher
2  * Copyright (C) 2011-2022 Dean Beeler, Jerome Fisher, Sergey V. Mikayev
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 2.1 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef MT32EMU_PART_H
19 #define MT32EMU_PART_H
20 
21 #include "globals.h"
22 #include "internals.h"
23 #include "Types.h"
24 #include "Structures.h"
25 
26 namespace MT32Emu {
27 
28 class Poly;
29 class Synth;
30 
31 class PolyList {
32 private:
33  Poly *firstPoly;
34  Poly *lastPoly;
35 
36 public:
37  PolyList();
38  bool isEmpty() const;
39  Poly *getFirst() const;
40  Poly *getLast() const;
41  void prepend(Poly *poly);
42  void append(Poly *poly);
43  Poly *takeFirst();
44  void remove(Poly * const poly);
45 };
46 
47 class Part {
48 private:
49  // Direct pointer to sysex-addressable memory dedicated to this part (valid for parts 1-8, NULL for rhythm)
50  TimbreParam *timbreTemp;
51 
52  // 0=Part 1, .. 7=Part 8, 8=Rhythm
53  unsigned int partNum;
54 
55  bool holdpedal;
56 
57  unsigned int activePartialCount;
58  unsigned int activeNonReleasingPolyCount;
59  PatchCache patchCache[4];
60  PolyList activePolys;
61 
62  void setPatch(const PatchParam *patch);
63  unsigned int midiKeyToKey(unsigned int midiKey);
64 
65  bool abortFirstPoly(unsigned int key);
66 
67 protected:
68  Synth *synth;
69  // Direct pointer into sysex-addressable memory
70  MemParams::PatchTemp *patchTemp;
71  char name[8]; // "Part 1".."Part 8", "Rhythm"
72  char currentInstr[11];
73  // Values outside the valid range 0..100 imply no override.
74  Bit8u volumeOverride;
75  Bit8u modulation;
76  Bit8u expression;
77  Bit32s pitchBend;
78  bool nrpn;
79  Bit16u rpn;
80  Bit16u pitchBenderRange; // (patchTemp->patch.benderRange * 683) at the time of the last MIDI program change or MIDI data entry.
81 
82  void backupCacheToPartials(PatchCache cache[4]);
83  void cacheTimbre(PatchCache cache[4], const TimbreParam *timbre);
84  void playPoly(const PatchCache cache[4], const MemParams::RhythmTemp *rhythmTemp, unsigned int midiKey, unsigned int key, unsigned int velocity);
85  void stopNote(unsigned int key);
86  const char *getName() const;
87 
88 public:
89  Part(Synth *synth, unsigned int usePartNum);
90  virtual ~Part();
91  void reset();
92  void setDataEntryMSB(unsigned char midiDataEntryMSB);
93  void setNRPN();
94  void setRPNLSB(unsigned char midiRPNLSB);
95  void setRPNMSB(unsigned char midiRPNMSB);
96  void resetAllControllers();
97  virtual void noteOn(unsigned int midiKey, unsigned int velocity);
98  virtual void noteOff(unsigned int midiKey);
99  void allNotesOff();
100  void allSoundOff();
101  Bit8u getVolume() const; // Effective output level, valid range 0..100.
102  void setVolume(unsigned int midiVolume); // Valid range 0..127, as defined for MIDI controller 7.
103  Bit8u getVolumeOverride() const;
104  void setVolumeOverride(Bit8u volumeOverride);
105  Bit8u getModulation() const;
106  void setModulation(unsigned int midiModulation);
107  Bit8u getExpression() const;
108  void setExpression(unsigned int midiExpression);
109  virtual void setPan(unsigned int midiPan);
110  Bit32s getPitchBend() const;
111  void setBend(unsigned int midiBend);
112  virtual void setProgram(unsigned int midiProgram);
113  void setHoldPedal(bool pedalval);
114  void stopPedalHold();
115  void updatePitchBenderRange();
116  virtual void refresh();
117  virtual void refreshTimbre(unsigned int absTimbreNum);
118  virtual void setTimbre(TimbreParam *timbre);
119  virtual unsigned int getAbsTimbreNum() const;
120  const char *getCurrentInstr() const;
121  const Poly *getFirstActivePoly() const;
122  unsigned int getActivePartialCount() const;
123  unsigned int getActiveNonReleasingPartialCount() const;
124  Synth *getSynth() const;
125 
126  const MemParams::PatchTemp *getPatchTemp() const;
127 
128  // This should only be called by Poly
129  void partialDeactivated(Poly *poly);
130  virtual void polyStateChanged(PolyState oldState, PolyState newState);
131 
132  // These are rather specialised, and should probably only be used by PartialManager
133  bool abortFirstPoly(PolyState polyState);
134  // Abort the first poly in PolyState_HELD, or if none exists, the first active poly in any state.
135  bool abortFirstPolyPreferHeld();
136  bool abortFirstPoly();
137 }; // class Part
138 
139 class RhythmPart: public Part {
140  // Pointer to the area of the MT-32's memory dedicated to rhythm
141  const MemParams::RhythmTemp *rhythmTemp;
142 
143  // This caches the timbres/settings in use by the rhythm part
144  PatchCache drumCache[85][4];
145 public:
146  RhythmPart(Synth *synth, unsigned int usePartNum);
147  void refresh();
148  void refreshTimbre(unsigned int timbreNum);
149  void setTimbre(TimbreParam *timbre);
150  void noteOn(unsigned int key, unsigned int velocity);
151  void noteOff(unsigned int midiKey);
152  unsigned int getAbsTimbreNum() const;
153  void setPan(unsigned int midiPan);
154  void setProgram(unsigned int patchNum);
155  void polyStateChanged(PolyState oldState, PolyState newState);
156 };
157 
158 } // namespace MT32Emu
159 
160 #endif // #ifndef MT32EMU_PART_H
Definition: Structures.h:47
Definition: Part.h:31
Definition: Structures.h:111
Definition: Part.h:139
Definition: Analog.h:26
Definition: Structures.h:136
Definition: Structures.h:246
Definition: Synth.h:131
Definition: Poly.h:30
Definition: Structures.h:143
Definition: Part.h:47