ScummVM API documentation
midi.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
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 as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef MTROPOLIS_PLUGIN_MIDI_H
23 #define MTROPOLIS_PLUGIN_MIDI_H
24 
25 #include "mtropolis/modifier_factory.h"
26 #include "mtropolis/modifiers.h"
27 #include "mtropolis/plugin/midi_data.h"
28 #include "mtropolis/runtime.h"
29 
30 class MidiDriver;
31 
32 namespace MTropolis {
33 
34 class Runtime;
35 
36 namespace Midi {
37 
38 class MidiPlugIn;
39 class MidiFilePlayer;
40 class MidiNotePlayer;
41 class MultiMidiPlayer;
42 class MidiCombinerSource;
43 
44 class MidiModifier : public Modifier {
45 public:
46  MidiModifier();
47  ~MidiModifier();
48 
49  bool load(const PlugInModifierLoaderContext &context, const Data::Midi::MidiModifier &data);
50 
51  bool respondsToEvent(const Event &evt) const override;
52  VThreadState consumeMessage(Runtime *runtime, const Common::SharedPtr<MessageProperties> &msg) override;
53  void disable(Runtime *runtime) override;
54 
55  bool readAttribute(MiniscriptThread *thread, DynamicValue &result, const Common::String &attrib) override;
56  MiniscriptInstructionOutcome writeRefAttribute(MiniscriptThread *thread, DynamicValueWriteProxy &result, const Common::String &attrib) override;
57  MiniscriptInstructionOutcome writeRefAttributeIndexed(MiniscriptThread *thread, DynamicValueWriteProxy &result, const Common::String &attrib, const DynamicValue &index) override;
58 
59 #ifdef MTROPOLIS_DEBUG_ENABLE
60  const char *debugGetTypeName() const override { return "MIDI Modifier"; }
61  SupportStatus debugGetSupportStatus() const override { return kSupportStatusDone; }
62 #endif
63 
64 private:
65  struct MuteTrackProxyInterface {
66  static MiniscriptInstructionOutcome write(MiniscriptThread *thread, const DynamicValue &dest, void *objectRef, uintptr ptrOrOffset);
67  static MiniscriptInstructionOutcome refAttrib(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib);
68  static MiniscriptInstructionOutcome refAttribIndexed(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib, const DynamicValue &index);
69  };
70 
71  Common::SharedPtr<Modifier> shallowClone() const override;
72  const char *getDefaultName() const override;
73 
74  MiniscriptInstructionOutcome scriptSetVolume(MiniscriptThread *thread, const DynamicValue &value);
75  MiniscriptInstructionOutcome scriptSetNoteVelocity(MiniscriptThread *thread, const DynamicValue &value);
76  MiniscriptInstructionOutcome scriptSetNoteDuration(MiniscriptThread *thread, const DynamicValue &value);
77  MiniscriptInstructionOutcome scriptSetNoteNum(MiniscriptThread *thread, const DynamicValue &value);
78  MiniscriptInstructionOutcome scriptSetLoop(MiniscriptThread *thread, const DynamicValue &value);
79  MiniscriptInstructionOutcome scriptSetPlayNote(MiniscriptThread *thread, const DynamicValue &value);
80  MiniscriptInstructionOutcome scriptSetTempo(MiniscriptThread *thread, const DynamicValue &value);
81  MiniscriptInstructionOutcome scriptSetMuteTrack(MiniscriptThread *thread, const DynamicValue &value);
82 
83  MiniscriptInstructionOutcome scriptSetMuteTrackIndexed(MiniscriptThread *thread, size_t trackIndex, bool muted);
84 
85  uint getBoostedVolume(Runtime *runtime) const;
86 
87  void playSingleNote();
88  void stopSingleNote();
89 
90  struct FilePart {
91  bool loop;
92  bool overrideTempo;
93  double tempo;
94  double fadeIn;
95  double fadeOut;
96  };
97 
98  struct SingleNotePart {
99  uint8 channel;
100  uint8 note;
101  uint8 velocity;
102  uint8 program;
103  double duration;
104  };
105 
106  union ModeSpecificUnion {
107  FilePart file;
108  SingleNotePart singleNote;
109  };
110 
111  enum Mode {
112  kModeFile,
113  kModeSingleNote,
114  };
115 
116  Event _executeWhen;
117  Event _terminateWhen;
118 
119  Mode _mode;
120  ModeSpecificUnion _modeSpecific;
121  uint8 _volume; // We need this always available because scripts will try to set it and then read it even in single note mode
122 
124 
125  uint16 _mutedTracks;
126 
127  MidiPlugIn *_plugIn;
128  MidiFilePlayer *_filePlayer;
129  MidiNotePlayer *_notePlayer;
130 };
131 
133 public:
134  explicit MidiPlugIn(bool useDynamicMidi);
135  ~MidiPlugIn();
136 
137  void registerModifiers(IPlugInModifierRegistrar *registrar) const override;
138 
139  MultiMidiPlayer *getMidi() const;
140 
141 private:
143 
145 };
146 
147 } // End of namespace Midi
148 
149 } // End of namespace MTropolis
150 
151 #endif
Definition: runtime.h:816
Definition: str.h:59
Definition: runtime.h:1594
Definition: runtime.h:1185
Definition: runtime.h:3035
Definition: miniscript.h:421
Definition: modifier_factory.h:57
Definition: runtime.h:544
Definition: mididrv.h:300
Definition: modifier_factory.h:48
Definition: runtime.h:369
Definition: runtime.h:1180
Definition: midi.h:132
Definition: midi_data.h:33
Definition: actions.h:25
Definition: midi.h:44
Definition: ptr.h:159