mirror of
https://github.com/vale981/openAV-Luppp
synced 2025-03-05 09:01:39 -05:00
-Implemented DiskReader and file loading.
This commit is contained in:
parent
8493a85cb9
commit
0440798324
6 changed files with 166 additions and 2 deletions
|
@ -18,6 +18,9 @@
|
|||
// Saving state
|
||||
#define DEBUG_SAVE 1
|
||||
|
||||
// Loading state
|
||||
#define DEBUG_LOAD 1
|
||||
|
||||
/// General Options
|
||||
#define NTRACKS 8
|
||||
#define NSCENES 10
|
||||
|
|
115
src/diskreader.cxx
Normal file
115
src/diskreader.cxx
Normal file
|
@ -0,0 +1,115 @@
|
|||
|
||||
#include "diskreader.hxx"
|
||||
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "event.hxx"
|
||||
#include "eventhandler.hxx"
|
||||
#include "worker.hxx"
|
||||
|
||||
using namespace std;
|
||||
|
||||
DiskReader::DiskReader()
|
||||
{
|
||||
// TODO : get from user input
|
||||
|
||||
stringstream s;
|
||||
s << getenv("HOME") << "/" << "sessionName" << "/";
|
||||
readSession( s.str() );
|
||||
};
|
||||
|
||||
void DiskReader::readSession( std::string path )
|
||||
{
|
||||
cout << "DiskReader::readSession() " << path << endl;
|
||||
sessionPath = path;
|
||||
|
||||
char *sampleChar;
|
||||
std::string sessionString;
|
||||
|
||||
|
||||
stringstream s;
|
||||
s << path << "session.luppp";
|
||||
|
||||
cout << "session path " << s.str().c_str() << endl;
|
||||
|
||||
|
||||
// open file, store entire contents into string
|
||||
std::ifstream file( s.str().c_str(), std::ios_base::in|std::ios_base::ate);
|
||||
long file_length = file.tellg();
|
||||
file.seekg(0, std::ios_base::beg);
|
||||
file.clear();
|
||||
char *string = new char[file_length];
|
||||
file.read(string, file_length);
|
||||
|
||||
cout << "sessionFile string:\n " << string << endl;
|
||||
|
||||
|
||||
session = cJSON_Parse( string );
|
||||
|
||||
if (!session)
|
||||
{
|
||||
printf("Error before: [%s]\n",cJSON_GetErrorPtr());
|
||||
return;
|
||||
}
|
||||
|
||||
//cout << "readSession: " << cJSON_Print( session ) << endl;
|
||||
|
||||
|
||||
cJSON* clip = cJSON_GetObjectItem( session, "clip");
|
||||
if ( clip )
|
||||
{
|
||||
// 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 );
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "DiskReader: Error getting clip" << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
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 );
|
||||
|
||||
|
||||
free ( string );
|
||||
|
||||
}
|
38
src/diskreader.hxx
Normal file
38
src/diskreader.hxx
Normal file
|
@ -0,0 +1,38 @@
|
|||
|
||||
#ifndef LUPPP_DISK_READER_H
|
||||
#define LUPPP_DISK_READER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "cjson/cJSON.h"
|
||||
|
||||
class AudioBuffer;
|
||||
|
||||
/** DiskReader
|
||||
* This class reads a previously saved session from disk, restoring Luppp's
|
||||
* internal state to that of when the save took place.
|
||||
*
|
||||
* The directory <sessionDir> is the main point of loading. The user selects
|
||||
* that directory to load the session from. <sessionDir>.luppp is the name of
|
||||
* the session file: it contains all info about the session: Volumes, loaded
|
||||
* samples etc.
|
||||
*
|
||||
* Samples are read from the directory <sessionDir>/samples, in which there is a
|
||||
* sample.cfg file, which can be parsed to get sample metadata.
|
||||
**/
|
||||
class DiskReader
|
||||
{
|
||||
public:
|
||||
DiskReader();
|
||||
|
||||
void readSession( std::string path );
|
||||
|
||||
private:
|
||||
cJSON* session;
|
||||
cJSON* sample;
|
||||
|
||||
std::string sessionName;
|
||||
std::string sessionPath;
|
||||
};
|
||||
|
||||
#endif // LUPPP_DISK_READER_H
|
|
@ -24,6 +24,9 @@ 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 );
|
||||
|
@ -85,7 +88,7 @@ void DiskWriter::writeSession( std::string path, std::string sessionName )
|
|||
int sampleDirError = mkdir( sampleDir.str().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH );
|
||||
|
||||
stringstream sessionLuppp;
|
||||
sessionLuppp << sessionDir.str() << "/" << sessionName << ".luppp";
|
||||
sessionLuppp << sessionDir.str() << "/session.luppp";
|
||||
|
||||
//cout << "Session dir: " << sessionDir.str() << "\n" << "Sample dir : " << sampleDir.str() << endl;
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ static void gui_static_read_rb(void* inst)
|
|||
|
||||
Gui::Gui() :
|
||||
window(1110,650),
|
||||
diskReader( new DiskReader ),
|
||||
diskWriter( new DiskWriter )
|
||||
{
|
||||
window.color(FL_BLACK);
|
||||
|
|
|
@ -9,9 +9,11 @@
|
|||
#include "config.hxx"
|
||||
#include "gtrack.hxx"
|
||||
#include "gunittrack.hxx"
|
||||
#include "diskwriter.hxx"
|
||||
#include "gmastertrack.hxx"
|
||||
|
||||
#include "diskwriter.hxx"
|
||||
#include "diskreader.hxx"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
|
@ -26,6 +28,7 @@ class Gui
|
|||
GMasterTrack* getMasterTrack(){return master;}
|
||||
|
||||
DiskWriter* getDiskWriter(){return diskWriter;}
|
||||
DiskReader* getDiskReader(){return diskReader;}
|
||||
|
||||
// for pushing strings to tooltip area
|
||||
void setTooltip( std::string s );
|
||||
|
@ -34,6 +37,7 @@ class Gui
|
|||
Fl_Double_Window window;
|
||||
Fl_Box* box;
|
||||
|
||||
DiskReader* diskReader;
|
||||
DiskWriter* diskWriter;
|
||||
|
||||
GMasterTrack* master;
|
||||
|
|
Loading…
Add table
Reference in a new issue