Sequence.h
1 /*
2 
3 Copyright (c) 2018, Johnathan Corkery. (jcorkery@umich.edu)
4 All rights reserved.
5 
6 This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
7 Dynacoe was released under the MIT License, as detailed below.
8 
9 
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is furnished
16 to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall
19 be included in all copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 
29 
30 
31 */
32 
33 #ifndef H_DC_SEQUENCE_INCLUDED
34 #define H_DC_SEQUENCE_INCLUDED
35 
36 #include <Dynacoe/Modules/Assets.h>
37 
38 
39 namespace Dynacoe {
40 
48 class Sequence : public Asset{
49  public:
50 
53  struct Note {
54  Note();
55 
56 
63  Note(AssetID sound_, float duration_ = 4.f, uint8_t volume_ = 128, uint8_t panning_ = 128) :
64  duration(duration_),
65  sound(sound_),
66  volume(volume_),
67  panning(panning_){}
68 
69  Note(const Note & n) :
70  duration(n.duration),
71  sound(n.sound),
72  volume(n.volume),
73  panning(n.panning){}
74 
77  float duration;
78 
82 
85  uint8_t volume;
86 
89  uint8_t panning;
90  };
91 
92 
95  class Chord {
96  public:
97  Chord(uint32_t channel = 0);
98  Chord(const std::vector<Note>&, float startTime, uint32_t channel = 0);
99 
102  Note & GetNote(int n);
103 
106  int GetNumNotes();
107 
110  void AddNote(const Note &);
111 
114  void RemoveNote(int n);
115 
118  void SetStartTime(float t);
119 
122  float GetStartTime();
123 
124 
127  uint32_t GetChannel();
128 
131  void SetChannel(uint32_t);
132 
133 
134 
135 
136 
137 
138 
139  private:
140  float setTime;
141  std::vector<Note> nList;
142  int32_t channel;
143  };
144 
145 
148  class Measure {
149  std::vector<Chord> cList;
150  int index;
151  public:
152  Measure();
153  Measure(const std::vector<Chord>&);
154 
157  Chord & GetChord(int i);
158 
161  int GetNumChords();
162 
165  void AddChord(const Chord &);
166 
169  void RemoveChord(int i);
170 
171 
172  };
173 
174 
175 
176  Sequence(const std::string & n);
177 
181 
185 
190 
191 
192 
193 
194 
197  float GetLength();
198 
201  int GetNumMeasures();
202 
206  int GetNumMeasuresUsed();
207 
208 
209 
213  void AddMeasures(const std::vector<Measure> &);
214 
217  Measure & GetMeasure(int i);
218 
221  void RemoveMeasure(int i);
222 
223 
224  private:
225  std::vector<Measure> mList;
226 
227 };
228 
229 
230 }
231 
232 
233 
234 #endif
void AddChord(const Chord &)
Adds the specified chord to this Measure.
int GetNumNotes()
Returns the number of notes that belong to this chord.
A collection of notes that begin playing at the same time.
Definition: Sequence.h:95
A discreet sound that plays for a specified amount of time.
Definition: Sequence.h:53
float duration
Duration of the sound in beats.
Definition: Sequence.h:77
AssetID sound
AssetID of the sound to be played.
Definition: Sequence.h:81
Assets that contains information to play a song made of loaded audio samples.
Definition: Sequence.h:48
void SetStartTime(float t)
Sets when this chord is played. Measured in beats.
int GetNumMeasuresUsed()
Returns the number of measures up to the last measure actully being utilized. i.e. the last measure that contains a note.
uint8_t panning
Panning of the note.
Definition: Sequence.h:89
Definition: AssetID.h:37
int GetNumChords()
Returns the number of chords part of this measure.
void AddNote(const Note &)
Adds a new note to be part of this chord.
float GetStartTime()
Returns the start time.
void SetChannel(uint32_t)
Sets the Sound channel that this chord will play on.
void RemoveNote(int n)
Removes the specified note from the chord.
Assets are referred to by an AssetID. The AssetID uniquely refers to an Asset stored within memory...
Definition: AssetID.h:42
A collection of chords. All chord start times are offset from the start of this measure.
Definition: Sequence.h:148
float beatsPerMinute
The playback speed of the sequence.
Definition: Sequence.h:180
int beatsPerMeasure
The number of beats that each measure should be given.
Definition: Sequence.h:184
void RemoveMeasure(int i)
Remove the specified measure.
Note(AssetID sound_, float duration_=4.f, uint8_t volume_=128, uint8_t panning_=128)
Convenience constructor.
Definition: Sequence.h:63
int GetNumMeasures()
Returns the number of physical measures stored in the sequence.
float beatDuration
Defines what represents the beat. This is a fraction of the while measure. For example, in 4/4 time, the beatDuration would be 1.f / 4.f because the quarter note would get the beat.
Definition: Sequence.h:189
Chord & GetChord(int i)
Returns the specified chord.
void RemoveChord(int i)
Removes the specified Chord.
Measure & GetMeasure(int i)
Returns the specified measure.
void AddMeasures(const std::vector< Measure > &)
Adds measures to the sequence.
uint8_t volume
Volume of the note. 0 - 255: 0 is no sound while 255 is max volume.
Definition: Sequence.h:85
Note & GetNote(int n)
Returns the specified note.
float GetLength()
Returns the duration of the Sequence in seconds.