libgig 4.4.1
Korg.h
1/***************************************************************************
2 * *
3 * Copyright (C) 2014 Christian Schoenebeck *
4 * <cuse@users.sourceforge.net> *
5 * *
6 * This library is part of libgig. *
7 * *
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library 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 library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21 * MA 02111-1307 USA *
22 ***************************************************************************/
23
24#ifndef LIBGIG_KORG_H
25#define LIBGIG_KORG_H
26
27#include "RIFF.h"
28#include "gig.h" // for struct buffer_t
29#include <vector>
30
74namespace Korg {
75
76 typedef std::string String;
77
78 class KMPRegion;
79 class KMPInstrument;
80
81 typedef gig::buffer_t buffer_t;
82
90 class KSFSample {
91 public:
92 String Name;
93 uint8_t DefaultBank;
94 uint32_t Start;
95 uint32_t Start2;
96 uint32_t LoopStart;
97 uint32_t LoopEnd;
98 uint32_t SampleRate;
99 uint8_t Attributes;
100 int8_t LoopTune;
101 uint8_t Channels;
102 uint8_t BitDepth;
103 uint32_t SamplePoints;
104
105 KSFSample(const String& filename);
106 virtual ~KSFSample();
107 int FrameSize() const;
108 bool IsCompressed() const;
109 uint8_t CompressionID() const;
110 bool Use2ndStart() const;
111 String FileName() const;
112 buffer_t GetCache() const;
114 buffer_t LoadSampleData(unsigned long SampleCount);
116 buffer_t LoadSampleDataWithNullSamplesExtension(unsigned long SampleCount, uint NullSamplesCount);
117 void ReleaseSampleData();
118 unsigned long SetPos(unsigned long SampleCount, RIFF::stream_whence_t Whence = RIFF::stream_start);
119 unsigned long GetPos() const;
120 unsigned long Read(void* pBuffer, unsigned long SampleCount);
121 private:
122 RIFF::File* riff;
123 buffer_t RAMCache;
124 };
125
133 class KMPRegion {
134 public:
135 bool Transpose;
136 uint8_t OriginalKey;
137 uint8_t TopKey;
138 int8_t Tune;
139 int8_t Level;
140 int8_t Pan;
143
144 String FullSampleFileName() const;
145 KMPInstrument* GetInstrument() const;
146 protected:
147 KMPRegion(KMPInstrument* parent, RIFF::Chunk* rlp1);
148 virtual ~KMPRegion();
149 friend class KMPInstrument;
150 private:
151 KMPInstrument* parent;
152 RIFF::Chunk* rlp1;
153 };
154
172 public:
173 String Name16;
174 String Name24;
175 uint8_t Attributes;
176
177 KMPInstrument(const String& filename);
178 virtual ~KMPInstrument();
179 KMPRegion* GetRegion(int index);
180 int GetRegionCount() const;
181 bool Use2ndStart() const;
182 String FileName() const;
183 String Name() const;
184 private:
185 RIFF::File* riff;
186 std::vector<KMPRegion*> regions;
187 };
188
199 class Exception : public RIFF::Exception {
200 public:
201 Exception(String Message);
202 void PrintMessage();
203 };
204
205 String libraryName();
206 String libraryVersion();
207
208} // namespace Korg
209
210#endif // LIBGIG_KORG_H
Korg format specific exception.
Definition Korg.h:199
.KMP multi sample file
Definition Korg.h:171
String Name16
Human readable name of the instrument for display purposes (not the file name). Since this name is al...
Definition Korg.h:173
uint8_t Attributes
Bit field of attribute flags (ATM only bit 0 is used, better call Use2ndStart() instead of accessing ...
Definition Korg.h:175
String Name24
Longer Human readable name (24 characters) of the instrument for display purposes (not the file name)...
Definition Korg.h:174
String Name() const
Returns the long name (Name24) if it was stored in the file, otherwise returns the short name (Name16...
Definition Korg.cpp:426
Region of a .KMP multi sample file.
Definition Korg.h:133
String SampleFileName
Base file name of sample file (12 bytes). Call FullSampleFileName() for getting the file name with pa...
Definition Korg.h:142
int8_t Tune
-99..+99 cents
Definition Korg.h:138
int8_t Level
-99..+99 cents
Definition Korg.h:139
uint8_t OriginalKey
Note of sample's original pitch, a.k.a. "root key" (0..127).
Definition Korg.h:136
int8_t FilterCutoff
-50..0
Definition Korg.h:141
int8_t Pan
-64..+63
Definition Korg.h:140
uint8_t TopKey
The end of this region on the keyboard (0..127). The start of this region is given by TopKey+1 of the...
Definition Korg.h:137
.KSF audio sample file
Definition Korg.h:90
uint8_t BitDepth
i.e. 8 or 16
Definition Korg.h:102
uint8_t Channels
Number of audio channels (seems to be always 1, thus Mono for all Korg sound files ATM).
Definition Korg.h:101
buffer_t GetCache() const
Returns current cached sample points.
Definition Korg.cpp:219
unsigned long Read(void *pBuffer, unsigned long SampleCount)
Reads SampleCount number of sample points from the current position into the buffer pointed by pBuffe...
Definition Korg.cpp:300
int8_t LoopTune
-99..+99
Definition Korg.h:100
uint8_t DefaultBank
0..3
Definition Korg.h:93
unsigned long SetPos(unsigned long SampleCount, RIFF::stream_whence_t Whence=RIFF::stream_start)
Sets the position within the sample (in sample points, not in bytes).
Definition Korg.cpp:252
uint32_t SamplePoints
Currently the library expects all Korg samples to be Mono, thus the value here might be incorrect in ...
Definition Korg.h:103
String Name
Sample name for drums (since this name is always stored with 16 bytes, this name must never be longer...
Definition Korg.h:92
buffer_t LoadSampleData()
Loads the whole sample wave into RAM.
Definition Korg.cpp:139
int FrameSize() const
Returns the size of one sample point of this sample in bytes.
Definition Korg.cpp:317
uint32_t SampleRate
i.e. 44100
Definition Korg.h:98
buffer_t LoadSampleDataWithNullSamplesExtension(uint NullSamplesCount)
Loads the whole sample wave into RAM.
Definition Korg.cpp:174
void ReleaseSampleData()
Frees the cached sample from RAM if loaded with LoadSampleData() previously.
Definition Korg.cpp:234
uint8_t Attributes
Bit field of flags, better call IsCompressed(), CompressionID() and Use2ndStart() instead of accessin...
Definition Korg.h:99
unsigned long GetPos() const
Returns the current position in the sample (in sample points).
Definition Korg.cpp:279
Ordinary RIFF Chunk.
Definition RIFF.h:179
Will be thrown whenever an error occurs while handling a RIFF file.
Definition RIFF.h:391
RIFF File.
Definition RIFF.h:313
KORG sound format specific classes and definitions.
Definition Korg.h:74
String libraryVersion()
Returns version of this C++ library.
Definition Korg.cpp:460
String libraryName()
Returns the name of this C++ library.
Definition Korg.cpp:452
stream_whence_t
File stream position dependent to these relations.
Definition RIFF.h:124
Pointer address and size of a buffer.
Definition gig.h:114