Purify libcanvas, remove libardour dependency

A canvas is just a canvas. Move WaveView into its own library.
This commit is contained in:
Robin Gareus
2017-07-17 20:12:33 +02:00
parent 601c317d70
commit beb73edf55
29 changed files with 267 additions and 293 deletions

View File

@@ -33,7 +33,6 @@ namespace PBD {
LIBCANVAS_API extern DebugBits CanvasEvents;
LIBCANVAS_API extern DebugBits CanvasRender;
LIBCANVAS_API extern DebugBits CanvasEnterLeave;
LIBCANVAS_API extern DebugBits WaveView;
}
}

View File

@@ -22,18 +22,17 @@
#define __canvas_canvas_fwd_h__
namespace ArdourCanvas {
class WaveView;
class Line;
class LineSet;
class LineSet;
class Rectangle;
class Ruler;
class Ruler;
class Polygon;
class PolyLine;
class GtkCanvas;
class GtkCanvasViewport;
class Text;
class Curve;
class ScrollGroup;
class ScrollGroup;
}
#endif /* __canvas_canvas_fwd_h__ */

View File

@@ -29,7 +29,6 @@ PBD::DebugBits PBD::DEBUG::CanvasItemsDirtied = PBD::new_debug_bit ("canvasitems
PBD::DebugBits PBD::DEBUG::CanvasEvents = PBD::new_debug_bit ("canvasevents");
PBD::DebugBits PBD::DEBUG::CanvasRender = PBD::new_debug_bit ("canvasrender");
PBD::DebugBits PBD::DEBUG::CanvasEnterLeave = PBD::new_debug_bit ("canvasenterleave");
PBD::DebugBits PBD::DEBUG::WaveView = PBD::new_debug_bit ("waveview");
struct timeval ArdourCanvas::epoch;
map<string, struct timeval> ArdourCanvas::last_time;

View File

@@ -19,8 +19,6 @@
#include <cairomm/cairomm.h>
#include "ardour/utils.h"
#include "pbd/compose.h"
#include "pbd/convert.h"

View File

@@ -21,8 +21,6 @@
#include "pbd/demangle.h"
#include "pbd/convert.h"
#include "ardour/utils.h"
#include "canvas/canvas.h"
#include "canvas/debug.h"
#include "canvas/item.h"

View File

@@ -22,8 +22,6 @@
#include "pbd/compose.h"
#include "pbd/convert.h"
#include "ardour/utils.h"
#include "canvas/item.h"
#include "canvas/outline.h"
#include "canvas/debug.h"

View File

@@ -1,164 +0,0 @@
#include <gtkmm/main.h>
#include "pbd/textreceiver.h"
#include "gtkmm2ext/utils.h"
#include "midi++/manager.h"
#include "ardour/session.h"
#include "ardour/audioengine.h"
#include "ardour/source_factory.h"
#include "ardour/audiosource.h"
#include "ardour/audiofilesource.h"
#include "ardour/region_factory.h"
#include "ardour/audioregion.h"
#include "canvas/wave_view.h"
#include "canvas/canvas.h"
#include "wave_view.h"
using namespace std;
using namespace PBD;
using namespace ARDOUR;
using namespace ArdourCanvas;
CPPUNIT_TEST_SUITE_REGISTRATION (WaveViewTest);
TextReceiver text_receiver ("test");
void
WaveViewTest::setUp ()
{
init (false, true);
Gtkmm2ext::init ();
SessionEvent::create_per_thread_pool ("test", 512);
Gtk::Main kit ();
Gtk::Main::init_gtkmm_internals ();
text_receiver.listen_to (error);
text_receiver.listen_to (info);
text_receiver.listen_to (fatal);
text_receiver.listen_to (warning);
AudioFileSource::set_build_peakfiles (true);
AudioFileSource::set_build_missing_peakfiles (true);
AudioEngine engine ("test", "");
MIDI::Manager::create (engine.jack ());
CPPUNIT_ASSERT (engine.start () == 0);
Session session (engine, "tmp_session", "tmp_session");
engine.set_session (&session);
char buf[256];
getcwd (buf, sizeof (buf));
string const path = string_compose ("%1/../../libs/canvas/test/sine.wav", buf);
boost::shared_ptr<Source> source = SourceFactory::createReadable (
DataType::AUDIO, session, path, 0, (Source::Flag) 0, false, true
);
boost::shared_ptr<AudioFileSource> audio_file_source = boost::dynamic_pointer_cast<AudioFileSource> (source);
audio_file_source->setup_peakfile ();
PBD::PropertyList properties;
properties.add (Properties::position, 128);
properties.add (Properties::length, audio_file_source->readable_length ());
_region = RegionFactory::create (source, properties, false);
_audio_region = boost::dynamic_pointer_cast<AudioRegion> (_region);
}
void
WaveViewTest::make_canvas ()
{
/* this leaks various things, but hey ho */
_canvas = new ImageCanvas (Duple (256, 256));
_wave_view = new WaveView (_canvas->root(), _audio_region);
_wave_view->set_frames_per_pixel ((double) (44100 / 1000) / 64);
_wave_view->set_height (64);
}
void
WaveViewTest::all ()
{
/* XXX: we run these all from the same method so that the setUp code only
gets called once; there are various singletons etc. in Ardour which don't
like being recreated.
*/
render_all_at_once ();
render_in_pieces ();
cache ();
}
void
WaveViewTest::render_all_at_once ()
{
make_canvas ();
_canvas->render_to_image (Rect (0, 0, 256, 256));
_canvas->write_to_png ("waveview_1.png");
/* XXX: doesn't check the result! */
}
void
WaveViewTest::render_in_pieces ()
{
make_canvas ();
cout << "\n\n--------------> PIECES\n";
_canvas->render_to_image (Rect (0, 0, 128, 256));
_canvas->render_to_image (Rect (128, 0, 256, 256));
_canvas->write_to_png ("waveview_2.png");
cout << "\n\n<-------------- PIECES\n";
/* XXX: doesn't check the result! */
}
void
WaveViewTest::cache ()
{
make_canvas ();
/* Whole of the render area needs caching from scratch */
_wave_view->invalidate_whole_cache ();
Rect whole (0, 0, 256, 256);
_canvas->render_to_image (whole);
CPPUNIT_ASSERT (_wave_view->_cache.size() == 1);
CPPUNIT_ASSERT (_wave_view->_cache.front()->start() == 0);
CPPUNIT_ASSERT (_wave_view->_cache.front()->end() == 256);
_wave_view->invalidate_whole_cache ();
/* Render a bit in the middle */
Rect part1 (128, 0, 196, 256);
_canvas->render_to_image (part1);
CPPUNIT_ASSERT (_wave_view->_cache.size() == 1);
CPPUNIT_ASSERT (_wave_view->_cache.front()->start() == 128);
CPPUNIT_ASSERT (_wave_view->_cache.front()->end() == 196);
/* Now render the whole thing and check that the cache sorts itself out */
_canvas->render_to_image (whole);
CPPUNIT_ASSERT (_wave_view->_cache.size() == 3);
list<WaveView::CacheEntry*>::iterator i = _wave_view->_cache.begin ();
CPPUNIT_ASSERT ((*i)->start() == 0);
CPPUNIT_ASSERT ((*i)->end() == 128);
++i;
CPPUNIT_ASSERT ((*i)->start() == 128);
CPPUNIT_ASSERT ((*i)->end() == 196);
++i;
CPPUNIT_ASSERT ((*i)->start() == 196);
CPPUNIT_ASSERT ((*i)->end() == 256);
++i;
}

View File

@@ -1,26 +0,0 @@
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
class WaveViewTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE (WaveViewTest);
CPPUNIT_TEST (all);
CPPUNIT_TEST_SUITE_END ();
public:
void setUp ();
void all ();
private:
void make_canvas ();
void render_all_at_once ();
void render_in_pieces ();
void cache ();
ArdourCanvas::ImageCanvas* _canvas;
ArdourCanvas::WaveView* _wave_view;
boost::shared_ptr<ARDOUR::Region> _region;
boost::shared_ptr<ARDOUR::AudioRegion> _audio_region;
};

View File

@@ -60,8 +60,6 @@ canvas_sources = [
'tracking_text.cc',
'types.cc',
'utils.cc',
'wave_view.cc',
'wave_view_private.cc',
'widget.cc',
'xfade_curve.cc',
]
@@ -88,7 +86,7 @@ def build(bld):
obj.export_includes = ['.']
obj.includes = ['.']
obj.uselib = 'SIGCPP CAIROMM GTKMM BOOST XML'
obj.use = [ 'libpbd', 'libevoral', 'libardour', 'libgtkmm2ext', 'libevoral' ]
obj.use = [ 'libpbd', 'libgtkmm2ext' ]
obj.name = 'libcanvas'
obj.target = 'canvas'
obj.vnum = CANVAS_LIB_VERSION
@@ -113,7 +111,7 @@ def build(bld):
unit_testobj.includes = obj.includes + ['test', '../pbd']
unit_testobj.uselib = 'CPPUNIT SIGCPP CAIROMM GTKMM'
unit_testobj.uselib_local = 'libcanvas libevoral libardour libgtkmm2ext'
unit_testobj.uselib_local = 'libcanvas libgtkmm2ext'
unit_testobj.name = 'libcanvas-unit-tests'
unit_testobj.target = 'run-tests'
unit_testobj.install_path = ''
@@ -138,7 +136,7 @@ def build(bld):
manual_testobj.source = t
manual_testobj.includes = obj.includes + ['test', '../pbd']
manual_testobj.uselib = 'CPPUNIT SIGCPP CAIROMM GTKMM'
manual_testobj.uselib_local = 'libcanvas libevoral libardour libgtkmm2ext'
manual_testobj.uselib_local = 'libcanvas libgtkmm2ext'
manual_testobj.name = 'libcanvas-manual-test-%s' % name
manual_testobj.target = target
manual_testobj.install_path = ''
@@ -157,7 +155,7 @@ def build(bld):
manual_testobj.source = [ t, 'benchmark/benchmark.cc' ]
manual_testobj.includes = obj.includes + ['test', '../pbd']
manual_testobj.uselib = 'CPPUNIT SIGCPP CAIROMM GTKMM'
manual_testobj.uselib_local = 'libcanvas libevoral libardour libgtkmm2ext'
manual_testobj.uselib_local = 'libcanvas libgtkmm2ext'
manual_testobj.name = 'libcanvas-benchmark-%s' % name
manual_testobj.target = target
manual_testobj.install_path = ''

23
libs/waveview/debug.cc Normal file
View File

@@ -0,0 +1,23 @@
/*
Copyright (C) 2011 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "pbd/debug.h"
#include "waveview/debug.h"
PBD::DebugBits PBD::DEBUG::WaveView = PBD::new_debug_bit ("waveview");

View File

@@ -26,9 +26,7 @@
#include <cairomm/cairomm.h>
#include <glibmm/threads.h>
#include "gtkmm2ext/utils.h"
#include "gtkmm2ext/gui_thread.h"
#include <gdkmm/general.h>
#include "pbd/base_ui.h"
#include "pbd/compose.h"
@@ -43,21 +41,22 @@
#include "ardour/audiosource.h"
#include "ardour/session.h"
#include "canvas/canvas.h"
#include "gtkmm2ext/colors.h"
#include "canvas/debug.h"
#include "canvas/wave_view.h"
#include "canvas/wave_view_private.h"
#include <gdkmm/general.h>
#include "gtkmm2ext/gui_thread.h"
#include "gtkmm2ext/utils.h"
#include "canvas/canvas.h"
#include "canvas/debug.h"
#include "waveview/wave_view.h"
#include "waveview/wave_view_private.h"
using namespace std;
using namespace ARDOUR;
using namespace PBD;
using namespace ArdourCanvas;
using namespace ARDOUR;
using namespace Gtkmm2ext;
using namespace ArdourCanvas;
using namespace ArdourWaveView;
double WaveView::_global_gradient_depth = 0.6;
bool WaveView::_global_logscaled = false;

View File

@@ -20,14 +20,14 @@
#include <cmath>
#include "ardour/lmath.h"
#include "canvas/wave_view_private.h"
#include "pbd/cpus.h"
#include "ardour/audioregion.h"
#include "ardour/audiosource.h"
namespace ArdourCanvas {
#include "waveview/wave_view_private.h"
namespace ArdourWaveView {
WaveViewProperties::WaveViewProperties (boost::shared_ptr<ARDOUR::AudioRegion> region)
: region_start (region->start ())
@@ -455,4 +455,4 @@ WaveViewDrawingThread::run ()
}
}
} // namespace ArdourCanvas
}

View File

@@ -0,0 +1,35 @@
/*
Copyright (C) 2011-2013 Paul Davis
Author: Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _WAVEVIEW_DEBUG_H_
#define _WAVEVIEW_DEBUG_H_
#include <sys/time.h>
#include <map>
#include "pbd/debug.h"
#include "waveview/visibility.h"
namespace PBD {
namespace DEBUG {
LIBWAVEVIEW_API extern DebugBits WaveView;
}
}
#endif

View File

@@ -0,0 +1,45 @@
/*
Copyright (C) 2013 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __libwaveview_visibility_h__
#define __libwaveview_visibility_h__
#if defined(COMPILER_MSVC)
#define LIBWAVEVIEW_DLL_IMPORT __declspec(dllimport)
#define LIBWAVEVIEW_DLL_EXPORT __declspec(dllexport)
#define LIBWAVEVIEW_DLL_LOCAL
#else
#define LIBWAVEVIEW_DLL_IMPORT __attribute__ ((visibility ("default")))
#define LIBWAVEVIEW_DLL_EXPORT __attribute__ ((visibility ("default")))
#define LIBWAVEVIEW_DLL_LOCAL __attribute__ ((visibility ("hidden")))
#endif
#ifdef LIBWAVEVIEW_STATIC // libcanvas is not a DLL
#define LIBWAVEVIEW_API
#define LIBWAVEVIEW_LOCAL
#else
#ifdef LIBWAVEVIEW_DLL_EXPORTS // defined if we are building the libcanvas DLL (instead of using it)
#define LIBWAVEVIEW_API LIBWAVEVIEW_DLL_EXPORT
#else
#define LIBWAVEVIEW_API LIBWAVEVIEW_DLL_IMPORT
#endif
#define LIBWAVEVIEW_LOCAL LIBWAVEVIEW_DLL_LOCAL
#endif
#endif /* __libwaveview_visibility_h__ */

View File

@@ -19,18 +19,17 @@
*/
#ifndef __CANVAS_WAVE_VIEW_H__
#define __CANVAS_WAVE_VIEW_H__
#ifndef _WAVEVIEW_WAVE_VIEW_H_
#define _WAVEVIEW_WAVE_VIEW_H_
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include "ardour/types.h"
#include <glibmm/refptr.h>
#include "canvas/visibility.h"
#include "ardour/types.h"
#include "canvas/item.h"
#include "waveview/visibility.h"
namespace ARDOUR {
class AudioRegion;
@@ -40,9 +39,7 @@ namespace Gdk {
class Pixbuf;
}
class WaveViewTest;
namespace ArdourCanvas {
namespace ArdourWaveView {
class WaveViewCacheGroup;
class WaveViewDrawRequest;
@@ -51,7 +48,7 @@ class WaveViewImage;
class WaveViewProperties;
class WaveViewDrawingThread;
class LIBCANVAS_API WaveView : public Item, public sigc::trackable
class LIBWAVEVIEW_API WaveView : public ArdourCanvas::Item, public sigc::trackable
{
public:
enum Shape { Normal, Rectified };
@@ -76,18 +73,18 @@ public:
other view parameters).
*/
WaveView (Canvas*, boost::shared_ptr<ARDOUR::AudioRegion>);
WaveView (ArdourCanvas::Canvas*, boost::shared_ptr<ARDOUR::AudioRegion>);
WaveView (Item*, boost::shared_ptr<ARDOUR::AudioRegion>);
~WaveView ();
virtual void prepare_for_render (Rect const& window_area) const;
virtual void prepare_for_render (ArdourCanvas::Rect const& window_area) const;
virtual void render (Rect const & area, Cairo::RefPtr<Cairo::Context>) const;
virtual void render (ArdourCanvas::Rect const & area, Cairo::RefPtr<Cairo::Context>) const;
void compute_bounding_box () const;
void set_samples_per_pixel (double);
void set_height (Distance);
void set_height (ArdourCanvas::Distance);
void set_channel (int);
void set_region_start (ARDOUR::frameoffset_t);
@@ -161,7 +158,6 @@ private:
#endif
private:
friend class ::WaveViewTest;
friend class WaveViewThreadClient;
friend class WaveViewDrawingThread;
@@ -247,8 +243,9 @@ private:
void set_image (boost::shared_ptr<WaveViewImage> img) const;
// @return true if item area intersects with draw area
bool get_item_and_draw_rect_in_window_coords (Rect const& canvas_rect, Rect& item_area,
Rect& draw_rect) const;
bool get_item_and_draw_rect_in_window_coords (ArdourCanvas::Rect const& canvas_rect,
ArdourCanvas::Rect& item_area,
ArdourCanvas::Rect& draw_rect) const;
boost::shared_ptr<WaveViewDrawRequest> create_draw_request (WaveViewProperties const&) const;
@@ -266,6 +263,6 @@ private:
void reset_cache_group ();
};
} // namespace ArdourCanvas
} /* namespace */
#endif // __CANVAS_WAVE_VIEW_H__
#endif

View File

@@ -17,18 +17,18 @@
*/
#ifndef __CANVAS_WAVE_VIEW_PRIVATE_H__
#define __CANVAS_WAVE_VIEW_PRIVATE_H__
#ifndef _WAVEVIEW_WAVE_VIEW_PRIVATE_H_
#define _WAVEVIEW_WAVE_VIEW_PRIVATE_H_
#include <deque>
#include "canvas/wave_view.h"
#include "waveview/wave_view.h"
namespace ARDOUR {
class AudioRegion;
}
namespace ArdourCanvas {
namespace ArdourWaveView {
struct WaveViewProperties
{
@@ -360,6 +360,6 @@ private:
};
} // namespace ArdourCanvas
} /* namespace */
#endif // __CANVAS_WAVE_VIEW_PRIVATE_H__
#endif

64
libs/waveview/wscript Normal file
View File

@@ -0,0 +1,64 @@
#!/usr/bin/env python
from waflib.extras import autowaf as autowaf
from waflib import Options
from waflib import TaskGen
import os
# Version of this package (even if built as a child)
MAJOR = '0'
MINOR = '0'
MICRO = '0'
WAVEVIEW_VERSION = "%s.%s.%s" % (MAJOR, MINOR, MICRO)
# Library version (UNIX style major, minor, micro)
# major increment <=> incompatible changes
# minor increment <=> compatible changes (additions)
# micro increment <=> no interface changes
WAVEVIEW_LIB_VERSION = '0.0.0'
# Variables for 'waf dist'
APPNAME = 'waveview'
VERSION = WAVEVIEW_VERSION
I18N_PACKAGE = 'libwaveview'
# Mandatory variables
top = '.'
out = 'build'
waveview_sources = [
'debug.cc',
'wave_view.cc',
'wave_view_private.cc',
]
def options(opt):
autowaf.set_options(opt)
def configure(conf):
conf.load ('compiler_cxx')
autowaf.configure(conf)
autowaf.check_pkg(conf, 'cairomm-1.0', uselib_store='CAIROMM', atleast_version='1.8.4')
def build(bld):
# Library
if bld.is_defined ('INTERNAL_SHARED_LIBS'):
obj = bld.shlib(features = 'cxx cxxshlib', source=waveview_sources)
obj.defines = [ 'LIBWAVEVIEW_DLL_EXPORTS=1' ]
else:
obj = bld.stlib(features = 'cxx cxxstlib', source=waveview_sources)
obj.cxxflags = [ '-fPIC' ]
obj.cflags = [ '-fPIC' ]
obj.defines = [ ]
obj.export_includes = ['.']
obj.includes = ['.']
obj.uselib = 'SIGCPP CAIROMM GTKMM BOOST XML'
obj.use = [ 'libpbd', 'libcanvas', 'libardour', 'libgtkmm2ext' ]
obj.name = 'libwaveview'
obj.target = 'waveview'
obj.vnum = WAVEVIEW_LIB_VERSION
obj.install_path = bld.env['LIBDIR']
obj.defines += [ 'PACKAGE="' + I18N_PACKAGE + '"' ]
def shutdown():
autowaf.shutdown()