2 * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
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.
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.
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.
19 #include <cairo/cairo.h>
20 #include <gtkmm/notebook.h>
21 #include <gtkmm/togglebutton.h>
23 #include "gtkmm2ext/cairo_widget.h"
24 #include "gtkmm2ext/gui_thread.h"
26 #include "ardour/export_status.h"
28 #include "ardour_dialog.h"
30 class CimgArea : public CairoWidget
33 CimgArea (Cairo::RefPtr<Cairo::ImageSurface> sf)
37 set_size_request (sf->get_width (), sf->get_height ());
41 virtual void background (cairo_t* cr, cairo_rectangle_t* r) {
42 cairo_set_source_surface (cr, _surface->cobj(), 0, 0);
43 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
47 virtual void overlay (cairo_t* cr, cairo_rectangle_t* r) {}
49 virtual void render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t* r)
51 ctx->rectangle (r->x, r->y, r->width, r->height);
53 background (ctx->cobj(), r);
54 overlay (ctx->cobj(), r);
57 Cairo::RefPtr<Cairo::ImageSurface> _surface;
60 class CimgPlayheadArea : public CimgArea
63 CimgPlayheadArea (Cairo::RefPtr<Cairo::ImageSurface> sf, float x0, float w, bool h = false)
72 void set_playhead (float pos) {
73 if (rint (_playhead * _aw) == rint (pos * _aw)) {
76 if (_playhead == -1 || pos == -1) {
79 invalidate (_playhead);
85 sigc::signal<void, float> seek_playhead;
89 virtual void overlay (cairo_t* cr, cairo_rectangle_t* r) {
90 if (_playhead > 0 && _playhead < 1.0 && _aw > 0) {
92 cairo_rectangle (cr, _x0, 0, _aw, _surface->get_height());
93 cairo_set_source_rgba (cr, .4, .4, .6, .4);
97 const float x = _playhead * _aw;
98 const float h = _surface->get_height();
99 cairo_set_source_rgba (cr, 1, 0, 0, 1);
100 cairo_set_line_width (cr, 1.5);
101 cairo_move_to (cr, _x0 + x, 0);
102 cairo_line_to (cr, _x0 + x, h);
107 bool on_button_press_event (GdkEventButton *ev) {
108 CairoWidget::on_button_press_event (ev);
109 if (ev->button == 1 && _aw > 0 && ev->x >= _x0 && ev->x <= _x0 + _aw) {
110 seek_playhead (((float) ev->x - _x0) / (float)_aw);
120 void invalidate (float pos) {
121 if (pos < 0 || pos > 1) { return; }
122 const float x = pos * _aw;
127 r.height = _surface->get_height();
132 class CimgWaveArea : public CimgPlayheadArea
136 Cairo::RefPtr<Cairo::ImageSurface> sf,
137 Cairo::RefPtr<Cairo::ImageSurface> sf_log,
138 Cairo::RefPtr<Cairo::ImageSurface> sf_rect,
139 Cairo::RefPtr<Cairo::ImageSurface> sf_logrec,
141 : CimgPlayheadArea (sf, x0, w)
144 , _sf_logrec (sf_logrec)
150 void set_logscale (bool en) {
155 void set_rectified (bool en) {
162 virtual void background (cairo_t* cr, cairo_rectangle_t* r) {
163 if (_logscale && _rectified) {
164 cairo_set_source_surface (cr, _sf_logrec->cobj(), 0, 0);
165 } else if (_logscale) {
166 cairo_set_source_surface (cr, _sf_log->cobj(), 0, 0);
167 } else if (_rectified) {
168 cairo_set_source_surface (cr, _sf_rect->cobj(), 0, 0);
170 cairo_set_source_surface (cr, _surface->cobj(), 0, 0);
172 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
177 Cairo::RefPtr<Cairo::ImageSurface> _sf_log;
178 Cairo::RefPtr<Cairo::ImageSurface> _sf_rect;
179 Cairo::RefPtr<Cairo::ImageSurface> _sf_logrec;
184 class ExportReport : public ArdourDialog
187 typedef boost::shared_ptr<ARDOUR::ExportStatus> StatusPtr;
188 ExportReport (ARDOUR::Session*, StatusPtr);
189 ExportReport (const std::string & title, const ARDOUR::AnalysisResults & ar);
192 void on_response (int response_id) {
193 Gtk::Dialog::on_response (response_id);
197 void init (const ARDOUR::AnalysisResults &, bool);
198 void draw_waveform (Cairo::RefPtr<Cairo::ImageSurface>& wave,
199 ARDOUR::ExportAnalysisPtr, uint32_t, int, size_t, int, int, bool, bool);
201 void open_folder (std::string);
202 void audition (std::string, unsigned int, int);
203 void stop_audition ();
204 void play_audition ();
205 void audition_active (bool);
206 void audition_seek (int, float);
207 void audition_progress (ARDOUR::framecnt_t, ARDOUR::framecnt_t);
208 void on_switch_page (GtkNotebookPage*, guint page_num);
209 void on_logscale_toggled (Gtk::ToggleButton*);
210 void on_rectivied_toggled (Gtk::ToggleButton*);
213 ARDOUR::Session* _session;
214 Gtk::Button* stop_btn;
215 Gtk::Button* play_btn;
216 PBD::ScopedConnectionList auditioner_connections;
218 struct AuditionInfo {
219 AuditionInfo (std::string p, unsigned int c) : path (p), channels (c) {}
220 AuditionInfo () : channels (0) {}
222 unsigned int channels;
225 std::map<int, std::list<CimgPlayheadArea*> > timeline;
226 std::map<int, AuditionInfo> files;
227 std::list<CimgWaveArea*> waves;