Korg.h
/***************************************************************************
* *
* Copyright (C) 2014 - 2025 Christian Schoenebeck *
* <cuse@users.sourceforge.net> *
* *
* This library is part of libgig. *
* *
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this library; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
* MA 02111-1307 USA *
***************************************************************************/
#ifndef LIBGIG_KORG_H
#define LIBGIG_KORG_H
#include "RIFF.h"
#include "gig.h" // for struct buffer_t
#include <vector>
namespace Korg {
typedef std::string String;
class KMPRegion;
class KMPInstrument;
typedef gig::buffer_t buffer_t;
class KSFSample {
public:
String Name;
uint8_t DefaultBank;
uint32_t Start;
uint32_t Start2;
uint32_t LoopStart;
uint32_t LoopEnd;
uint32_t SampleRate;
uint8_t Attributes;
int8_t LoopTune;
uint8_t Channels;
uint8_t BitDepth;
uint32_t SamplePoints;
KSFSample(const String& filename);
virtual ~KSFSample();
int FrameSize() const;
bool IsCompressed() const;
uint8_t CompressionID() const;
bool Use2ndStart() const;
String FileName() const;
buffer_t GetCache() const;
buffer_t LoadSampleData();
buffer_t LoadSampleData(unsigned long SampleCount);
buffer_t LoadSampleDataWithNullSamplesExtension(uint NullSamplesCount);
buffer_t LoadSampleDataWithNullSamplesExtension(unsigned long SampleCount, uint NullSamplesCount);
void ReleaseSampleData();
unsigned long SetPos(unsigned long SampleCount, RIFF::stream_whence_t Whence = RIFF::stream_start);
unsigned long GetPos() const;
unsigned long Read(void* pBuffer, unsigned long SampleCount);
private:
RIFF::File* riff;
buffer_t RAMCache;
};
class KMPRegion {
public:
bool Transpose;
uint8_t OriginalKey;
uint8_t TopKey;
int8_t Tune;
int8_t Level;
int8_t Pan;
int8_t FilterCutoff;
String SampleFileName;
String FullSampleFileName() const;
KMPInstrument* GetInstrument() const;
protected:
KMPRegion(KMPInstrument* parent, RIFF::Chunk* rlp1);
virtual ~KMPRegion();
friend class KMPInstrument;
private:
KMPInstrument* parent;
RIFF::Chunk* rlp1;
};
class KMPInstrument {
public:
String Name16;
String Name24;
uint8_t Attributes;
KMPInstrument(const String& filename);
virtual ~KMPInstrument();
KMPRegion* GetRegion(int index);
int GetRegionCount() const;
bool Use2ndStart() const;
String FileName() const;
String Name() const;
private:
RIFF::File* riff;
std::vector<KMPRegion*> regions;
};
class Exception : public RIFF::Exception {
public:
Exception(String Message);
void PrintMessage() const;
};
String libraryName();
String libraryVersion();
} // namespace Korg
#endif // LIBGIG_KORG_H
Korg::KMPInstrument
.KMP multi sample file
Definition Korg.h:171
Korg::KMPInstrument::Name16
String Name16
Human readable name of the instrument for display purposes (not the file name). Since this name is al...
Definition Korg.h:173
Korg::KMPInstrument::Attributes
uint8_t Attributes
Bit field of attribute flags (ATM only bit 0 is used, better call Use2ndStart() instead of accessing ...
Definition Korg.h:175
Korg::KMPInstrument::Name24
String Name24
Longer Human readable name (24 characters) of the instrument for display purposes (not the file name)...
Definition Korg.h:174
Korg::KMPInstrument::Name
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
Korg::KMPRegion
Region of a .KMP multi sample file.
Definition Korg.h:133
Korg::KMPRegion::SampleFileName
String SampleFileName
Base file name of sample file (12 bytes). Call FullSampleFileName() for getting the file name with pa...
Definition Korg.h:142
Korg::KMPRegion::Tune
int8_t Tune
-99..+99 cents
Definition Korg.h:138
Korg::KMPRegion::Level
int8_t Level
-99..+99 cents
Definition Korg.h:139
Korg::KMPRegion::OriginalKey
uint8_t OriginalKey
Note of sample's original pitch, a.k.a. "root key" (0..127).
Definition Korg.h:136
Korg::KMPRegion::FilterCutoff
int8_t FilterCutoff
-50..0
Definition Korg.h:141
Korg::KMPRegion::Pan
int8_t Pan
-64..+63
Definition Korg.h:140
Korg::KMPRegion::TopKey
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
Korg::KSFSample::BitDepth
uint8_t BitDepth
i.e. 8 or 16
Definition Korg.h:102
Korg::KSFSample::Channels
uint8_t Channels
Number of audio channels (seems to be always 1, thus Mono for all Korg sound files ATM).
Definition Korg.h:101
Korg::KSFSample::GetCache
buffer_t GetCache() const
Returns current cached sample points.
Definition Korg.cpp:219
Korg::KSFSample::Read
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
Korg::KSFSample::LoopTune
int8_t LoopTune
-99..+99
Definition Korg.h:100
Korg::KSFSample::DefaultBank
uint8_t DefaultBank
0..3
Definition Korg.h:93
Korg::KSFSample::SetPos
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
Korg::KSFSample::SamplePoints
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
Korg::KSFSample::Name
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
Korg::KSFSample::LoadSampleData
buffer_t LoadSampleData()
Loads the whole sample wave into RAM.
Definition Korg.cpp:139
Korg::KSFSample::FrameSize
int FrameSize() const
Returns the size of one sample point of this sample in bytes.
Definition Korg.cpp:317
Korg::KSFSample::SampleRate
uint32_t SampleRate
i.e. 44100
Definition Korg.h:98
Korg::KSFSample::LoadSampleDataWithNullSamplesExtension
buffer_t LoadSampleDataWithNullSamplesExtension(uint NullSamplesCount)
Loads the whole sample wave into RAM.
Definition Korg.cpp:174
Korg::KSFSample::ReleaseSampleData
void ReleaseSampleData()
Frees the cached sample from RAM if loaded with LoadSampleData() previously.
Definition Korg.cpp:234
Korg::KSFSample::Attributes
uint8_t Attributes
Bit field of flags, better call IsCompressed(), CompressionID() and Use2ndStart() instead of accessin...
Definition Korg.h:99
Korg::KSFSample::GetPos
unsigned long GetPos() const
Returns the current position in the sample (in sample points).
Definition Korg.cpp:279
RIFF::Chunk
Ordinary RIFF Chunk.
Definition RIFF.h:186
RIFF::Exception
Will be thrown whenever an error occurs while handling a RIFF file.
Definition RIFF.h:397
RIFF::File
RIFF File.
Definition RIFF.h:314
Korg
KORG sound format specific classes and definitions.
Definition Korg.h:74
Korg::libraryVersion
String libraryVersion()
Returns version of this C++ library.
Definition Korg.cpp:460
Korg::libraryName
String libraryName()
Returns the name of this C++ library.
Definition Korg.cpp:452
RIFF::stream_whence_t
stream_whence_t
File stream position dependent to these relations.
Definition RIFF.h:128
gig::buffer_t
Pointer address and size of a buffer.
Definition gig.h:114