mirror of
https://github.com/vale981/openAV-Luppp
synced 2025-03-05 09:01:39 -05:00
-Updated session writing format, now using tracks and clip arrays
This commit is contained in:
parent
78b8a17df0
commit
a30c938c1f
2 changed files with 61 additions and 6 deletions
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include "diskwriter.hxx"
|
||||
|
||||
#include "config.hxx"
|
||||
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
@ -40,6 +42,7 @@ void DiskWriter::writeAudioBuffer(int track, int scene, AudioBuffer* ab )
|
|||
stringstream filename;
|
||||
filename << "t_" << track << "_s_" << scene << ".wav";
|
||||
|
||||
/*
|
||||
// add the track / scene / name combo to session JSON node
|
||||
cJSON* clip = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(session, "clip", clip );
|
||||
|
@ -47,33 +50,70 @@ void DiskWriter::writeAudioBuffer(int track, int scene, AudioBuffer* ab )
|
|||
cJSON_AddNumberToObject(clip,"track", track);
|
||||
cJSON_AddNumberToObject(clip,"scene", scene);
|
||||
cJSON_AddStringToObject(clip,"file", filename.str().c_str());
|
||||
*/
|
||||
|
||||
// store the clip in clipData, we will write the session JSON for it in writeSession
|
||||
clipData.push_back( ClipData( track, scene, filename.str() ) );
|
||||
|
||||
|
||||
// add the AudioBuffer metadata to the sample JSON node
|
||||
cJSON* sampleClip = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(sample, filename.str().c_str(), sampleClip );
|
||||
|
||||
cJSON_AddNumberToObject(sampleClip,"beats", ab->getBeats() );
|
||||
|
||||
// write the AudioBuffer contents to <path>/samples/ as <name>.wav
|
||||
// or alternatively t_<track>_s_<scene>.wav
|
||||
|
||||
stringstream path;
|
||||
path << sessionPath << "/" << sessionName << "/samples/" << filename.str();
|
||||
|
||||
Worker::writeSample( path.str(), ab );
|
||||
|
||||
// de allocate the AudioBuffer here!!
|
||||
// de allocate the AudioBuffer
|
||||
delete ab;
|
||||
}
|
||||
|
||||
void DiskWriter::writeSession( std::string path, std::string sessionName )
|
||||
{
|
||||
// add JSON "tracks" array
|
||||
cJSON* trackArray = cJSON_CreateObject();
|
||||
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 );
|
||||
|
||||
// add track metadata: volumes, sends etc
|
||||
cJSON_AddNumberToObject( track, "ID", t );
|
||||
cJSON_AddNumberToObject( track, "volume", 0.4 );
|
||||
|
||||
// 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
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// write session.luppp JSON node to <path>/<sessionName>.luppp
|
||||
stringstream sessionDir;
|
||||
sessionDir << getenv("HOME") << "/" << sessionName;
|
||||
int sessionDirError = mkdir( sessionDir.str().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH );
|
||||
|
||||
if ( sessionDirError )
|
||||
{
|
||||
// handle by using different filename?
|
||||
|
@ -103,5 +143,6 @@ void DiskWriter::writeSession( std::string path, std::string sessionName )
|
|||
sampleFile << cJSON_Print( sample );
|
||||
sampleFile.close();
|
||||
|
||||
|
||||
// clear the clipData, clean page for next save
|
||||
clipData.clear();
|
||||
}
|
||||
|
|
|
@ -3,11 +3,23 @@
|
|||
#define LUPPP_DISK_WRITER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cjson/cJSON.h"
|
||||
|
||||
class AudioBuffer;
|
||||
|
||||
/// To hold data about loaded clips until we write the JSON out
|
||||
class ClipData
|
||||
{
|
||||
public:
|
||||
ClipData(int tr, int sc, std::string na) :
|
||||
track(tr), scene(sc), name(na) {}
|
||||
int track;
|
||||
int scene;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
/** DiskWriter
|
||||
* This class writes soundfiles to disk, and keeps track of which filename was
|
||||
* in which track/scene combo in the grid. This metadata is then written to the
|
||||
|
@ -32,6 +44,8 @@ class DiskWriter
|
|||
std::string sessionName;
|
||||
std::string sessionPath;
|
||||
|
||||
std::vector<ClipData> clipData;
|
||||
|
||||
};
|
||||
|
||||
#endif // LUPPP_DISK_WRITER_H
|
||||
|
|
Loading…
Add table
Reference in a new issue