Fixes a few leaks and errors

This commit is contained in:
Mathias Buhr 2017-04-22 01:26:48 +02:00 committed by Harry van Haaren
parent a332d9b0fe
commit c5d33f89cd
26 changed files with 76 additions and 141 deletions

View file

@ -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)

View file

@ -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} )

View file

@ -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;

View file

@ -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;

View file

@ -20,7 +20,7 @@
#ifndef AVTK_BUTTON_H
#define AVTK_BUTTON_H
#include <FL/Fl_Button.H>
#include <ntk/FL/Fl_Button.H>
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

View file

@ -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) {

View file

@ -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

View file

@ -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

View file

@ -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()
{

View file

@ -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;

View file

@ -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()
{

View file

@ -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;

View file

@ -37,7 +37,6 @@ public:
bool mouseOver;
bool highlight;
int x, y, w, h;
const char* label;
void add( Binding* b );

View file

@ -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 ) {

View file

@ -89,7 +89,6 @@ public:
bool mouseOver;
bool highlight;
int x, y, w, h;
const char* label;
void setID( int id );

View file

@ -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;

View file

@ -52,7 +52,6 @@ private:
bool orientationHorizontal;
int x, y, w, h;
const char* label;
int mouseClickedX;
int mouseClickedY;

View file

@ -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<float> data;
void setData( float* d, long size )
void setData( const std::vector<float>& 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;

View file

@ -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

View file

@ -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());

View file

@ -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;

View file

@ -105,8 +105,8 @@ void AudioEditor::show( AudioBuffer* buf, bool modal )
}
std::vector<float>& 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};

View file

@ -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)

View file

@ -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<GTrack>(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<GTrack> 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);
}
}

View file

@ -21,6 +21,7 @@
#include <vector>
#include <string>
#include <memory>
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
@ -68,7 +69,7 @@ public:
void addMidiControllerToSetup(std::string);
void setupMidiControllers();
GTrack* getTrack(int id);
std::shared_ptr<GTrack> getTrack(int id) const;
GMasterTrack* getMasterTrack()
{
return master;
@ -137,7 +138,7 @@ private:
GMasterTrack* master;
vector<GTrack*> tracks;
vector<std::shared_ptr<GTrack>> tracks;
// FIXME: refactor tooltip code out..?
std::string tooltip;

View file

@ -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;
}