1 //=========================================================
2 //  MusE
3 //  Linux Music Editor
4 //
5 //  type_defs.h
6 //  Copyright (C) 2012 Tim E. Real (terminator356 on users dot sourceforge dot net)
7 //
8 //  This program is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU General Public License
10 //  as published by the Free Software Foundation; version 2 of
11 //  the License, or (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU General Public License for more details.
17 //
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 //
22 //=========================================================
23 
24 #ifndef __TYPE_DEFS_H__
25 #define __TYPE_DEFS_H__
26 
27 #include <stdint.h>
28 
29 namespace MusECore {
30 
31 // REMOVE Tim. Added. Moved here from event.h.
32 // NOTICE: The values 3 and 4 (PAfter and CAfter) are reserved for the support of those two obsolete
33 //          channel and key pressure events in old files. They are converted to controllers upon load.
34 enum EventType { Note=0, Controller=1, Sysex=2, /*PAfter=3,*/ /*CAfter=4,*/ Meta=5, Wave=6 };
35 
36 typedef int64_t SongChangedFlags_t;
37 
38 struct SongChangedStruct_t
39 {
40   private:
41   //
42   // 128-bit combination of 128-bit SC_XX flags:
43   //
44   // Normal lower 64 bits of 128-bit flags.
45   SongChangedFlags_t _flagsLo;
46   // Upper 64 bits of 128-bit flags.
47   SongChangedFlags_t _flagsHi;
48 
49   public:
50   // An optional pointer to the object which initiated this song change.
51   // The object's own songChanged() slot (if present) can use this to
52   //  ignore self-generated songChanged signals. This is the only practical
53   //  mechanism available for objects needing to do so. There's really
54   //  no other easy way to ignore such signals.
55   void* _sender;
56 
57   public:
58   inline SongChangedStruct_t(SongChangedFlags_t flagsLo = 0, SongChangedFlags_t flagsHi = 0, void* sender = 0) :
_flagsLoSongChangedStruct_t59     _flagsLo(flagsLo), _flagsHi(flagsHi), _sender(sender) { };
60 
flagsLoSongChangedStruct_t61   SongChangedFlags_t flagsLo() const { return _flagsLo; }
flagsHiSongChangedStruct_t62   SongChangedFlags_t flagsHi() const { return _flagsHi; }
63 
64   // C++11: Avoid necessity of using the "Safe Bool Idiom".
65   explicit inline operator bool() const { return _flagsLo || _flagsHi; }
66 
67   inline SongChangedStruct_t operator~() const
68   { SongChangedStruct_t r(~_flagsLo, ~_flagsHi); return r; }
69 
70   inline bool operator==(const SongChangedStruct_t& f) const { return _flagsLo == f._flagsLo && _flagsHi == f._flagsHi; }
71   inline bool operator!=(const SongChangedStruct_t& f) const { return _flagsLo != f._flagsLo || _flagsHi != f._flagsHi; }
72 
73   inline SongChangedStruct_t& operator|=(const SongChangedStruct_t& f)
74   { _flagsLo |= f._flagsLo; _flagsHi |= f._flagsHi; return *this; }
75 
76   inline SongChangedStruct_t& operator&=(const SongChangedStruct_t& f)
77   { _flagsLo &= f._flagsLo; _flagsHi &= f._flagsHi; return *this; }
78 
79 
80   inline friend SongChangedStruct_t operator|(const SongChangedStruct_t& a, const SongChangedStruct_t& b)
81   { SongChangedStruct_t r(a); r |= b; return r; }
82 
83   inline friend SongChangedStruct_t operator&(const SongChangedStruct_t& a, const SongChangedStruct_t& b)
84   { SongChangedStruct_t r(a); r &= b; return r; }
85 };
86 
87 // Song changed flags:
88 // These are flags, usually passed by connecting to the songChanged() signal,
89 //  which inform that various things have changed and appropriate action should
90 //  be taken (redraw, refill lists etc.) upon the signal's reception.
91 // NOTE: Use the SongChangedStruct_t typedef to support all the bits.
92 
93 #define SC_NOTHING                    MusECore::SongChangedStruct_t(0, 0)
94 #define SC_TRACK_INSERTED             MusECore::SongChangedStruct_t(1)
95 #define SC_TRACK_REMOVED              MusECore::SongChangedStruct_t(2)
96 #define SC_TRACK_MODIFIED             MusECore::SongChangedStruct_t(4)
97 #define SC_PART_INSERTED              MusECore::SongChangedStruct_t(8)
98 #define SC_PART_REMOVED               MusECore::SongChangedStruct_t(0x10)
99 #define SC_PART_MODIFIED              MusECore::SongChangedStruct_t(0x20)
100 #define SC_EVENT_INSERTED             MusECore::SongChangedStruct_t(0x40)
101 #define SC_EVENT_REMOVED              MusECore::SongChangedStruct_t(0x80)
102 #define SC_EVENT_MODIFIED             MusECore::SongChangedStruct_t(0x100)
103 #define SC_SIG                        MusECore::SongChangedStruct_t(0x200)        // timing signature
104 #define SC_TEMPO                      MusECore::SongChangedStruct_t(0x400)        // tempo map changed
105 #define SC_MASTER                     MusECore::SongChangedStruct_t(0x800)        // master flag changed
106 #define SC_SELECTION                  MusECore::SongChangedStruct_t(0x1000)       // event selection. part and track selection have their own.
107 #define SC_MUTE                       MusECore::SongChangedStruct_t(0x2000)       // A track's mute or off state changed.
108 #define SC_SOLO                       MusECore::SongChangedStruct_t(0x4000)
109 #define SC_RECFLAG                    MusECore::SongChangedStruct_t(0x8000)
110 #define SC_ROUTE         MusECore::SongChangedStruct_t(0x10000)  // A route was added, changed, or deleted. Or a midi track's out channel/port was changed.
111 #define SC_CHANNELS                   MusECore::SongChangedStruct_t(0x20000)
112 #define SC_CONFIG                     MusECore::SongChangedStruct_t(0x40000)      // midiPort-midiDevice
113 #define SC_DRUMMAP                    MusECore::SongChangedStruct_t(0x80000)     // must update drumeditor
114 #define SC_MIDI_INSTRUMENT            MusECore::SongChangedStruct_t(0x100000)     // A midi port or device's instrument has changed
115 #define SC_AUDIO_CONTROLLER           MusECore::SongChangedStruct_t(0x200000)     // An audio controller value was added deleted or modified.
116 #define SC_AUTOMATION                 MusECore::SongChangedStruct_t(0x400000)     // A track's automation mode setting changed (off, read, touch, write etc).
117 #define SC_AUX                        MusECore::SongChangedStruct_t(0x800000)    // A mixer aux was added or deleted. Not adjusted.
118 #define SC_RACK                       MusECore::SongChangedStruct_t(0x1000000)    // mixer rack changed
119 #define SC_CLIP_MODIFIED              MusECore::SongChangedStruct_t(0x2000000)
120 #define SC_MIDI_CONTROLLER_ADD        MusECore::SongChangedStruct_t(0x4000000)    // a hardware midi controller was added or deleted
121 // SC_MIDI_TRACK_PROP: A midi track's properties changed (name, thru etc).
122 // For fairly 'static' properties, not frequently changing transp del compr velo or len,
123 //  nor output channel/port (use SC_ROUTE).
124 #define SC_MIDI_TRACK_PROP            MusECore::SongChangedStruct_t(0x8000000)
125 #define SC_PART_SELECTION             MusECore::SongChangedStruct_t(0x10000000)   // part selection changed
126 #define SC_KEY                        MusECore::SongChangedStruct_t(0x20000000)   // key map changed
127 #define SC_TRACK_SELECTION            MusECore::SongChangedStruct_t(0x40000000)   // track selection changed
128 #define SC_PORT_ALIAS_PREFERENCE      MusECore::SongChangedStruct_t(0x80000000)  // (Jack) port alias viewing preference has changed
129 #define SC_ROUTER_CHANNEL_GROUPING    MusECore::SongChangedStruct_t(0x100000000)  // Router channel grouping changed
130 #define SC_AUDIO_CONTROLLER_LIST      MusECore::SongChangedStruct_t(0x200000000)  // An audio controller list was added deleted or modified.
131 #define SC_PIANO_SELECTION            MusECore::SongChangedStruct_t(0x400000000)  // Piano keyboard selected note changed.
132 #define SC_DRUM_SELECTION             MusECore::SongChangedStruct_t(0x800000000)  // Drum list selected note changed.
133 #define SC_TRACK_REC_MONITOR          MusECore::SongChangedStruct_t(0x1000000000) // Audio or midi track's record monitor changed.
134 #define SC_TRACK_MOVED                MusECore::SongChangedStruct_t(0x2000000000) // Audio or midi track's position in track list or mixer changed.
135 #define SC_TRACK_RESIZED              MusECore::SongChangedStruct_t(0x4000000000) // Audio or midi track was resized in the arranger.
136 #define SC_METRONOME                  MusECore::SongChangedStruct_t(0x8000000000) // Metronome lists settings such as accents changed.
137 #define SC_EXTERNAL_MIDI_SYNC         MusECore::SongChangedStruct_t(0x10000000000) // External midi sync flag changed.
138 #define SC_USE_JACK_TRANSPORT         MusECore::SongChangedStruct_t(0x20000000000) // UseJackTransport flag changed.
139 #define SC_TIMEBASE_MASTER            MusECore::SongChangedStruct_t(0x40000000000) // Timebase master state changed.
140 #define SC_AUDIO_CONVERTER            MusECore::SongChangedStruct_t(0x80000000000) // Audio converters settings or value lists changed.
141 #define SC_AUDIO_STRETCH              MusECore::SongChangedStruct_t(0x100000000000) // Audio converters stretch/pitch ratios changed.
142 #define SC_MARKER_INSERTED            MusECore::SongChangedStruct_t(0x200000000000)
143 #define SC_MARKER_REMOVED             MusECore::SongChangedStruct_t(0x400000000000)
144 #define SC_MARKER_MODIFIED            MusECore::SongChangedStruct_t(0x800000000000)
145 // The marker list was rebuilt as a result of tempo changes. NOTE: Currently signals/slots are used for add/remove/modify etc.
146 #define SC_MARKERS_REBUILT            MusECore::SongChangedStruct_t(0x1000000000000)
147 // The midi division changed. Re-normalization of tempo and signature lists will have already occurred.
148 #define SC_DIVISION_CHANGED           MusECore::SongChangedStruct_t(0x2000000000000)
149 #define SC_EVERYTHING                 MusECore::SongChangedStruct_t(-1, -1)       // global update
150 
151 
152 typedef int64_t EventID_t;
153 #define MUSE_INVALID_EVENT_ID   -1
154 #define MUSE_INVALID_POSITION   INT_MAX
155 
156 enum class ResizeDirection {
157       RESIZE_TO_THE_LEFT,
158       RESIZE_TO_THE_RIGHT
159 };
160 
161 enum RelevantSelectedEvents { NoEventsRelevant = 0x00, NotesRelevant = 0x01, ControllersRelevant = 0x02,
162                 SysexRelevant = 0x04, MetaRelevant = 0x08, WaveRelevant = 0x10,
163                 AllEventsRelevant = NotesRelevant | ControllersRelevant |
164                                     SysexRelevant | MetaRelevant | WaveRelevant};
165 typedef int RelevantSelectedEvents_t;
166 
167 enum FunctionOptions {
168   FunctionNoOptions = 0x00,
169   // For pasting. Whether to cut the given items before pasting.
170   // Don't call cut_items() AND then set this flag on paste_at().
171   // Here, cutting is usually reserved for direct pasting
172   //  (calling paste_items_at() with an EventTagList*).
173   FunctionCutItems = 0x01,
174   // Always paste into a new part.
175   FunctionPasteAlwaysNewPart = 0x02,
176   // Never paste into a new part.
177   FunctionPasteNeverNewPart = 0x04,
178   // Erase existing target controller items first.
179   FunctionEraseItems = 0x08,
180   // If FunctionEraseItems is set: How to handle the last item in any 'cluster' of controller events.
181   FunctionEraseItemsWysiwyg = 0x10,
182   // If FunctionEraseItems is set: Erase existing target items in empty source space between 'clusters'.
183   FunctionEraseItemsInclusive = 0x20,
184   FunctionEraseItemsDefault =
185     FunctionEraseItems | FunctionEraseItemsWysiwyg,
186   FunctionAllOptions =
187     FunctionCutItems | FunctionPasteAlwaysNewPart | FunctionPasteNeverNewPart |
188     FunctionEraseItems | FunctionEraseItemsWysiwyg | FunctionEraseItemsInclusive
189 };
190 typedef int FunctionOptions_t;
191 
192 struct FunctionOptionsStruct
193 {
194   FunctionOptions_t _flags;
195 
_flagsFunctionOptionsStruct196   FunctionOptionsStruct(const FunctionOptions_t& flags = FunctionEraseItemsDefault) : _flags(flags) { }
clearFunctionOptionsStruct197   void clear() { _flags = FunctionNoOptions; }
setFlagsFunctionOptionsStruct198   void setFlags(const FunctionOptions_t& flags) { _flags = flags; }
appendFlagsFunctionOptionsStruct199   void appendFlags(const FunctionOptions_t& flags) { _flags |= flags; }
removeFlagsFunctionOptionsStruct200   void removeFlags(const FunctionOptions_t& flags) { _flags &= ~flags; }
201 };
202 
203 
204 }   // namespace MusECore
205 
206 #endif
207