tweaks and so forth to get first canvas-based rendering to Push2 display

This commit is contained in:
Paul Davis
2016-09-16 13:17:24 -05:00
parent 8cc94e79ac
commit b835486170
9 changed files with 73 additions and 24 deletions

View File

@@ -21,12 +21,17 @@
#include <cairomm/surface.h>
#include <cairomm/context.h>
#include "pbd/compose.h"
#include "ardour/debug.h"
#include "canvas.h"
#include "layout.h"
#include "push2.h"
using namespace ArdourCanvas;
using namespace ArdourSurface;
using namespace PBD;
const int Push2Canvas::pixels_per_row = 1024;
@@ -62,6 +67,7 @@ Push2Canvas::vblank ()
/* re-render dirty areas, if any */
if (expose ()) {
DEBUG_TRACE (DEBUG::Push2, "re-blit to device frame buffer\n");
/* something rendered, update device_frame_buffer */
blit_to_device_frame_buffer ();
}
@@ -94,11 +100,13 @@ Push2Canvas::request_redraw (Rect const & r)
{
Cairo::RectangleInt cr;
cr.x = r.x1;
cr.y = r.y1;
cr.x = r.x0;
cr.y = r.y0;
cr.width = r.width();
cr.width = r.height();
DEBUG_TRACE (DEBUG::Push2, string_compose ("invalidate rect %1\n", r));
expose_region->do_union (cr);
/* next vblank will redraw */
@@ -115,6 +123,8 @@ Push2Canvas::expose ()
const int nrects = expose_region->get_num_rectangles ();
DEBUG_TRACE (DEBUG::Push2, string_compose ("expose with %1 rects\n", nrects));
for (int n = 0; n < nrects; ++n) {
Cairo::RectangleInt r = expose_region->get_rectangle (n);
context->rectangle (r.x, r.y, r.width, r.height);
@@ -126,11 +136,17 @@ Push2Canvas::expose ()
if (layout) {
Cairo::RectangleInt r = expose_region->get_extents();
Rect rr (r.x, r.y, r.x + r.width, r.y + r.height);
DEBUG_TRACE (DEBUG::Push2, string_compose ("render layout with %1\n", rr));
layout->render (Rect (r.x, r.y, r.x + r.width, r.y + r.height), context);
}
context->reset_clip ();
/* why is there no "reset()" method for Cairo::Region? */
expose_region = Cairo::Region::create ();
return true;
}
@@ -188,3 +204,16 @@ Push2Canvas::blit_to_device_frame_buffer ()
return 0;
}
void
Push2Canvas::request_size (Duple)
{
/* fixed size canvas */
}
Rect
Push2Canvas::visible_area () const
{
/* may need to get more sophisticated once we do scrolling */
return Rect (0, 0, 960, 160);
}

View File

@@ -47,8 +47,6 @@ class Push2Canvas : public ArdourCanvas::Canvas
void request_redraw (ArdourCanvas::Rect const &);
bool vblank ();
void splash ();
Cairo::RefPtr<Cairo::Context> image_context() { return context; }
int rows() const { return _rows; }

View File

@@ -146,6 +146,8 @@ MixLayout::show ()
void
MixLayout::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const
{
DEBUG_TRACE (DEBUG::Push2, string_compose ("mix render %1\n", area));
set_source_rgb (context, p2.get_color (Push2::DarkBackground));
context->rectangle (0, 0, display_width(), display_height());
context->fill ();

View File

@@ -51,6 +51,7 @@
#include "mix.h"
#include "push2.h"
#include "scale.h"
#include "splash.h"
#include "track_mix.h"
#include "pbd/i18n.h"
@@ -126,7 +127,6 @@ Push2::Push2 (ARDOUR::Session& s)
, _modifier_state (None)
, splash_start (0)
, _current_layout (0)
, drawn_layout (0)
, connection_state (ConnectionState (0))
, gui (0)
, _mode (MusicalMode::IonianMajor)
@@ -228,10 +228,11 @@ Push2::open ()
}
try {
_canvas = new Push2Canvas (*this, 160, 960);
_canvas = new Push2Canvas (*this, 960, 160);
mix_layout = new MixLayout (*this, *session);
scale_layout = new ScaleLayout (*this, *session);
track_mix_layout = new TrackMixLayout (*this, *session);
splash_layout = new SplashLayout (*this, *session);
} catch (...) {
error << _("Cannot construct Canvas for display") << endmsg;
libusb_release_interface (handle, 0x00);
@@ -279,8 +280,6 @@ Push2::open ()
connect_to_parser ();
_canvas->splash ();
return 0;
}
@@ -317,12 +316,17 @@ Push2::close ()
periodic_connection.disconnect ();
session_connections.drop_connections ();
_current_layout = 0;
drawn_layout = 0;
if (_current_layout) {
_canvas->root()->remove (_current_layout);
_current_layout = 0;
}
delete mix_layout;
mix_layout = 0;
delete scale_layout;
scale_layout = 0;
delete splash_layout;
splash_layout = 0;
if (handle) {
libusb_release_interface (handle, 0x00);
@@ -449,6 +453,14 @@ Push2::stop ()
return 0;
}
void
Push2::splash ()
{
set_current_layout (splash_layout);
splash_start = get_microseconds ();
}
bool
Push2::vblank ()
{
@@ -458,15 +470,13 @@ Push2::vblank ()
if (get_microseconds() - splash_start > 3000000) {
splash_start = 0;
DEBUG_TRACE (DEBUG::Push2, "splash interval ended, switch to mix layout\n");
set_current_layout (mix_layout);
}
return true;
} else {
_canvas->vblank();
}
_canvas->vblank();
return true;
}
@@ -519,7 +529,6 @@ Push2::set_active (bool yn)
init_touch_strip ();
set_pad_scale (_scale_root, _root_octave, _mode, _in_key);
splash ();
set_current_layout (mix_layout);
} else {
@@ -1106,11 +1115,6 @@ Push2::end_shift ()
}
}
void
Push2::splash ()
{
}
bool
Push2::pad_filter (MidiBuffer& in, MidiBuffer& out) const
{
@@ -1600,6 +1604,8 @@ Push2::set_current_layout (Push2Layout* layout)
_current_layout->show ();
_canvas->root()->add (_current_layout);
}
_canvas->request_redraw ();
}
void

View File

@@ -515,10 +515,10 @@ class Push2 : public ARDOUR::ControlProtocol
mutable Glib::Threads::Mutex layout_lock;
Push2Layout* _current_layout;
Push2Layout* drawn_layout;
Push2Layout* mix_layout;
Push2Layout* scale_layout;
Push2Layout* track_mix_layout;
Push2Layout* splash_layout;
void set_current_layout (Push2Layout*);
bool pad_filter (ARDOUR::MidiBuffer& in, ARDOUR::MidiBuffer& out) const;

View File

@@ -67,6 +67,8 @@ ScaleLayout::~ScaleLayout ()
void
ScaleLayout::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const
{
DEBUG_TRACE (DEBUG::Push2, string_compose ("scale render %1\n", area));
context->set_source_rgb (0.764, 0.882, 0.882);
context->rectangle (0, 0, 960, 160);
context->fill ();

View File

@@ -24,6 +24,7 @@
#include "pbd/i18n.h"
#include "pbd/search_path.h"
#include "ardour/debug.h"
#include "ardour/filesystem_paths.h"
#include "splash.h"
@@ -50,9 +51,15 @@ SplashLayout::SplashLayout (Push2& p, Session& s)
img = Cairo::ImageSurface::create_from_png (splash_file);
}
SplashLayout::~SplashLayout ()
{
}
void
SplashLayout::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const
{
DEBUG_TRACE (DEBUG::Push2, string_compose ("splash render %1\n", area));
int rows = display_height ();
int cols = display_width ();

View File

@@ -38,6 +38,9 @@ class SplashLayout : public Push2Layout
void render (ArdourCanvas::Rect const &, Cairo::RefPtr<Cairo::Context>) const;
void strip_vpot (int, int) {}
void strip_vpot_touch (int, bool) {}
private:
Cairo::RefPtr<Cairo::ImageSurface> img;
};

View File

@@ -146,6 +146,8 @@ TrackMixLayout::show ()
void
TrackMixLayout::render (ArdourCanvas::Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
{
DEBUG_TRACE (DEBUG::Push2, string_compose ("track mix render %1\n", area));
set_source_rgb (context, p2.get_color (Push2::DarkBackground));
context->rectangle (0, 0, display_width(), display_height());
context->fill ();