diff --git a/CMakeLists.txt b/CMakeLists.txt index f492195..f0aa217 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ set(LUPPP_VERSION_PATCH "1") set(LUPPP_VERSION "${LUPPP_VERSION_MAJOR}.${LUPPP_VERSION_MINOR}.${LUPPP_VERSION_PATCH}") option(BUILD_TESTS "Build test version" OFF) +option(WITH_ASAN "Build address sanitized version" OFF) #set(CMAKE_VERBOSE_MAKEFILE on) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7b44db1..69454fa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,7 +50,14 @@ IF(RELEASE_BUILD) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -W -Wno-unused-variable ") ENDIF(RELEASE_BUILD) -if( ${ARCHITECTURE} STREQUAL "x86_64" ) +IF(WITH_ASAN) + SET(CMAKE_C_COMPILER "/usr/bin/clang") + SET(CMAKE_CXX_COMPILER "/usr/bin/clang++") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -fsanitize=address -fno-omit-frame-pointer") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g -fsanitize=address -fno-omit-frame-pointer") +ENDIF() + +if( ${ARCHITECTURE} STREQUAL "x86_64" AND NOT WITH_ASAN) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -msse2") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -msse2") else() @@ -63,6 +70,12 @@ FILE(GLOB sources *.cxx avtk/*.cxx cjson/*.c controller/*.cxx dsp/*.cxx observe # Compile binary add_executable (luppp version.hxx ${sources} ) +# require a C++11 compiler +set_target_properties(luppp PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES + CXX_EXTENSIONS NO +) # Linking target_link_libraries( luppp ${JACK_LIBRARIES} ) diff --git a/src/avtk/avtk_background.h b/src/avtk/avtk_background.h index 6fc07c0..2ce1d5c 100644 --- a/src/avtk/avtk_background.h +++ b/src/avtk/avtk_background.h @@ -34,33 +34,18 @@ class Background : public Fl_Widget { public: Background(int _x, int _y, int _w, int _h, const char *_label = 0): - Fl_Widget(_x, _y, _w, _h, _label) + Fl_Widget(_x, _y, _w, _h) { + copy_label(_label); x = _x; y = _y; w = _w; h = _h; - label = strdup(_label); - highlight = false; } bool highlight; int x, y, w, h; - const char* label; - - void setLabel(const char* l) - { - if( label ) - free( (char*) label); - - label = strdup( l ); - redraw(); - } - const char* getLabel() - { - return label; - } void draw() { @@ -87,7 +72,7 @@ public: cairo_move_to( cr, x + 10, y + 14 ); cairo_set_source_rgba( cr, 0 / 255.f, 153 / 255.f , 255 / 255.f , 1 ); cairo_set_font_size( cr, 10 ); - cairo_show_text( cr, label ); + cairo_show_text( cr, label() ); // lower stripe cairo_move_to( cr, x , y + 20 ); @@ -122,8 +107,7 @@ public: if ( Fl::event_state(FL_BUTTON3) && Fl::event_y() < y + 20 ) { const char* name = fl_input( "Track name: ", "" ); if ( name ) { - free( (char*) label ); - label = strdup( name ); + copy_label(name); redraw(); } return 1; diff --git a/src/avtk/avtk_box.h b/src/avtk/avtk_box.h index f36525b..ffde3c1 100644 --- a/src/avtk/avtk_box.h +++ b/src/avtk/avtk_box.h @@ -30,8 +30,9 @@ class Box : public Fl_Widget { public: Box(int _x, int _y, int _w, int _h, const char *_label = 0): - Fl_Widget(_x, _y, _w, _h, _label) + Fl_Widget(_x, _y, _w, _h) { + copy_label(_label); x = _x; y = _y; w = _w; @@ -39,29 +40,13 @@ public: r = g = b = 0; - label = strdup(_label); - highlight = false; } bool highlight; int x, y, w, h; - const char* label; int r,g,b; - void setLabel(const char* l) - { - if( label ) - free( (char*) label); - - label = strdup( l ); - redraw(); - } - const char* getLabel() - { - return label; - } - void setColor( int red, int green, int blue ) { r = red; diff --git a/src/avtk/avtk_button.h b/src/avtk/avtk_button.h index 3fe7996..790c92f 100644 --- a/src/avtk/avtk_button.h +++ b/src/avtk/avtk_button.h @@ -20,7 +20,7 @@ #ifndef AVTK_BUTTON_H #define AVTK_BUTTON_H -#include +#include namespace Avtk { @@ -29,16 +29,14 @@ class Button : public Fl_Button { public: Button(int _x, int _y, int _w, int _h, const char *_label): - Fl_Button(_x, _y, _w, _h, _label) + Fl_Button(_x, _y, _w, _h) { + copy_label(_label); x = _x; y = _y; w = _w; h = _h; - labelMe = _label; - setLabel( labelMe ); - _r = 1.0; _g = 0.48; _b = 0.0; @@ -63,14 +61,6 @@ public: bool mouseOver; bool highlight; int x, y, w, h; - const char* labelMe; - - void setLabel( const char* l) - { - labelMe = l; - label( labelMe ); - redraw(); - } float _r, _g, _b; // foreground colour float _bgr, _bgg, _bgb; // background colour diff --git a/src/avtk/avtk_dial.h b/src/avtk/avtk_dial.h index 7012f51..543aa47 100644 --- a/src/avtk/avtk_dial.h +++ b/src/avtk/avtk_dial.h @@ -44,13 +44,6 @@ public: mouseClicked = false; highlight = false; - _label = strdup( _lab ); - } - - ~Dial() - { - if( _label ) - free( _label ); } bool highlight; @@ -66,17 +59,6 @@ public: bool drawLabel; - void setLabel( const char* newLabel ) - { - if( _label ) - free( _label ); - - _label = strdup( newLabel ); - - label( _label ); - redraw(); - } - void draw() { if (damage() & FL_DAMAGE_ALL) { diff --git a/src/avtk/avtk_light_button.h b/src/avtk/avtk_light_button.h index 441a1ca..c664e76 100644 --- a/src/avtk/avtk_light_button.h +++ b/src/avtk/avtk_light_button.h @@ -29,7 +29,7 @@ class LightButton : public Fl_Button { public: LightButton(int _x, int _y, int _w, int _h, const char *_label): - Fl_Button(_x, _y, _w, _h, _label) + Fl_Button(_x, _y, _w, _h) { x = _x; y = _y; @@ -48,8 +48,6 @@ public: _outg = _g; _outb = _b; - label = _label; - _highlight = false; mouseOver = false; } @@ -57,7 +55,6 @@ public: bool mouseOver; bool _highlight; int x, y, w, h; - const char* label; float _r, _g, _b; // foreground colour float _bgr, _bgg, _bgb; // background colour float _outr, _outg, _outb; // outline colour diff --git a/src/avtk/avtk_radial_status.h b/src/avtk/avtk_radial_status.h index 29227e9..ea1cc01 100644 --- a/src/avtk/avtk_radial_status.h +++ b/src/avtk/avtk_radial_status.h @@ -29,15 +29,14 @@ class RadialStatus : public Fl_Slider { public: RadialStatus(int _x, int _y, int _w, int _h, const char *_label = 0): - Fl_Slider(_x, _y, _w, _h, _label) + Fl_Slider(_x, _y, _w, _h) { + copy_label(_label); x = _x; y = _y; w = _w; h = _h; - label = _label; - previousAngle = -1; _r = 1.0; @@ -64,8 +63,6 @@ public: bool mouseOver; bool highlight; int x, y, w, h; - const char* label; - int previousAngle; float _r, _g, _b; // foreground colour diff --git a/src/avtk/avtk_reverb.h b/src/avtk/avtk_reverb.h index a3a05d3..c93692b 100644 --- a/src/avtk/avtk_reverb.h +++ b/src/avtk/avtk_reverb.h @@ -29,8 +29,9 @@ class Reverb : public Fl_Slider { public: Reverb(int _x, int _y, int _w, int _h, const char *_label =0): - Fl_Slider(_x, _y, _w, _h, _label) + Fl_Slider(_x, _y, _w, _h) { + copy_label(_label); x = _x; y = _y; w = _w; @@ -42,8 +43,6 @@ public: active = false; - label = _label; - highlight = false; mouseOver = false; } @@ -96,7 +95,6 @@ public: bool mouseOver; bool highlight; int x, y, w, h; - const char* label; void draw() { diff --git a/src/avtk/avtk_sidechain_gain.h b/src/avtk/avtk_sidechain_gain.h index b141230..8bc2493 100644 --- a/src/avtk/avtk_sidechain_gain.h +++ b/src/avtk/avtk_sidechain_gain.h @@ -34,15 +34,14 @@ class SidechainGain : public Fl_Slider { public: SidechainGain(int _x, int _y, int _w, int _h, const char *_label = 0): - Fl_Slider(_x, _y, _w, _h, _label) + Fl_Slider(_x, _y, _w, _h) { + copy_label(_label); x = _x; y = _y; w = _w; h = _h; - label = _label; - mouseClickedX = 0; mouseClickedY = 0; mouseClicked = false; @@ -84,7 +83,6 @@ public: bool active; bool highlight; int x, y, w, h; - const char* label; int mouseClickedX; int mouseClickedY; diff --git a/src/avtk/avtk_unit.h b/src/avtk/avtk_unit.h index 9bc4bb7..c2626c8 100644 --- a/src/avtk/avtk_unit.h +++ b/src/avtk/avtk_unit.h @@ -57,15 +57,14 @@ class Unit : public Fl_Button { public: Unit(int _x, int _y, int _w, int _h, const char *_label): - Fl_Button(_x, _y, _w, _h, _label) + Fl_Button(_x, _y, _w, _h) { + copy_label(_label); x = _x; y = _y; w = _w; h = _h; - label = _label; - highlight = false; mouseOver = false; @@ -83,7 +82,6 @@ public: bool mouseOver; bool highlight; int x, y, w, h; - const char* label; void draw() { diff --git a/src/avtk/bindings.cxx b/src/avtk/bindings.cxx index 3800886..fd68e65 100644 --- a/src/avtk/bindings.cxx +++ b/src/avtk/bindings.cxx @@ -27,15 +27,14 @@ namespace Avtk { Bindings::Bindings( int _x, int _y, int _w, int _h, const char *_label ) : - Fl_Button(_x, _y, _w, _h, _label) + Fl_Button(_x, _y, _w, _h) { + copy_label(_label); x = _x; y = _y; w = _w; h = _h; - label = _label; - bindYPx = 25; highlight = false; diff --git a/src/avtk/bindings.h b/src/avtk/bindings.h index bc82a79..d6cda6a 100644 --- a/src/avtk/bindings.h +++ b/src/avtk/bindings.h @@ -37,7 +37,6 @@ public: bool mouseOver; bool highlight; int x, y, w, h; - const char* label; void add( Binding* b ); diff --git a/src/avtk/clipselector.cxx b/src/avtk/clipselector.cxx index 738e81a..b0ab6bf 100644 --- a/src/avtk/clipselector.cxx +++ b/src/avtk/clipselector.cxx @@ -32,8 +32,9 @@ namespace Avtk ClipSelector::ClipSelector( int _x, int _y, int _w, int _h, const char *_label, bool master ) : - Fl_Button(_x, _y, _w, _h, _label) + Fl_Button(_x, _y, _w, _h) { + copy_label(_label); x = _x; y = _y; w = _w; @@ -41,7 +42,6 @@ ClipSelector::ClipSelector( int _x, int _y, int _w, int _h, special = -1; - label = _label; _master = master; if ( _master ) { diff --git a/src/avtk/clipselector.hxx b/src/avtk/clipselector.hxx index 1b688f2..35ba47d 100644 --- a/src/avtk/clipselector.hxx +++ b/src/avtk/clipselector.hxx @@ -89,7 +89,6 @@ public: bool mouseOver; bool highlight; int x, y, w, h; - const char* label; void setID( int id ); diff --git a/src/avtk/volume.cxx b/src/avtk/volume.cxx index 9a3deda..e24e85a 100644 --- a/src/avtk/volume.cxx +++ b/src/avtk/volume.cxx @@ -21,15 +21,14 @@ using namespace Avtk; Volume::Volume(int _x, int _y, int _w, int _h, const char *_label ): - Fl_Slider(_x, _y, _w, _h, _label) + Fl_Slider(_x, _y, _w, _h) { + copy_label(_label); x = _x; y = _y; w = _w; h = _h; - label = _label; - mouseClickedX = 0; mouseClickedY = 0; mouseClicked = false; diff --git a/src/avtk/volume.hxx b/src/avtk/volume.hxx index ae592d0..106f0cc 100644 --- a/src/avtk/volume.hxx +++ b/src/avtk/volume.hxx @@ -52,7 +52,6 @@ private: bool orientationHorizontal; int x, y, w, h; - const char* label; int mouseClickedX; int mouseClickedY; diff --git a/src/avtk/waveform.h b/src/avtk/waveform.h index 32cca90..47688bc 100644 --- a/src/avtk/waveform.h +++ b/src/avtk/waveform.h @@ -35,29 +35,27 @@ class Waveform : public Fl_Widget { public: Waveform(int _x, int _y, int _w, int _h, const char *_label=0 ): - Fl_Widget(_x, _y, _w, _h, _label) + Fl_Widget(_x, _y, _w, _h), + data(_w) { + copy_label(_label); x = _x; y = _y; w = _w; h = _h; - label = _label; - highlight = false; newWaveform = false; waveformCr = 0; waveformSurf = 0; - - data = (float*)malloc( sizeof(float) * w ); - srand (time(NULL)); - for (int i = 0; i < _w; i++) { - data[i] = rand() / RAND_MAX / 0.75; - } + std::generate(data.begin(), data.end(), []() -> float { + return rand() / RAND_MAX / 0.75; + } + ); newWaveform = true; @@ -67,7 +65,6 @@ public: bool strokeRim; bool highlight; int x, y, w, h; - const char* label; cairo_t* waveformCr; cairo_surface_t* waveformSurf; @@ -75,13 +72,12 @@ public: bool newWaveform; long dataSize; - float* data; + std::vector data; - void setData( float* d, long size ) + void setData( const std::vector& newdata ) { //cout << "AvtkWaveform: setDataPtr = " << data << endl; - dataSize = size; - data = d; + data = newdata; newWaveform = true; @@ -137,7 +133,7 @@ public: cairo_set_dash ( waveformCr, dashes, 0, 0.0); - if ( !data ) { + if ( !data.empty() ) { // draw X cairo_move_to( cr, 0 , 0 ); cairo_line_to( cr, 0 + w, 0 + h ); @@ -241,11 +237,8 @@ public: // FIXME: needs to be resampled, not clipped at end // delete old data, and resize it - float* newData = (float*)malloc( sizeof(float) * w ); - memcpy( newData, data, newSize ); - free ( data ); - data = newData; + data.resize(w); newWaveform = true; diff --git a/src/diskreader.cxx b/src/diskreader.cxx index 6f16839..be8d488 100644 --- a/src/diskreader.cxx +++ b/src/diskreader.cxx @@ -596,7 +596,7 @@ int DiskReader::readTracks() if( !name ) { LUPPP_WARN("Track %i has no name data saved.", t); } else { - gui->getTrack(t)->bg.setLabel( name->valuestring ); + gui->getTrack(t)->bg.copy_label( name->valuestring ); } } // fader diff --git a/src/diskwriter.cxx b/src/diskwriter.cxx index 4908730..aa93358 100644 --- a/src/diskwriter.cxx +++ b/src/diskwriter.cxx @@ -88,7 +88,14 @@ DiskWriter::DiskWriter() } else { LUPPP_NOTE("Creating .config/openAV/luppp directory"); } -}; +} + +DiskWriter::~DiskWriter() +{ + // reset the cJSON objects + cJSON_Delete( sessionJson ); + cJSON_Delete( audioJson ); +} void DiskWriter::initialize(std::string path, std::string name ) { @@ -396,7 +403,7 @@ int DiskWriter::writeSession() // add track metadata: volumes, sends etc cJSON_AddNumberToObject( track, "ID", t ); - cJSON_AddStringToObject( track, "name", gui->getTrack(t)->bg.getLabel() ); + cJSON_AddStringToObject( track, "name", gui->getTrack(t)->bg.label() ); cJSON_AddNumberToObject( track, "fader", gui->getTrack(t)->getVolume()->value() ); cJSON_AddNumberToObject( track, "pan", gui->getTrack(t)->getPan()); diff --git a/src/diskwriter.hxx b/src/diskwriter.hxx index 838d781..215bf42 100644 --- a/src/diskwriter.hxx +++ b/src/diskwriter.hxx @@ -54,6 +54,7 @@ class DiskWriter { public: DiskWriter(); + ~DiskWriter(); /// sets up session write path etc void initialize( std::string path, std::string sessionName ); @@ -82,8 +83,8 @@ public: #endif private: - cJSON* sessionJson; - cJSON* audioJson; + cJSON* sessionJson = nullptr; + cJSON* audioJson = nullptr; bool foldersCreated; std::string sessionName; diff --git a/src/gaudioeditor.cxx b/src/gaudioeditor.cxx index 4b80275..e0f08f0 100644 --- a/src/gaudioeditor.cxx +++ b/src/gaudioeditor.cxx @@ -105,8 +105,8 @@ void AudioEditor::show( AudioBuffer* buf, bool modal ) } std::vector& tmp = ab->getDataL(); - int size = tmp.size(); - waveform->setData( &tmp[0], size ); + const auto size = tmp.size(); + waveform->setData( tmp ); const int beats[]= {1,2,4,8,16,32,64}; diff --git a/src/gmastertrack.cxx b/src/gmastertrack.cxx index c95ab69..e61f3dd 100644 --- a/src/gmastertrack.cxx +++ b/src/gmastertrack.cxx @@ -263,7 +263,7 @@ void GMasterTrack::setBpm( int b ) tempoDial.value( ( bpm - 60 ) / 160.f ); std::stringstream s; s << bpm; - tempoDial.setLabel( s.str().c_str() ); + tempoDial.copy_label( s.str().c_str() ); } void GMasterTrack::setInputVol(float f) diff --git a/src/gui.cxx b/src/gui.cxx index 68daadb..3aaf3cd 100644 --- a/src/gui.cxx +++ b/src/gui.cxx @@ -442,7 +442,7 @@ Gui::Gui(const char* argZero) : for (; i < NTRACKS; i++ ) { stringstream s; s << "Track " << i+1; - tracks.push_back( new GTrack(8 + i * 118, 40, 110, 650, s.str().c_str() ) ); + tracks.push_back( std::make_shared(8 + i * 118, 40, 110, 650, s.str().c_str() ) ); } master = new GMasterTrack(8 + i * 118, 40, 150, 650, "Master"); } @@ -515,7 +515,7 @@ void Gui::reset() for(unsigned int i = 0; i < NTRACKS; i++) { stringstream s; s << "Track " << i+1; - tracks.at(i)->bg.setLabel( s.str().c_str() ); + tracks.at(i)->bg.copy_label( s.str().c_str() ); for(unsigned int s = 0; s < NSCENES; s++) { tracks.at(i)->getClipSelector()->clipName( s, "" ); @@ -530,7 +530,7 @@ void Gui::reset() } -GTrack* Gui::getTrack(int id) +std::shared_ptr Gui::getTrack(int id) const { return tracks.at(id); } @@ -915,10 +915,4 @@ Gui::~Gui() delete diskWriter; delete master; - - for(unsigned int i = 0; i < tracks.size(); i++) { - delete tracks.at(i); - } - - } diff --git a/src/gui.hxx b/src/gui.hxx index 3fcd473..52520f7 100644 --- a/src/gui.hxx +++ b/src/gui.hxx @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -68,7 +69,7 @@ public: void addMidiControllerToSetup(std::string); void setupMidiControllers(); - GTrack* getTrack(int id); + std::shared_ptr getTrack(int id) const; GMasterTrack* getMasterTrack() { return master; @@ -137,7 +138,7 @@ private: GMasterTrack* master; - vector tracks; + vector> tracks; // FIXME: refactor tooltip code out..? std::string tooltip; diff --git a/src/main.cxx b/src/main.cxx index c4cc787..066bad0 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -39,8 +39,8 @@ jack_ringbuffer_t* rbToDsp = 0; jack_ringbuffer_t* rbToGui = 0; // global static pointers, for access from EventHandlerGui and EventHandlerDsp -Gui * gui = 0; -Jack* jack = 0; +Gui * gui = nullptr; +Jack* jack = nullptr; void signalHanlder(int signum) @@ -130,6 +130,7 @@ int main(int argc, char** argv) gui->show(); + delete gui; return 0; }