mirror of
https://github.com/vale981/openAV-Luppp
synced 2025-03-05 09:01:39 -05:00
-File writing / reading now working for multiple clips, including beat durations
This commit is contained in:
parent
a30c938c1f
commit
d00b3877bc
3 changed files with 62 additions and 40 deletions
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue