diff --git a/src/diskreader.cxx b/src/diskreader.cxx index 62c8d3f..4390e1f 100644 --- a/src/diskreader.cxx +++ b/src/diskreader.cxx @@ -67,40 +67,58 @@ void DiskReader::readSession( std::string path ) - cJSON* clip = cJSON_GetObjectItem( session, "clip"); - if ( clip ) + cJSON* tracks = cJSON_GetObjectItem( session, "tracks"); + if ( tracks ) { - // get metadata for Clip - cJSON* track = cJSON_GetObjectItem( clip, "track"); - cJSON* scene = cJSON_GetObjectItem( clip, "scene"); - cJSON* file = cJSON_GetObjectItem( clip, "file"); - int t = track->valueint; - int s = scene->valueint; - stringstream sampleFilePath; - sampleFilePath << path << "/samples/" << file->valuestring; -#ifdef DEBUG_LOAD - cout << "clip has track " << t << " scene " << s << " file: " << - sampleFilePath.str() << endl; -#endif - - // load it - AudioBuffer* ab = Worker::loadSample( sampleFilePath.str() ); - EventLooperLoad e = EventLooperLoad( t, s, ab ); - writeToDspRingbuffer( &e ); - - cJSON* sampleFile = cJSON_GetObjectItem( sample, file->valuestring ); - if ( sampleFile ) + int nTracks = cJSON_GetArraySize( tracks ); + for(int t = 0; t < nTracks; t++ ) { - cJSON* beats = cJSON_GetObjectItem( sampleFile, "beats" ); + cJSON* track = cJSON_GetArrayItem( tracks, t ); - cout << "Clip @ " << t << " " << s << " gets " << beats->valuedouble << " beats."<< endl; - EventLooperLoopLength e = EventLooperLoopLength( t, s, beats->valueint ); - writeToDspRingbuffer( &e ); - } - else - { - cout << "Wanring: Sample " << file->valuestring << " has no entry for beats." << endl; - } + cJSON* clips = cJSON_GetObjectItem( track, "clips"); + if ( clips ) + { + + int nClips = cJSON_GetArraySize( clips ); + for(int s = 0; s < nClips; s++ ) + { + // get metadata for Clip + cJSON* clip = cJSON_GetArrayItem( clips, s ); + + if ( !strcmp(clip->valuestring, "") == 0 ) + { + stringstream sampleFilePath; + sampleFilePath << path << "/samples/" << clip->valuestring; +#ifdef DEBUG_LOAD + cout << "clip " << sampleFilePath.str() << endl; +#endif + + // load it + AudioBuffer* ab = Worker::loadSample( sampleFilePath.str() ); + EventLooperLoad e = EventLooperLoad( t, s, ab ); + writeToDspRingbuffer( &e ); + + // retrieve sample metadata from sample.cfg using filename as key + cJSON* sampleFile = cJSON_GetObjectItem( sample, clip->valuestring ); + if ( sampleFile ) + { + cJSON* beats = cJSON_GetObjectItem( sampleFile, "beats" ); + + cout << "Clip @ " << t << " " << s << " gets " << beats->valuedouble << " beats."<< endl; + EventLooperLoopLength e = EventLooperLoopLength( t, s, beats->valueint ); + writeToDspRingbuffer( &e ); + } + else { + cout << "Wanring: Sample " << clip->valuestring << " has no entry for beats." << endl; + } + } + + } // nClips loop + + } + + } // nTracks loop + } else { diff --git a/src/diskwriter.cxx b/src/diskwriter.cxx index 59981b0..305060b 100644 --- a/src/diskwriter.cxx +++ b/src/diskwriter.cxx @@ -25,9 +25,6 @@ void DiskWriter::initialize(std::string path, std::string name ) session = cJSON_CreateObject(); sample = cJSON_CreateObject(); - cJSON* lupppSession = cJSON_CreateObject(); - cJSON_AddItemToObject(session, "lupppSession", lupppSession ); - // add session metadata cJSON_AddItemToObject ( session, "session", cJSON_CreateString( sessionName.c_str() )); cJSON_AddNumberToObject( session, "version_major", 1 ); @@ -74,14 +71,14 @@ void DiskWriter::writeAudioBuffer(int track, int scene, AudioBuffer* ab ) void DiskWriter::writeSession( std::string path, std::string sessionName ) { // add JSON "tracks" array - cJSON* trackArray = cJSON_CreateObject(); + cJSON* trackArray = cJSON_CreateArray(); cJSON_AddItemToObject(session, "tracks", trackArray ); // write tracks into JSON tracks array for(int t = 0; t < NTRACKS; t++) { cJSON* track = cJSON_CreateObject(); - cJSON_AddItemToObject( trackArray, "track", track ); + cJSON_AddItemToArray( trackArray, track ); // add track metadata: volumes, sends etc cJSON_AddNumberToObject( track, "ID", t ); @@ -90,16 +87,23 @@ void DiskWriter::writeSession( std::string path, std::string sessionName ) // write clipData vector into clip placeholder cJSON* clips = cJSON_CreateArray(); cJSON_AddItemToObject( track, "clips", clips ); + + + for(int s = 0; s < NSCENES; s++) { - //handle each clip + // add empty string to array + cJSON* clip = cJSON_CreateString( "" ); + cJSON_AddItemToArray( clips, clip ); + + // replace blank string if clip exists for(int i = 0; i < clipData.size(); i++) { if ( clipData.at(i).track == t && clipData.at(i).scene == s ) { - cJSON* clip = cJSON_CreateString( clipData.at(i).name.c_str() ); - cJSON_AddItemToArray( clips, clip ); + cJSON* newClip = cJSON_CreateString( clipData.at(i).name.c_str() ); + cJSON_ReplaceItemInArray( clips, s, newClip ); } } diff --git a/src/gui.cxx b/src/gui.cxx index ce56be3..616d38b 100644 --- a/src/gui.cxx +++ b/src/gui.cxx @@ -91,7 +91,7 @@ static void gui_header_callback(Fl_Widget *w, void *data) } else if ( strcmp(m->label(), "Save ") == 0 ) { - const char* name = fl_input( "Save session as", "lupppSession" ); + const char* name = fl_input( "Save session as", "sessionName" ); if ( name ) { cout << "Save clicked, name = " << name << endl;