2 Copyright (C) 2010 Paul Davis
3 Author: Carl Hetherington <cth@carlh.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <gtkmm/stock.h>
22 #include <gtkmm/table.h>
23 #include "ardour/beats_frames_converter.h"
24 #include "patch_change_dialog.h"
28 /** @param tc If non-0, a time converter for this patch change. If 0, time and channel controls will be desensitized */
29 PatchChangeDialog::PatchChangeDialog (
30 const ARDOUR::BeatsFramesConverter* tc,
31 ARDOUR::Session* session,
32 Evoral::PatchChange<Evoral::MusicalTime> const & patch,
33 const Gtk::BuiltinStockID& ok
35 : ArdourDialog (_("Patch Change"), true)
36 , _time_converter (tc)
37 , _time (X_("patchchangetime"), true, X_("PatchChangeTimeClock"), true, false)
38 , _channel (*manage (new Adjustment (1, 1, 16, 1, 4)))
39 , _program (*manage (new Adjustment (1, 1, 128, 1, 16)))
40 , _bank (*manage (new Adjustment (1, 1, 16384, 1, 64)))
42 Table* t = manage (new Table (4, 2));
46 if (_time_converter) {
48 Label* l = manage (new Label (_("Time")));
49 l->set_alignment (0, 0.5);
50 t->attach (*l, 0, 1, r, r + 1);
51 t->attach (_time, 1, 2, r, r + 1);
54 _time.set_session (session);
55 _time.set_mode (AudioClock::BBT);
56 _time.set (_time_converter->to (patch.time ()), true);
58 l = manage (new Label (_("Channel")));
59 l->set_alignment (0, 0.5);
60 t->attach (*l, 0, 1, r, r + 1);
61 t->attach (_channel, 1, 2, r, r + 1);
64 _channel.set_value (patch.channel() + 1);
67 Label* l = manage (new Label (_("Program")));
68 l->set_alignment (0, 0.5);
69 t->attach (*l, 0, 1, r, r + 1);
70 t->attach (_program, 1, 2, r, r + 1);
73 _program.set_value (patch.program () + 1);
75 l = manage (new Label (_("Bank")));
76 l->set_alignment (0, 0.5);
77 t->attach (*l, 0, 1, r, r + 1);
78 t->attach (_bank, 1, 2, r, r + 1);
81 _bank.set_value (patch.bank() + 1);
85 add_button (Stock::CANCEL, RESPONSE_CANCEL);
86 add_button (ok, RESPONSE_ACCEPT);
87 set_default_response (RESPONSE_ACCEPT);
92 Evoral::PatchChange<Evoral::MusicalTime>
93 PatchChangeDialog::patch () const
95 Evoral::MusicalTime t = 0;
96 if (_time_converter) {
97 t = _time_converter->from (_time.current_time ());
100 return Evoral::PatchChange<Evoral::MusicalTime> (
102 _channel.get_value_as_int() - 1,
103 _program.get_value_as_int() - 1,
104 _bank.get_value_as_int() - 1