Partial exposure of export-audition playhead
[ardour.git] / gtk2_ardour / export_report.h
1 /*
2  * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18
19 #include <cairo/cairo.h>
20 #include <gtkmm/notebook.h>
21
22 #include "gtkmm2ext/cairo_widget.h"
23 #include "gtkmm2ext/gui_thread.h"
24
25 #include "ardour/export_status.h"
26
27 #include "ardour_dialog.h"
28
29 class CimgArea : public CairoWidget
30 {
31 public:
32         CimgArea (Cairo::RefPtr<Cairo::ImageSurface> sf)
33                 : CairoWidget()
34                 , _surface(sf)
35                 , _playhead(-1)
36                 , _x0 (0)
37                 , _aw (0)
38         {
39                 set_size_request (sf->get_width (), sf->get_height ());
40         }
41
42         virtual void render (cairo_t* cr, cairo_rectangle_t* r)
43         {
44                 cairo_rectangle (cr, r->x, r->y, r->width, r->height);
45                 cairo_clip (cr);
46                 cairo_set_source_surface (cr, _surface->cobj(), 0, 0);
47                 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
48                 cairo_paint (cr);
49
50                 if (_playhead > 0 && _playhead < 1.0 && _aw > 0) {
51                         cairo_rectangle (cr, _x0, 0, _aw, _surface->get_height());
52                         cairo_set_source_rgba (cr, .4, .4, .6, .4);
53                         cairo_fill (cr);
54
55                         const float x = _playhead * _aw;
56                         const float h = _surface->get_height();
57                         cairo_set_source_rgba (cr, 1, 0, 0, 1);
58                         cairo_set_line_width (cr, 1.5);
59                         cairo_move_to (cr, _x0 + x, 0);
60                         cairo_line_to (cr, _x0 + x, h);
61                         cairo_stroke (cr);
62                 }
63         }
64
65         void set_playhead (float pos) {
66                 if (rint (_playhead * _aw) == rint (pos * _aw)) {
67                         return;
68                 }
69                 if (_playhead == -1 || pos == -1) {
70                         set_dirty ();
71                 } else {
72                         invalidate (_playhead);
73                         invalidate (pos);
74                 }
75                 _playhead = pos;
76         }
77
78         void set_audition_axis (float x0, float w) {
79                 _x0 = x0;
80                 _aw = w;
81         }
82
83 private:
84         Cairo::RefPtr<Cairo::ImageSurface> _surface;
85         float _playhead;
86         float _x0, _aw;
87
88         void invalidate (float pos) {
89                 if (pos < 0 || pos > 1) { return; }
90                 const float x = pos * _aw;
91                 cairo_rectangle_t r;
92                 r.y = 0;
93                 r.x = _x0 + x - 1;
94                 r.width = 3;
95                 r.height = _surface->get_height();
96                 set_dirty (&r);
97         }
98 };
99
100 class ExportReport : public ArdourDialog
101 {
102 public:
103         typedef boost::shared_ptr<ARDOUR::ExportStatus> StatusPtr;
104         ExportReport (ARDOUR::Session*, StatusPtr);
105         int run ();
106
107 private:
108         void open_folder (std::string);
109         void audition (std::string, unsigned int, int);
110         void stop_audition ();
111         void audition_active (bool);
112         void audition_progress (ARDOUR::framecnt_t, ARDOUR::framecnt_t);
113         void on_switch_page (GtkNotebookPage*, guint page_num);
114
115         StatusPtr        status;
116         Gtk::Notebook    pages;
117         ARDOUR::Session* _session;
118         Gtk::Button*     stop_btn;
119         PBD::ScopedConnectionList auditioner_connections;
120
121         std::vector<CimgArea*> timeline;
122         int _audition_num;
123         int _page_num;
124 };