Planeshift
instrument.h
Go to the documentation of this file.
1 /*
2  * instrument.h, Author: Andrea Rizzi <88whacko@gmail.com>
3  *
4  * Copyright (C) 2001-2011 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 
20 #ifndef INSTRUMENT_H
21 #define INSTRUMENT_H
22 
23 //====================================================================================
24 // Crystal Space Includes
25 //====================================================================================
26 #include <cssysdef.h>
27 #include <csutil/hash.h>
28 
29 //------------------------------------------------------------------------------------
30 // Forward Declarations
31 //------------------------------------------------------------------------------------
32 struct iSndSysStream;
33 struct csSndSysSoundFormat;
34 
35 
40 struct Note
41 {
42  char* normal;
43  char* sharp;
44  char* flat;
45 
46  size_t normalLength;
47  size_t sharpLength;
48  size_t flatLength;
49 
53  Note()
54  {
55  normal = 0;
56  sharp = 0;
57  flat = 0;
58 
59  normalLength = 0;
60  sharpLength = 0;
61  flatLength = 0;
62  }
63 };
64 
69 {
70 public:
71  float volume;
72  float minDist;
73  float maxDist;
74 
80  Instrument(uint polyphony);
81 
85  ~Instrument();
86 
91  bool IsDefined();
92 
97  uint GetPolyphony() const { return polyphony; }
98 
103  const csSndSysSoundFormat* GetFormat() const { return format; }
104 
109  size_t GetLongestNoteSize() const { return longestBufferSize; }
110 
123  bool AddNote(const char* fileName, char note, int alter, uint octave);
124 
147  size_t GetNoteBuffer(char note, int alter, uint octave, float duration, char* &buffer, size_t &length);
148 
162  void AddNoteToChord(char note, int alter, uint octave, float duration, uint noteNumber, char* buffer, size_t &bufferLength);
163 
164 private:
165  uint polyphony;
166  size_t longestBufferSize;
167  csSndSysSoundFormat* format;
168  csHash<csHash<Note*, char>*, uint> notes;
169 
179  Note* GetNote(char pitch, uint octave);
180 
191  void SetEnharmonic(char pitch, int alter, uint octave, char* buffer, size_t length);
192 };
193 
194 #endif /* INSTRUMENT_H */
195 
float volume
Definition: instrument.h:71
Note()
Constructor.
Definition: instrument.h:53
float maxDist
Definition: instrument.h:73
A single note in a musical score.
Definition: pawssheetline.h:61
size_t GetLongestNoteSize() const
Gets the size of the note with the longest buffer.
Definition: instrument.h:109
size_t sharpLength
the length of the buffer of the sharp note.
Definition: instrument.h:47
float minDist
Definition: instrument.h:72
char * sharp
the buffer of the sharp note.
Definition: instrument.h:43
char * flat
the buffer of the flat note.
Definition: instrument.h:44
char * normal
the buffer of the unaltered note.
Definition: instrument.h:42
size_t flatLength
the length of the buffer of the flat note.
Definition: instrument.h:48
const csSndSysSoundFormat * GetFormat() const
Gets the csSndSysSoundFormat of the notes of this instrument.
Definition: instrument.h:103
size_t normalLength
the length of the buffer of the unaltered note.
Definition: instrument.h:46
short int alter
The note&#39;s alteration (-1 flat, 0 normal, 1 sharp).
Definition: pawssheetline.h:64
uint GetPolyphony() const
Gets the number of notes that this instrument can play at the same time.
Definition: instrument.h:97
This class represent a musical instrument.
Definition: instrument.h:68