diff --git a/src/audiobuffer.cxx b/src/audiobuffer.cxx index c7612df..13cb689 100644 --- a/src/audiobuffer.cxx +++ b/src/audiobuffer.cxx @@ -40,8 +40,6 @@ 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 @@ -56,20 +54,18 @@ int AudioBuffer::getID() return ID; } -void AudioBuffer::setName(const char* n) +void AudioBuffer::setName(const std::string& n) { - memcpy( name, n, sizeof(char)* 19 ); - - if ( strlen(n) > 19 ) { + name = n; + if (n.size() > 20) { #ifdef DEBUG_BUFFER cout << "AudioBuffer setName too long, truncating." << endl; #endif - return; + name.resize(20); } - } -char* AudioBuffer::getName() +const std::string& AudioBuffer::getName() const { return name; } diff --git a/src/audiobuffer.hxx b/src/audiobuffer.hxx index 0c9e4d4..08511ba 100644 --- a/src/audiobuffer.hxx +++ b/src/audiobuffer.hxx @@ -41,9 +41,9 @@ public: void setID(int id); int getID(); - void setName(const char* n); + void setName(const std::string& n); - char* getName(); + const std::string& getName() const; int getBeats(); void setBeats(int b); @@ -73,7 +73,7 @@ protected: /// buffer.size(), which also has non-used space at the end. long audioFrames; - char name[20]; + std::string name; std::vector bufferL; std::vector bufferR; diff --git a/src/diskreader.cxx b/src/diskreader.cxx index be8d488..6796587 100644 --- a/src/diskreader.cxx +++ b/src/diskreader.cxx @@ -262,8 +262,9 @@ 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 ); + //char* tmp = strdup( path.c_str() ); + std::string baseName = path.substr(path.find_last_of("/\\") + 1); + //char* baseName = basename( tmp ); //cout << "tmp " << tmp << " baseName " << baseName << endl; ab->setName( baseName ); @@ -295,7 +296,7 @@ int DiskReader::loadSample( int track, int scene, string path ) return LUPPP_RETURN_ERROR; } - cJSON* sample = cJSON_GetObjectItem( audioJson, baseName ); + cJSON* sample = cJSON_GetObjectItem( audioJson, baseName.c_str() ); if ( sample ) { cJSON* beats = cJSON_GetObjectItem( sample, "beats" ); cJSON* name = cJSON_GetObjectItem( sample, "name" ); @@ -325,7 +326,6 @@ int DiskReader::loadSample( int track, int scene, string path ) cJSON_Delete( audioJson ); delete[] sampleString; - free ( tmp ); } else { // this means there's no audio.cfg file found for the sample: show the user // the file, and ask what the intended beat number is, and load the AudioBuffer @@ -340,7 +340,7 @@ int DiskReader::loadSample( int track, int scene, string path ) std::string sub = name.substr( i ); ab->setName( sub.c_str() ); - LUPPP_NOTE("AudioBuffer %s set %i beats", ab->getName(), ab->getBeats() ); + LUPPP_NOTE("AudioBuffer %s set %i beats", ab->getName().c_str(), ab->getBeats() ); loadableBuffer = true; }