-DiskReader now reads sample.cfg file, gets beats, and sets it on the AudioBuffer. DiskWriter writes clips using filename instead of "clip", easier to retrieve.
parent
0440798324
commit
d4ec2fee03
|
@ -19,7 +19,7 @@ DiskReader::DiskReader()
|
||||||
// TODO : get from user input
|
// TODO : get from user input
|
||||||
|
|
||||||
stringstream s;
|
stringstream s;
|
||||||
s << getenv("HOME") << "/" << "sessionName" << "/";
|
s << getenv("HOME") << "/" << "sessionName";
|
||||||
readSession( s.str() );
|
readSession( s.str() );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -28,36 +28,48 @@ void DiskReader::readSession( std::string path )
|
||||||
cout << "DiskReader::readSession() " << path << endl;
|
cout << "DiskReader::readSession() " << path << endl;
|
||||||
sessionPath = path;
|
sessionPath = path;
|
||||||
|
|
||||||
char *sampleChar;
|
|
||||||
std::string sessionString;
|
|
||||||
|
|
||||||
|
|
||||||
stringstream s;
|
stringstream s;
|
||||||
s << path << "session.luppp";
|
s << path << "/session.luppp";
|
||||||
|
|
||||||
cout << "session path " << s.str().c_str() << endl;
|
stringstream samplePath;
|
||||||
|
samplePath << path << "/samples/sample.cfg";
|
||||||
|
|
||||||
|
cout << "session path: " << s.str() << endl;
|
||||||
|
cout << "sample path: " << samplePath.str() << endl;
|
||||||
|
|
||||||
// open file, store entire contents into string
|
// open session, read all
|
||||||
std::ifstream file( s.str().c_str(), std::ios_base::in|std::ios_base::ate);
|
std::ifstream file( s.str().c_str(), std::ios_base::in|std::ios_base::ate);
|
||||||
long file_length = file.tellg();
|
long file_length = file.tellg();
|
||||||
file.seekg(0, std::ios_base::beg);
|
file.seekg(0, std::ios_base::beg);
|
||||||
file.clear();
|
file.clear();
|
||||||
char *string = new char[file_length];
|
char *sessionString = new char[file_length];
|
||||||
file.read(string, file_length);
|
file.read(sessionString, file_length);
|
||||||
|
|
||||||
cout << "sessionFile string:\n " << string << endl;
|
// open sample, read all
|
||||||
|
std::ifstream sampleFile( samplePath.str().c_str(), std::ios_base::in|std::ios_base::ate);
|
||||||
|
file_length = sampleFile.tellg();
|
||||||
|
sampleFile.seekg(0, std::ios_base::beg);
|
||||||
|
sampleFile.clear();
|
||||||
|
char *sampleString = new char[file_length];
|
||||||
|
sampleFile.read(sampleString, file_length);
|
||||||
|
|
||||||
|
//cout << "sessionFile string:\n " << sessionString << endl;
|
||||||
|
//cout << "sampleFile string: \n " << sampleString << endl;
|
||||||
|
|
||||||
|
|
||||||
session = cJSON_Parse( string );
|
// create cJSON nodes from strings
|
||||||
|
session = cJSON_Parse( sessionString );
|
||||||
if (!session)
|
if (!session) {
|
||||||
{
|
printf("Error in Session JSON before: [%s]\n",cJSON_GetErrorPtr());
|
||||||
printf("Error before: [%s]\n",cJSON_GetErrorPtr());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
sample = cJSON_Parse( sampleString );
|
||||||
|
if (!sample) {
|
||||||
|
printf("Error in Sample JSON before: [%s]\n",cJSON_GetErrorPtr());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//cout << "readSample: " << cJSON_Print( sample ) << endl;
|
||||||
|
|
||||||
//cout << "readSession: " << cJSON_Print( session ) << endl;
|
|
||||||
|
|
||||||
|
|
||||||
cJSON* clip = cJSON_GetObjectItem( session, "clip");
|
cJSON* clip = cJSON_GetObjectItem( session, "clip");
|
||||||
|
@ -76,40 +88,35 @@ void DiskReader::readSession( std::string path )
|
||||||
sampleFilePath.str() << endl;
|
sampleFilePath.str() << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// load it
|
// load it
|
||||||
AudioBuffer* ab = Worker::loadSample( sampleFilePath.str() );
|
AudioBuffer* ab = Worker::loadSample( sampleFilePath.str() );
|
||||||
EventLooperLoad e = EventLooperLoad( t, s, ab );
|
EventLooperLoad e = EventLooperLoad( t, s, ab );
|
||||||
writeToDspRingbuffer( &e );
|
writeToDspRingbuffer( &e );
|
||||||
|
|
||||||
|
cJSON* sampleFile = cJSON_GetObjectItem( sample, file->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 " << file->valuestring << " has no entry for beats." << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cout << "DiskReader: Error getting clip" << endl;
|
cout << "DiskReader: Error getting clip" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cleanup
|
||||||
|
|
||||||
/*
|
|
||||||
for( int i = 0; i < cJSON_GetArraySize( session ); i++ )
|
|
||||||
{
|
|
||||||
cJSON* subitem = cJSON_GetArrayItem( session, i);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
name = cJSON_GetObjectItem(subitem, "name");
|
|
||||||
index = cJSON_GetObjectItem(subitem, "index");
|
|
||||||
optional = cJSON_GetObjectItem(subitem, "optional");
|
|
||||||
|
|
||||||
cout << "i = " << i << " session: " << subitem->valueint << endl;
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cJSON_Delete( session );
|
cJSON_Delete( session );
|
||||||
|
cJSON_Delete( sample );
|
||||||
|
|
||||||
|
free ( sessionString );
|
||||||
free ( string );
|
free ( sampleString );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,9 +52,8 @@ void DiskWriter::writeAudioBuffer(int track, int scene, AudioBuffer* ab )
|
||||||
|
|
||||||
// add the AudioBuffer metadata to the sample JSON node
|
// add the AudioBuffer metadata to the sample JSON node
|
||||||
cJSON* sampleClip = cJSON_CreateObject();
|
cJSON* sampleClip = cJSON_CreateObject();
|
||||||
cJSON_AddItemToObject(sample, "sample", sampleClip );
|
cJSON_AddItemToObject(sample, filename.str().c_str(), sampleClip );
|
||||||
|
|
||||||
cJSON_AddStringToObject(sampleClip,"file", filename.str().c_str() );
|
|
||||||
cJSON_AddNumberToObject(sampleClip,"beats", ab->getBeats() );
|
cJSON_AddNumberToObject(sampleClip,"beats", ab->getBeats() );
|
||||||
|
|
||||||
// write the AudioBuffer contents to <path>/samples/ as <name>.wav
|
// write the AudioBuffer contents to <path>/samples/ as <name>.wav
|
||||||
|
|
Loading…
Reference in New Issue