Planeshift
|
00001 /* 00002 * instrument.h, Author: Andrea Rizzi <[email protected]> 00003 * 00004 * Copyright (C) 2001-2011 Atomic Blue ([email protected], http://www.atomicblue.org) 00005 * 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License 00009 * as published by the Free Software Foundation (version 2 of the License) 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 * 00018 */ 00019 00020 #ifndef INSTRUMENT_H 00021 #define INSTRUMENT_H 00022 00023 //==================================================================================== 00024 // Crystal Space Includes 00025 //==================================================================================== 00026 #include <cssysdef.h> 00027 #include <csutil/hash.h> 00028 00029 //------------------------------------------------------------------------------------ 00030 // Forward Declarations 00031 //------------------------------------------------------------------------------------ 00032 struct iSndSysStream; 00033 struct csSndSysSoundFormat; 00034 00035 00040 struct Note 00041 { 00042 char* normal; 00043 char* sharp; 00044 char* flat; 00045 00046 size_t normalLength; 00047 size_t sharpLength; 00048 size_t flatLength; 00049 00053 Note() 00054 { 00055 normal = 0; 00056 sharp = 0; 00057 flat = 0; 00058 00059 normalLength = 0; 00060 sharpLength = 0; 00061 flatLength = 0; 00062 } 00063 }; 00064 00068 class Instrument 00069 { 00070 public: 00071 float volume; 00072 float minDist; 00073 float maxDist; 00074 00080 Instrument(uint polyphony); 00081 00085 ~Instrument(); 00086 00091 bool IsDefined(); 00092 00097 uint GetPolyphony() const { return polyphony; } 00098 00103 const csSndSysSoundFormat* GetFormat() const { return format; } 00104 00109 size_t GetLongestNoteSize() const { return longestBufferSize; } 00110 00123 bool AddNote(const char* fileName, char note, int alter, uint octave); 00124 00147 size_t GetNoteBuffer(char note, int alter, uint octave, float duration, char* &buffer, size_t &length); 00148 00162 void AddNoteToChord(char note, int alter, uint octave, float duration, uint noteNumber, char* buffer, size_t &bufferLength); 00163 00164 private: 00165 uint polyphony; 00166 size_t longestBufferSize; 00167 csSndSysSoundFormat* format; 00168 csHash<csHash<Note*, char>*, uint> notes; 00169 00179 Note* GetNote(char pitch, uint octave); 00180 00191 void SetEnharmonic(char pitch, int alter, uint octave, char* buffer, size_t length); 00192 }; 00193 00194 #endif /* INSTRUMENT_H */ 00195