Move Export Audition Buttons to the bottom
[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                 , _highlight (false)
39         {
40                 set_size_request (sf->get_width (), sf->get_height ());
41         }
42
43         virtual void render (cairo_t* cr, cairo_rectangle_t* r)
44         {
45                 cairo_rectangle (cr, r->x, r->y, r->width, r->height);
46                 cairo_clip (cr);
47                 cairo_set_source_surface (cr, _surface->cobj(), 0, 0);
48                 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
49                 cairo_paint (cr);
50
51                 if (_playhead > 0 && _playhead < 1.0 && _aw > 0) {
52                         if (_highlight) {
53                                 cairo_rectangle (cr, _x0, 0, _aw, _surface->get_height());
54                                 cairo_set_source_rgba (cr, .4, .4, .6, .4);
55                                 cairo_fill (cr);
56                         }
57
58                         const float x = _playhead * _aw;
59                         const float h = _surface->get_height();
60                         cairo_set_source_rgba (cr, 1, 0, 0, 1);
61                         cairo_set_line_width (cr, 1.5);
62                         cairo_move_to (cr, _x0 + x, 0);
63                         cairo_line_to (cr, _x0 + x, h);
64                         cairo_stroke (cr);
65                 }
66         }
67
68         void set_playhead (float pos) {
69                 if (rint (_playhead * _aw) == rint (pos * _aw)) {
70                         return;
71                 }
72                 if (_playhead == -1 || pos == -1) {
73                         set_dirty ();
74                 } else {
75                         invalidate (_playhead);
76                         invalidate (pos);
77                 }
78                 _playhead = pos;
79         }
80
81         void set_audition_axis (float x0, float w, bool h = false) {
82                 _x0 = x0;
83                 _aw = w;
84                 _highlight = h;
85         }
86
87         sigc::signal<void, float> seek_playhead;
88
89 protected:
90         bool on_button_press_event (GdkEventButton *ev) {
91                 CairoWidget::on_button_press_event (ev);
92                 if (ev->button == 1 && _aw > 0 && ev->x >= _x0 && ev->x <= _x0 + _aw) {
93                         seek_playhead (((float) ev->x - _x0) / (float)_aw);
94                 }
95                 return true;
96         }
97
98 private:
99         Cairo::RefPtr<Cairo::ImageSurface> _surface;
100         float _playhead;
101         float _x0, _aw;
102         bool _highlight;
103
104         void invalidate (float pos) {
105                 if (pos < 0 || pos > 1) { return; }
106                 const float x = pos * _aw;
107                 cairo_rectangle_t r;
108                 r.y = 0;
109                 r.x = _x0 + x - 1;
110                 r.width = 3;
111                 r.height = _surface->get_height();
112                 set_dirty (&r);
113         }
114 };
115
116 class ExportReport : public ArdourDialog
117 {
118 public:
119         typedef boost::shared_ptr<ARDOUR::ExportStatus> StatusPtr;
120         ExportReport (ARDOUR::Session*, StatusPtr);
121         int run ();
122
123 private:
124         void open_folder (std::string);
125         void audition (std::string, unsigned int, int);
126         void stop_audition ();
127         void play_audition ();
128         void audition_active (bool);
129         void audition_seek (int, float);
130         void audition_progress (ARDOUR::framecnt_t, ARDOUR::framecnt_t);
131         void on_switch_page (GtkNotebookPage*, guint page_num);
132
133         StatusPtr        status;
134         Gtk::Notebook    pages;
135         ARDOUR::Session* _session;
136         Gtk::Button*     stop_btn;
137         Gtk::Button*     play_btn;
138         PBD::ScopedConnectionList auditioner_connections;
139
140         struct AuditionInfo {
141                 AuditionInfo (std::string p, unsigned int c) : path (p), channels (c) {}
142                 AuditionInfo () : channels (0) {}
143                 std::string  path;
144                 unsigned int channels;
145         };
146
147         std::map<int, std::list<CimgArea*> > timeline;
148         std::map<int, AuditionInfo> files;
149
150         int _audition_num;
151         int _page_num;
152 };