diff --git a/src/audiobuffer.cxx b/src/audiobuffer.cxx new file mode 100644 index 0000000..06a99da --- /dev/null +++ b/src/audiobuffer.cxx @@ -0,0 +1,124 @@ +/* + * Author: Harry van Haaren 2013 + * harryhaaren@gmail.com + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 program. If not, see . + */ + +#include "audiobuffer.hxx" + +#include + +AudioBuffer::AudioBuffer() +{ + ID = privateID++; + init(); +} + +AudioBuffer::AudioBuffer(unsigned long size) +{ + // FIXME recorded buffers don't get an ID, using garbage IDs + /// no ID assigned: it *takes* the one from the previous buffer! + init(); + buffer.resize(size); +} + +void AudioBuffer::init() +{ + numBeats = 0; + audioFrames = 0; + memset( name, 0, sizeof(char)*20 ); + //sprintf( name, "%i", ID ); +} + +/// this function is used for "resizing" an exisiting buffer, and should +/// not be called for any other reason. +void AudioBuffer::setID(int id) +{ + ID = id; +} + +int AudioBuffer::getID() +{ + return ID; +} + +void AudioBuffer::setName(const char* n) +{ + memcpy( name, n, sizeof(char)* 19 ); + + if ( strlen(n) > 19 ) + { +#ifdef DEBUG_BUFFER + cout << "AudioBuffer setName too long, truncating." << endl; +#endif + return; + } + +} + +char* AudioBuffer::getName() +{ + return name; +} + +int AudioBuffer::getBeats() +{ + return numBeats; +} + +void AudioBuffer::setBeats(int b) +{ +#ifdef DEBUG_BUFFER + cout << "AudioBuffer now has " << b << " beats\n" << endl; +#endif + numBeats = b; +} + +void AudioBuffer::setAudioFrames(long af) +{ + audioFrames = af; +#ifdef DEBUG_BUFFER + cout << "AudioBuffer " << ID << " has " << audioFrames << " audioFrames\n" << endl; +#endif +} + +long AudioBuffer::getAudioFrames() +{ + return audioFrames; +} + +std::vector& AudioBuffer::getData() +{ + return buffer; +} + +void AudioBuffer::nonRtSetSample(std::vector& sample) +{ + buffer.swap(sample); +} +void AudioBuffer::nonRtResize(unsigned long size) +{ + buffer.resize(size); +} + +/* +ostream& AudioBuffer::operator<<(ostream& o, const AudioBuffer& a) +{ + o << "AudioBuffer " << a.name << + " beats: " << a.numBeats << + " audioFrames: " << a.audioFrames << endl; + return o; +} +*/ diff --git a/src/audiobuffer.hxx b/src/audiobuffer.hxx index ae729f6..2db923e 100644 --- a/src/audiobuffer.hxx +++ b/src/audiobuffer.hxx @@ -31,104 +31,34 @@ using namespace std; class AudioBuffer { public: - AudioBuffer() - { - ID = privateID++; - init(); - } - AudioBuffer(unsigned long size) - { - // FIXME recorded buffers don't get an ID, using garbage IDs - /// no ID assigned: it *takes* the one from the previous buffer! - init(); - buffer.resize(size); - } + AudioBuffer(); + AudioBuffer(unsigned long size); - void init() - { - numBeats = 0; - audioFrames = 0; - memset( name, 0, sizeof(char)*20 ); - //sprintf( name, "%i", ID ); - } + void init(); /// this function is used for "resizing" an exisiting buffer, and should /// not be called for any other reason. - void setID(int id) - { - ID = id; - } + void setID(int id); - int getID() - { - return ID; - } + int getID(); + void setName(const char* n); - void setName(const char* n) - { - if ( strlen(n) > 19 ) - { -#ifdef DEBUG_BUFFER - cout << "AudioBuffer setName too long!" << endl; -#endif - return; - } - - memcpy( name, n, sizeof(char)* 20 ); - } + char* getName(); + int getBeats(); - char* getName() - { - return name; - } + void setBeats(int b); - int getBeats() - { - return numBeats; - } + void setAudioFrames(long af); - void setBeats(int b) - { -#ifdef DEBUG_BUFFER - cout << "AudioBuffer now has " << b << " beats\n" << endl; -#endif - numBeats = b; - } + long getAudioFrames(); - void setAudioFrames(long af) - { - audioFrames = af; -#ifdef DEBUG_BUFFER - cout << "AudioBuffer " << ID << " has " << audioFrames << " audioFrames\n" << endl; -#endif - } + std::vector& getData(); - long getAudioFrames() - { - return audioFrames; - } + void nonRtSetSample(std::vector& sample); - std::vector& getData() - { - return buffer; - } + void nonRtResize(unsigned long size); - void nonRtSetSample(std::vector& sample) - { - buffer.swap(sample); - } - void nonRtResize(unsigned long size) - { - buffer.resize(size); - } - - friend ostream& operator<<(ostream& o, const AudioBuffer& a) - { - o << "AudioBuffer " << a.name << - " beats: " << a.numBeats << - " audioFrames: " << a.audioFrames << endl; - return o; - } + //friend ostream& operator<<(ostream& o, const AudioBuffer& a); protected: static int privateID; diff --git a/src/diskreader.cxx b/src/diskreader.cxx index 2066d90..ba09ab6 100644 --- a/src/diskreader.cxx +++ b/src/diskreader.cxx @@ -222,6 +222,12 @@ int DiskReader::loadSample( int track, int scene, string path ) bool loadableBuffer = false; + // retrieve sample metadata from sample.cfg using filename as key + char* tmp = strdup( path.c_str() ); + char* baseName = basename( tmp ); + //cout << "tmp " << tmp << " baseName " << baseName << endl; + ab->setName( baseName ); + if ( infile.frames() > 0 ) { char* basePath = strdup( path.c_str() ); @@ -252,11 +258,6 @@ int DiskReader::loadSample( int track, int scene, string path ) return LUPPP_RETURN_ERROR; } - // retrieve sample metadata from sample.cfg using filename as key - char* tmp = strdup( path.c_str() ); - char* baseName = basename( tmp ); - //cout << "tmp " << tmp << " baseName " << baseName << endl; - cJSON* sample = cJSON_GetObjectItem( audioJson, baseName ); if ( sample ) { @@ -268,6 +269,7 @@ int DiskReader::loadSample( int track, int scene, string path ) loadableBuffer = true; ab->setBeats( beats->valuedouble ); } + if ( name ) { ab->setName( name->valuestring ); @@ -277,8 +279,9 @@ int DiskReader::loadSample( int track, int scene, string path ) // if we don't find the beats from audio.cfg, show dialog if ( loadableBuffer == false ) { - cout << "Warning: audio.cfg has no entry for beats." << endl; + LUPPP_NOTE("Warning: audio.cfg has no entry for beats."); int ret = showAudioEditor( ab ); + if ( ret == LUPPP_RETURN_OK ) { // flag that we can load this sample OK @@ -307,15 +310,13 @@ int DiskReader::loadSample( int track, int scene, string path ) } else { - LUPPP_NOTE("AudioBuffer set %i beats.", ab->getBeats() ); - - std::string name = path; int i = name.find_last_of('/') + 1; std::string sub = name.substr( i ); - ab->setName( sub.c_str() ); + LUPPP_NOTE("AudioBuffer %s set %i beats", ab->getName(), ab->getBeats() ); + loadableBuffer = true; } } diff --git a/src/gaudioeditor.cxx b/src/gaudioeditor.cxx index 6a33a88..eccb0c0 100644 --- a/src/gaudioeditor.cxx +++ b/src/gaudioeditor.cxx @@ -112,7 +112,7 @@ void AudioEditor::show( AudioBuffer* buf, bool modal ) } else { - printf("%i, fpb = %i, bpm= = %i\n", beat, fpb, bpm ); + //printf("%i, fpb = %i, bpm= = %i\n", beat, fpb, bpm ); // enable option ( may be disabled previously! ) beatButtons[i]->setGreyOut( false );