Missing files.
[ardour.git] / gtk2_ardour / patch_change_dialog.cc
1 /*
2     Copyright (C) 2010 Paul Davis
3     Author: Carl Hetherington <cth@carlh.net>
4
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.
9
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.
14
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.
18
19 */
20
21 #include <gtkmm/stock.h>
22 #include <gtkmm/table.h>
23 #include "ardour/beats_frames_converter.h"
24 #include "patch_change_dialog.h"
25
26 using namespace Gtk;
27
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
34         )
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)))
41 {
42         Table* t = manage (new Table (4, 2));
43         t->set_spacings (6);
44         int r = 0;
45
46         if (_time_converter) {
47
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);
52                 ++r;
53                 
54                 _time.set_session (session);
55                 _time.set_mode (AudioClock::BBT);
56                 _time.set (_time_converter->to (patch.time ()), true);
57                 
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);
62                 ++r;
63                 
64                 _channel.set_value (patch.channel() + 1);
65         }
66         
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);
71         ++r;
72         
73         _program.set_value (patch.program () + 1);
74
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);
79         ++r;
80         
81         _bank.set_value (patch.bank() + 1);
82         
83         get_vbox()->add (*t);
84
85         add_button (Stock::CANCEL, RESPONSE_CANCEL);
86         add_button (ok, RESPONSE_ACCEPT);
87         set_default_response (RESPONSE_ACCEPT);
88
89         show_all ();
90 }
91
92 Evoral::PatchChange<Evoral::MusicalTime>
93 PatchChangeDialog::patch () const
94 {
95         Evoral::MusicalTime t = 0;
96         if (_time_converter) {
97                 t = _time_converter->from (_time.current_time ());
98         }
99         
100         return Evoral::PatchChange<Evoral::MusicalTime> (
101                 t,
102                 _channel.get_value_as_int() - 1,
103                 _program.get_value_as_int() - 1,
104                 _bank.get_value_as_int() - 1
105                 );
106 }