From f7aec84cf1a6e0853d6c9fd35cd09e1013ccffab Mon Sep 17 00:00:00 2001 From: Harry van Haaren Date: Sat, 12 Oct 2013 01:31:56 +0100 Subject: [PATCH] -AudioEditor exists, loading files without audio.cfg file now possibe as user asked for beat info --- src/avtk/clipselector.cxx | 2 +- src/diskreader.cxx | 9 ++++++- src/gaudioeditor.cxx | 57 ++++++++++++++++++++++++++++++++++++--- src/gaudioeditor.hxx | 7 +++++ 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/src/avtk/clipselector.cxx b/src/avtk/clipselector.cxx index 9fa8bee..bb4c1c5 100644 --- a/src/avtk/clipselector.cxx +++ b/src/avtk/clipselector.cxx @@ -247,7 +247,7 @@ int ClipSelector::handle(int event) Fl_Menu_Item rclick_menu[] = { { "Load" }, - { "Bars", 0, 0, 0, FL_SUBMENU }, + { "Beats", 0, 0, 0, FL_SUBMENU }, {"1 "}, {"2"}, {"4"}, diff --git a/src/diskreader.cxx b/src/diskreader.cxx index 4b71b26..56d8796 100644 --- a/src/diskreader.cxx +++ b/src/diskreader.cxx @@ -132,7 +132,14 @@ int DiskReader::loadSample( int track, int scene, string path ) // FIXME: Cancel = no load sample? gui->getAudioEditor()->show( ab, true ); while ( gui->getAudioEditor()->shown() ) Fl::wait(); - LUPPP_WARN("finished show() " ); + + // handle "cancel" return + if ( ab->getBeats() == -1 ) + { + LUPPP_WARN("cancel clicked, deleting audiobuffer" ); + delete ab; + return LUPPP_RETURN_OK; + } } } diff --git a/src/gaudioeditor.cxx b/src/gaudioeditor.cxx index 09e4361..e6b1880 100644 --- a/src/gaudioeditor.cxx +++ b/src/gaudioeditor.cxx @@ -2,6 +2,8 @@ #include "gaudioeditor.hxx" +#include + #include "config.hxx" #include "audiobuffer.hxx" @@ -10,17 +12,52 @@ #include "avtk/avtk_button.h" +void oneCB (Fl_Widget*,void* data) { ((AudioEditor*)data)->setBeatsAndQuit( 1 ); } +void twoCB (Fl_Widget*,void* data) { ((AudioEditor*)data)->setBeatsAndQuit( 2 ); } +void fourCB (Fl_Widget*,void* data) { ((AudioEditor*)data)->setBeatsAndQuit( 4 ); } +void eightCB (Fl_Widget*,void* data) { ((AudioEditor*)data)->setBeatsAndQuit( 8 ); } +void sixteenCB (Fl_Widget*,void* data) { ((AudioEditor*)data)->setBeatsAndQuit( 16); } +void thirtyTwoCB(Fl_Widget*,void* data) { ((AudioEditor*)data)->setBeatsAndQuit( 32); } +void sixtyfourCB(Fl_Widget*,void* data) { ((AudioEditor*)data)->setBeatsAndQuit( 64); } + +void cancelCB(Fl_Widget*,void* data) +{ + printf("button, beats = 4\n"); + AudioEditor* ae = (AudioEditor*) data; + ae->setBeatsAndQuit( -1 ); +} + AudioEditor::AudioEditor() { - window = new Fl_Double_Window(500,230,"Audio Editor"); + window = new Fl_Double_Window(450,200,"Audio Editor : Beats?"); waveform = new Avtk::Waveform(5, 5, 450, 150, "Waveform"); + cancel = new Avtk::Button(360, 160, 80,30, "Cancel"); + + const char* names[] = { + "1","2","4","8","16","32","64" + }; + + for(int i = 0; i < 7; i++) + { + stringstream s; + s << i; + beatButtons[i] = new Avtk::Button(5 + i * 50, 160, 40,30, strdup(names[i]) ); + } window->end(); + + beatButtons[0]->callback( oneCB , this); + beatButtons[1]->callback( twoCB , this); + beatButtons[2]->callback( fourCB , this); + beatButtons[3]->callback( eightCB , this); + beatButtons[4]->callback( sixteenCB , this); + beatButtons[5]->callback( thirtyTwoCB, this); + beatButtons[6]->callback( sixtyfourCB, this); + + cancel->callback( cancelCB, this ); } void AudioEditor::show( AudioBuffer* buf, bool modal ) { - - ab = buf; if ( !ab ) @@ -33,12 +70,24 @@ void AudioEditor::show( AudioBuffer* buf, bool modal ) waveform->setData( &tmp[0], tmp.size() ); } - window->set_modal(); window->show(); } +void AudioEditor::setBeatsAndQuit(int beats) +{ + ab->setBeats(beats); + window->hide(); +} + +/* +AudioBuffer* AudioEditor::getAudioBuffer() +{ + return ab; +} +*/ + bool AudioEditor::shown() { return window->shown(); diff --git a/src/gaudioeditor.hxx b/src/gaudioeditor.hxx index ca0ee15..10eab53 100644 --- a/src/gaudioeditor.hxx +++ b/src/gaudioeditor.hxx @@ -9,6 +9,7 @@ class AudioBuffer; namespace Avtk { class Waveform; +class Button; } class AudioEditor @@ -22,11 +23,17 @@ class AudioEditor /// returns true if the editor window is shown bool shown(); + + void setBeatsAndQuit( int beats ); + + //AudioBuffer* getAudioBuffer(); private: // GUI elements Fl_Double_Window* window; Avtk::Waveform* waveform; + Avtk::Button* cancel; + Avtk::Button* beatButtons[7]; // Contents AudioBuffer* ab;