AudioFileReaderInternal::AudioFileReaderInternal (AudioFileReader const& original, AudioFileRegion const& region, const int bufferSize) throw() : readBuffer (Chars::withSize ((bufferSize > 0) ? bufferSize : AudioFile::DefaultBufferSize)), numFramesPerBuffer (0), newPositionOnNextRead (-1), hitEndOfFile (false), numChannelsChanged (false), audioFileChanged (false), defaultNumChannels (0) { pl_AudioFileReader_Init (getPeerRef()); AudioFileReaderRegion* readerRegion = new AudioFileReaderRegion (original, region); // setName (original.getName() + "#" + region.getLabel()); if (pl_AudioFileReader_OpenWithCustomNextFunction (getPeerRef(), AudioFileReaderInternal_Region_NextFunction, AudioFileReaderInternal_Region_FreeFunction, AudioFileReaderInternal_Region_SetFramePosition, AudioFileReaderInternal_Region_GetFramePosition, readerRegion) == PlankResult_OK) { if (getBytesPerFrame() > 0) numFramesPerBuffer = readBuffer.length() / getBytesPerFrame(); } }
AudioFileReaderInternal::AudioFileReaderInternal (AudioFileReaderArray const& audioFiles, const AudioFile::MultiFileTypes multiMode, const int bufferSize, IntVariable* indexRef) throw() : readBuffer (Chars::withSize ((bufferSize > 0) ? bufferSize : AudioFile::DefaultBufferSize)), numFramesPerBuffer (0), newPositionOnNextRead (-1), hitEndOfFile (false), numChannelsChanged (false), audioFileChanged (false), defaultNumChannels (0) { pl_AudioFileReader_Init (getPeerRef()); PlankDynamicArrayRef array = pl_DynamicArray_Create(); pl_DynamicArray_InitWithItemSizeAndSize (array, sizeof (PlankAudioFileReader), audioFiles.length(), true); PlankAudioFileReader* rawArray = static_cast<PlankAudioFileReader*> (pl_DynamicArray_GetArray (array)); for (int i = 0; i < audioFiles.length(); ++i) { AudioFileReader reader = audioFiles.atUnchecked (i); reader.disownPeer (&rawArray[i]); } if (indexRef) nextMultiIndexRef = *indexRef; ResultCode result = pl_AudioFileReader_OpenWithAudioFileArray (getPeerRef(), array, true, multiMode, nextMultiIndexRef.getValuePtr()); if (result == PlankResult_OK) { if (getBytesPerFrame() > 0) numFramesPerBuffer = readBuffer.length() / getBytesPerFrame(); } }
AudioFile::Encoding AudioFileReaderInternal::getEncoding() const throw() { int value; ResultCode result = pl_AudioFileReader_GetEncoding (getPeerRef(), &value); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif const int format = value; switch (format) { case AudioFile::EncodingInvalid: return AudioFile::EncodingInvalid; case AudioFile::EncodingUnknown: return AudioFile::EncodingUnknown; case AudioFile::EncodingPCMLittleEndian: return AudioFile::EncodingPCMLittleEndian; case AudioFile::EncodingPCMBigEndian: return AudioFile::EncodingPCMBigEndian; case AudioFile::EncodingFloatLittleEndian: return AudioFile::EncodingFloatLittleEndian; case AudioFile::EncodingFloatBigEndian: return AudioFile::EncodingFloatBigEndian; case AudioFile::EncodingPCMLittleEndianNonInterleaved: return AudioFile::EncodingPCMLittleEndianNonInterleaved; case AudioFile::EncodingPCMBigEndianNonInterleaved: return AudioFile::EncodingPCMBigEndianNonInterleaved; case AudioFile::EncodingFloatLittleEndianNonInterleaved: return AudioFile::EncodingFloatLittleEndianNonInterleaved; case AudioFile::EncodingFloatBigEndianNonInterleaved: return AudioFile::EncodingFloatBigEndianNonInterleaved; default: return AudioFile::EncodingInvalid; } }
AudioFile::Format AudioFileReaderInternal::getFormat() const throw() { int value; ResultCode result = pl_AudioFileReader_GetFormat (getPeerRef(), &value); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif const int format = value; switch (format) { case AudioFile::FormatInvalid: return AudioFile::FormatInvalid; case AudioFile::FormatUnknown: return AudioFile::FormatUnknown; case AudioFile::FormatWAV: return AudioFile::FormatWAV; case AudioFile::FormatAIFF: return AudioFile::FormatAIFF; case AudioFile::FormatAIFC: return AudioFile::FormatAIFC; case AudioFile::FormatOggVorbis: return AudioFile::FormatOggVorbis; case AudioFile::FormatOpus: return AudioFile::FormatOpus; case AudioFile::FormatRegion: return AudioFile::FormatRegion; case AudioFile::FormatMulti: return AudioFile::FormatMulti; case AudioFile::FormatArray: return AudioFile::FormatArray; case AudioFile::FormatQueue: return AudioFile::FormatQueue; case AudioFile::FormatCustom: return AudioFile::FormatCustom; default: return AudioFile::FormatInvalid; } }
BEGIN_PLONK_NAMESPACE #include "../core/plonk_Headers.h" TextFileInternal::TextFileInternal() throw() { pl_File_Init (getPeerRef()); }
void AudioFileReaderInternal::resetFramePosition() throw() { ResultCode result = pl_AudioFileReader_ResetFramePosition (getPeerRef()); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif }
void BinaryFileInternal::write (const double value) throw() { const ResultCode result = pl_File_WriteD (getPeerRef(), value); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif }
void BinaryFileInternal::setEof() throw() { const ResultCode result = pl_File_SetEOF (getPeerRef()); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif }
void TextFileInternal::writeLine (const char* text) throw() { const ResultCode result = pl_File_WriteLine (getPeerRef(), text); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif }
void BinaryFileInternal::setPosition(const LongLong position) throw() { const ResultCode result = pl_File_SetPosition (getPeerRef(), position); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif }
void BinaryFileInternal::write (void* data, const int maximumBytes) throw() { const ResultCode result = pl_File_Write (getPeerRef(), data, maximumBytes); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif }
void BinaryFileInternal::read (double& value) throw() { const ResultCode result = pl_File_ReadD (getPeerRef(), &value); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif }
void BinaryFileInternal::read (Int24& value) throw() { const ResultCode result = pl_File_ReadI24 (getPeerRef(), reinterpret_cast<Int24::Internal*> (&value) ); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif }
ResultCode AudioFileReaderInternal::init (const char* path, AudioFileMetaDataIOFlags const& metaDataIOFlags) throw() { plonk_assert (path != 0); pl_AudioFileReader_Init (getPeerRef()); ResultCode result = pl_AudioFileReader_OpenInternal (getPeerRef(), path, metaDataIOFlags.getValue()); const int bytesPerFrame = getBytesPerFrame(); if (bytesPerFrame == 0) result = PlankResult_AudioFileInavlidType; else if (result == PlankResult_OK) numFramesPerBuffer = readBuffer.length() / getBytesPerFrame(); if (this->hasMetaData()) this->getMetaData().sortCuePointsByPosition(); return result; }
int AudioFileReaderInternal::getNumChannels() const throw() { int value; ResultCode result = pl_AudioFileReader_GetNumChannels (getPeerRef(), &value); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif return value; }
LongLong AudioFileReaderInternal::getFramePosition() const throw() { LongLong value; ResultCode result = pl_AudioFileReader_GetFramePosition (getPeerRef(), &value); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif return value; }
double AudioFileReaderInternal::getSampleRate() const throw() { double value; ResultCode result = pl_AudioFileReader_GetSampleRate (getPeerRef(), &value); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif return value; }
ResultCode AudioFileReaderInternal::init (ByteArray const& bytes, AudioFileMetaDataIOFlags const& metaDataIOFlags) throw() { pl_AudioFileReader_Init (getPeerRef()); PlankFile file; if (BinaryFileInternal::setupBytes (&file, bytes, false)) { if (pl_AudioFileReader_OpenWithFile (getPeerRef(), &file, metaDataIOFlags.getValue()) == PlankResult_OK) { numFramesPerBuffer = readBuffer.length() / getBytesPerFrame(); if (this->hasMetaData()) this->getMetaData().sortCuePointsByPosition(); return PlankResult_OK; } } return PlankResult_UnknownError; }
int BinaryFileInternal::read (void* data, const int maximumBytes) throw() { int bytesRead; const ResultCode result = pl_File_Read (getPeerRef(), data, maximumBytes, &bytesRead); plonk_assert (result == PlankResult_OK || result == PlankResult_FileEOF); #ifndef PLONK_DEBUG (void)result; #endif return bytesRead; }
LongLong BinaryFileInternal::getPosition() const throw() { LongLong position; const ResultCode result = pl_File_GetPosition (getPeerRef(), &position); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif return position; }
TextFileInternal::TextFileInternal (Text const& path, const bool writable, const bool clearContents) throw() { pl_File_Init (getPeerRef()); plonk_assert ((writable == true) || (clearContents == false)); ResultCode result; if (clearContents) pl_FileErase (path.getArray()); result = writable ? pl_File_OpenTextWrite (getPeerRef(), path.getArray(), true, clearContents) : pl_File_OpenTextRead (getPeerRef(), path.getArray(), false); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif }
AudioFileReaderInternal::AudioFileReaderInternal (AudioFileReaderQueue const& audioFiles, const int bufferSize) throw() : readBuffer (Chars::withSize ((bufferSize > 0) ? bufferSize : AudioFile::DefaultBufferSize)), numFramesPerBuffer (0), newPositionOnNextRead (-1), hitEndOfFile (false), numChannelsChanged (false), audioFileChanged (false), defaultNumChannels (0) { pl_AudioFileReader_Init (getPeerRef()); if (pl_AudioFileReader_OpenWithCustomNextFunction (getPeerRef(), AudioFileReaderInternal_Queue_NextFunction, AudioFileReaderInternal_Queue_FreeFunction, AudioFileReaderInternal_Queue_SetFramePosition, //0, AudioFileReaderInternal_Queue_GetFramePosition, //0, new AudioFileReaderQueue (audioFiles)) == PlankResult_OK) { if (getBytesPerFrame() > 0) numFramesPerBuffer = readBuffer.length() / getBytesPerFrame(); } }
AudioFileReaderInternal::AudioFileReaderInternal (FilePathQueue const& fileQueue, const int bufferSize) throw() : readBuffer (Chars::withSize ((bufferSize > 0) ? bufferSize : AudioFile::DefaultBufferSize)), numFramesPerBuffer (0), newPositionOnNextRead (-1), hitEndOfFile (false), numChannelsChanged (false), audioFileChanged (false), defaultNumChannels (0) { pl_AudioFileReader_Init (getPeerRef()); PlankFile file; if (BinaryFileInternal::setupMulti (&file, fileQueue, PLANK_BIGENDIAN)) { if (pl_AudioFileReader_OpenWithFile (getPeerRef(), &file, AudioFile::MetaDataIOFlagsNone) == PlankResult_OK) { if (getBytesPerFrame() > 0) numFramesPerBuffer = readBuffer.length() / getBytesPerFrame(); } } }
Threading::Thread::Thread (const char* name) throw() { ResultCode result; result = pl_Thread_Init (getPeerRef()); plonk_assert (result == PlankResult_OK); if (name != 0) { result = pl_Thread_SetName (getPeerRef(), name); plonk_assert (result == PlankResult_OK); } result = pl_Thread_SetFunction (getPeerRef(), Threading::run); plonk_assert (result == PlankResult_OK); result = pl_Thread_SetUserData (getPeerRef(), this); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif }
Text TextFileInternal::readLine (const int maximumLength) throw() { Text buffer (Text::withSize (maximumLength)); const ResultCode result = pl_File_ReadLine (getPeerRef(), buffer, maximumLength); plonk_assert ((result == PlankResult_OK) || (result == PlankResult_FileEOF)); #ifndef PLONK_DEBUG (void)result; #endif return buffer.getArray(); // copies, reducing size }
BEGIN_PLONK_NAMESPACE #include "../../core/plonk_Headers.h" AudioFileReaderInternal::AudioFileReaderInternal() throw() : numFramesPerBuffer (0), newPositionOnNextRead (-1), hitEndOfFile (false), numChannelsChanged (false), audioFileChanged (false), defaultNumChannels (0) { pl_AudioFileReader_Init (getPeerRef()); }
TextFileInternal::TextFileInternal (TextFileQueue const& fileQueue) throw() { pl_File_Init (getPeerRef()); const bool shouldTakeOwnership = true; ResultCode result; PlankMulitFileReaderRef multi = pl_MultiFileReader_Create(); result = pl_MultiFileReader_InitCustom (multi, PLANKFILE_READ, new TextFileQueue (fileQueue), shouldTakeOwnership, plonk_TextFileInternal_TextFileQueue_NextFuntion, plonk_TextFileInternal_TextFileQueue_DestroyCustomFuntion); plonk_assert (result == PlankResult_OK); result = pl_File_OpenMulti (getPeerRef(), multi, PLANKFILE_READ); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif }
Text TextFileInternal::readAll() throw() { Text buffer (Text::emptyWithAllocatedSize (512)); ResultCode result = PlankResult_OK; int bytesRead; char temp[17]; while (result == PlankResult_OK) { result = pl_File_Read (getPeerRef(), temp, 16, &bytesRead); temp[bytesRead] = '\0'; buffer.add (temp); } return buffer; }
Text TextFileInternal::read (const int numBytes) throw() { Text buffer (Text::emptyWithAllocatedSize (numBytes)); ResultCode result = PlankResult_OK; int bytesRead, bytesRemaining, bytesThisTime; char temp[17]; bytesRemaining = numBytes; while ((result == PlankResult_OK) && (bytesRemaining > 0)) { bytesThisTime = plonk::min (bytesRemaining, 16); result = pl_File_Read (getPeerRef(), temp, bytesThisTime, &bytesRead); temp[bytesRead] = '\0'; buffer.add (temp); bytesRemaining -= bytesRead; } return buffer; }
ResultCode BinaryFileInternal::copy (BinaryFileInternal* source, const LongLong size) throw() { const ResultCode result = pl_File_Copy (getPeerRef(), source->getPeerRef(), size); plonk_assert (result == PlankResult_OK); return result; }