From a3020cf1e2417f15cc95d175f2b8c8b0c7140077 Mon Sep 17 00:00:00 2001 From: Harry van Haaren Date: Tue, 17 Sep 2013 12:07:25 +0100 Subject: [PATCH] -Updated testing, debugging and error code --- run.sh | 2 +- src/diskwriter.cxx | 39 +++++++++--------------------------- src/eventhandlergui.cxx | 2 ++ src/gui.cxx | 8 ++++---- src/looperclip.cxx | 6 +++--- src/main.cxx | 19 ++++++++---------- src/tests/diskwritertest.cxx | 10 ++++++--- test.sh | 10 ++++++--- 8 files changed, 41 insertions(+), 55 deletions(-) diff --git a/run.sh b/run.sh index 46d29fd..4a9ebc6 100755 --- a/run.sh +++ b/run.sh @@ -1,4 +1,4 @@ #!/bin/bash set -e -xterm -e "sleep 1 && aj-snapshot -r .ajsnapshot" & bin/luppp +make && xterm -e "sleep 1 && aj-snapshot -r .ajsnapshot" & bin/luppp diff --git a/src/diskwriter.cxx b/src/diskwriter.cxx index 5017ab6..fb1e3b9 100644 --- a/src/diskwriter.cxx +++ b/src/diskwriter.cxx @@ -24,8 +24,8 @@ DiskWriter::DiskWriter() void DiskWriter::initialize(std::string path, std::string name ) { - sessionPath = path; - sessionName = name; + sessionPath = getenv("HOME"); + sessionName = "lupppSession"; session = cJSON_CreateObject(); sample = cJSON_CreateObject(); @@ -37,20 +37,9 @@ int 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 ); - - 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 ); @@ -62,18 +51,19 @@ int DiskWriter::writeAudioBuffer(int track, int scene, AudioBuffer* ab ) // FIXME: trim trailing / sessionPath from session path if its there stringstream path; - path << sessionPath << "/" << sessionName << "/samples/" << filename.str(); + path << sessionPath << sessionName << "/samples/" << filename.str(); SndfileHandle outfile( path.str(), SFM_WRITE, SF_FORMAT_WAV | SF_FORMAT_FLOAT, 1, 44100); cout << "Worker::writeSample() " << path.str() << " size: " << ab->getAudioFrames() << endl; // FIXME: the size of the buffer is bigger than the audio contained in it: // calculate the length that needs saving using getBeats() * framesPerBeat - - outfile.write( &ab->getData()[0], ab->getAudioFrames() ); - - // de allocate the AudioBuffer - delete ab; + if ( ab->getAudioFrames() > 0 ) + outfile.write( &ab->getData()[0], ab->getAudioFrames() ); + else + { + LUPPP_WARN("%s","Sample has zero samples"); + } return LUPPP_RETURN_OK; } @@ -98,17 +88,6 @@ void DiskWriter::writeMaster() cJSON_AddItemToArray( sceneNames, sceneName ); } - // reverb - /* - Avtk::Reverb* rev = master->getReverb(); - cJSON* reverb = cJSON_CreateObject(); - cJSON_AddItemToObject( masterTrack, "reverb", reverb ); - cJSON_AddNumberToObject( reverb, "active", rev->getActive() ); - cJSON_AddNumberToObject( reverb, "size", rev->size() ); - cJSON_AddNumberToObject( reverb, "wet", rev->wet() ); - cJSON_AddNumberToObject( reverb, "damping", rev->damping() ); - */ - } int DiskWriter::writeSession( std::string path, std::string sessionName ) diff --git a/src/eventhandlergui.cxx b/src/eventhandlergui.cxx index db8f79e..d9a1e75 100644 --- a/src/eventhandlergui.cxx +++ b/src/eventhandlergui.cxx @@ -112,6 +112,8 @@ void handleGuiEvents() cout << "EventSaveBuffer: " << ev.track << " " << ev.scene << " " << ev.ab->getID() << endl; #endif gui->getDiskWriter()->writeAudioBuffer( ev.track, ev.scene, ev.ab ); + // de allocate the AudioBuffer + delete ev.ab; } break; } case Event::STATE_SAVE_FINISH: { diff --git a/src/gui.cxx b/src/gui.cxx index e3abb55..eb5f3b6 100644 --- a/src/gui.cxx +++ b/src/gui.cxx @@ -60,8 +60,8 @@ static void gui_header_callback(Fl_Widget *w, void *data) } else if ( strcmp(m->label(), "New Session") == 0 ) { - int no = fl_choice("Start a new session?","Cancel","Yes",0); - if ( no ) + int yes = fl_choice("Start a new session?","Cancel","Yes",0); + if ( yes ) { EventStateReset ev; writeToDspRingbuffer( &ev ); @@ -128,8 +128,8 @@ void Gui::selectLoadSample( int track, int scene ) Gui::Gui() : window(1110,650), - diskReader( new DiskReader ), - diskWriter( new DiskWriter ) + diskReader( new DiskReader() ), + diskWriter( new DiskWriter() ) { LUPPP_NOTE( "%s", "Gui()" ); window.color(FL_BLACK); diff --git a/src/looperclip.cxx b/src/looperclip.cxx index 7cad67c..537d854 100644 --- a/src/looperclip.cxx +++ b/src/looperclip.cxx @@ -69,8 +69,8 @@ void LooperClip::reset() EventGuiPrint e( buffer ); writeToGuiRingbuffer( &e ); - //EventRequestSaveBuffer e2( track, scene, _buffer->getAudioFrames() ); - //writeToGuiRingbuffer( &e2 ); + // set "progress" to zero as there's no clip anymore + jack->getControllerUpdater()->setTrackSceneProgress(track, scene, 0 ); } else { @@ -78,7 +78,7 @@ void LooperClip::reset() } init(); - cout << *_buffer << endl; + //cout << *_buffer << endl; } /// loads a sample: eg from disk, unloading current sample if necessary diff --git a/src/main.cxx b/src/main.cxx index b68e7ae..d2aea92 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -48,22 +48,18 @@ int main(int argc, char** argv) #ifdef BUILD_TESTS if ( runTests ) { + // counts failures + int testResult = 0; + // setup the testing Gui / JACK gui = new Gui(); jack = new Jack(); // test offline functionality - gui->getDiskWriter()->runTests(); - - - delete gui; - delete jack; - - gui = new Gui(); - jack = new Jack(); + testResult += gui->getDiskWriter()->runTests(); // test realtime functionality - jack->getGridLogic()->runTests(); + testResult += jack->getGridLogic()->runTests(); delete gui; delete jack; @@ -71,8 +67,7 @@ int main(int argc, char** argv) #ifdef BUILD_COVERAGE_TEST if ( stopAfterTest ) { - LUPPP_NOTE("%s","Done testing, quitting!"); - return 0; + return testResult; } #endif } @@ -85,5 +80,7 @@ int main(int argc, char** argv) jack->activate(); gui->show(); + + return 0; } diff --git a/src/tests/diskwritertest.cxx b/src/tests/diskwritertest.cxx index c65089d..98fb7bc 100644 --- a/src/tests/diskwritertest.cxx +++ b/src/tests/diskwritertest.cxx @@ -11,16 +11,20 @@ #include "qunit.hxx" extern Gui* gui; +extern bool testsPassed; int DiskWriter::runTests() { QUnit::UnitTest qunit( QUnit::normal ); - //AudioBuffer ab; - //QUNIT_IS_TRUE( gui->getDiskWriter()->writeAudioBuffer(0, 0, &ab) == LUPPP_RETURN_OK ); + // set the session path to /tmp for test writing + + + AudioBuffer ab(440); + QUNIT_IS_TRUE( gui->getDiskWriter()->writeAudioBuffer(0, 0, &ab) == LUPPP_RETURN_OK ); QUNIT_IS_TRUE( gui->getDiskWriter()->writeSession("/tmp","luppTestSession") == LUPPP_RETURN_OK ); - return 0; + return qunit.errors(); } #endif diff --git a/test.sh b/test.sh index 5d6623a..f82a0b8 100755 --- a/test.sh +++ b/test.sh @@ -15,9 +15,13 @@ #set -e - -./bin/luppp -test -stopAfterTest - +make && ./bin/luppp -test -stopAfterTest +if [ $? -eq 0 ]; then + notify-send -t 5 "Luppp: Tests passed..." + echo OK +else + notify-send -t 10 -u critical "Luppp: Build / Test Failed!" +fi