globally change all use of "frame" to refer to audio into "sample".
[ardour.git] / libs / surfaces / push2 / canvas.h
1 /*
2     Copyright (C) 2016 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __ardour_push2_canvas_h__
21 #define __ardour_push2_canvas_h__
22
23 #include <cairomm/refptr.h>
24 #include <glibmm/threads.h>
25
26 #include "canvas/canvas.h"
27
28 namespace Cairo {
29         class ImageSurface;
30         class Context;
31         class Region;
32 }
33
34 namespace ArdourSurface {
35
36 class Push2;
37
38 /* A canvas which renders to the Push2 display */
39
40 class Push2Canvas : public ArdourCanvas::Canvas
41 {
42   public:
43         Push2Canvas (Push2& p2, int cols, int rows);
44         ~Push2Canvas();
45
46         void request_redraw ();
47         void request_redraw (ArdourCanvas::Rect const &);
48         bool vblank ();
49
50         Cairo::RefPtr<Cairo::Context> image_context() { return context; }
51
52         int rows() const { return _rows; }
53         int cols() const { return _cols; }
54
55         static double inter_button_spacing() { return 120.0; }
56
57         ArdourCanvas::Coord width() const { return cols(); }
58         ArdourCanvas::Coord height() const { return rows(); }
59         void request_size (ArdourCanvas::Duple);
60         ArdourCanvas::Rect visible_area () const;
61
62         /* API that does nothing since we have no input events */
63         void ungrab () {}
64         void grab (ArdourCanvas::Item*) {}
65         void focus (ArdourCanvas::Item*) {}
66         void unfocus (ArdourCanvas::Item*) {}
67         void re_enter() {}
68         void pick_current_item (int) {}
69         void pick_current_item (ArdourCanvas::Duple const &, int) {}
70         bool get_mouse_position (ArdourCanvas::Duple&) const { return false; }
71
72         Glib::RefPtr<Pango::Context> get_pango_context ();
73
74   private:
75         Push2& p2;
76         int _cols;
77         int _rows;
78
79         static const int pixels_per_row;
80         int pixel_area () const { return _rows * pixels_per_row; }
81
82         uint8_t   sample_header[16];
83         uint16_t* device_sample_buffer;
84
85         Cairo::RefPtr<Cairo::ImageSurface> sample_buffer;
86         Cairo::RefPtr<Cairo::Context> context;
87         Cairo::RefPtr<Cairo::Region> expose_region;
88         Glib::RefPtr<Pango::Context> pango_context;
89
90         bool expose ();
91         int blit_to_device_sample_buffer ();
92 };
93
94 } /* namespace ArdourSurface */
95
96 #endif /* __ardour_push2_canvas_h__ */