summaryrefslogtreecommitdiff
path: root/gtk2_ardour/patch_change_dialog.cc
blob: 475ae1f6a47e130e3bc393bb604d285a0aeaab4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
    Copyright (C) 2010 Paul Davis
    Author: Carl Hetherington <cth@carlh.net>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#include <gtkmm/stock.h>
#include <gtkmm/table.h>
#include "ardour/beats_frames_converter.h"
#include "patch_change_dialog.h"
#include "i18n.h"

using namespace Gtk;

/** @param tc If non-0, a time converter for this patch change.  If 0, time control will be desensitized */
PatchChangeDialog::PatchChangeDialog (
	const ARDOUR::BeatsFramesConverter* tc,
	ARDOUR::Session* session,
	Evoral::PatchChange<Evoral::MusicalTime> const & patch,
	const Gtk::BuiltinStockID& ok
	)
	: ArdourDialog (_("Patch Change"), true)
	, _time_converter (tc)
	, _time (X_("patchchangetime"), true, X_("PatchChangeTimeClock"), true, false)
	, _channel (*manage (new Adjustment (1, 1, 16, 1, 4)))
	, _program (*manage (new Adjustment (1, 1, 128, 1, 16)))
	, _bank (*manage (new Adjustment (1, 1, 16384, 1, 64)))
{
	Table* t = manage (new Table (4, 2));
	Label* l;
	t->set_spacings (6);
	int r = 0;

	if (_time_converter) {
		
		l = manage (new Label (_("Time")));
		l->set_alignment (0, 0.5);
		t->attach (*l, 0, 1, r, r + 1);
		t->attach (_time, 1, 2, r, r + 1);
		++r;

		_time.set_session (session);
		_time.set_mode (AudioClock::BBT);
		_time.set (_time_converter->to (patch.time ()), true);
	}

	l = manage (new Label (_("Channel")));
	l->set_alignment (0, 0.5);
	t->attach (*l, 0, 1, r, r + 1);
	t->attach (_channel, 1, 2, r, r + 1);
	++r;
	
	_channel.set_value (patch.channel() + 1);

	l = manage (new Label (_("Program")));
	l->set_alignment (0, 0.5);
	t->attach (*l, 0, 1, r, r + 1);
	t->attach (_program, 1, 2, r, r + 1);
	++r;

	_program.set_value (patch.program () + 1);

	l = manage (new Label (_("Bank")));
	l->set_alignment (0, 0.5);
	t->attach (*l, 0, 1, r, r + 1);
	t->attach (_bank, 1, 2, r, r + 1);
	++r;

	_bank.set_value (patch.bank() + 1);

	get_vbox()->add (*t);

	add_button (Stock::CANCEL, RESPONSE_CANCEL);
	add_button (ok, RESPONSE_ACCEPT);
	set_default_response (RESPONSE_ACCEPT);

	show_all ();
}

Evoral::PatchChange<Evoral::MusicalTime>
PatchChangeDialog::patch () const
{
	Evoral::MusicalTime t = 0;

	if (_time_converter) {
		t = _time_converter->from (_time.current_time ());
	}

	return Evoral::PatchChange<Evoral::MusicalTime> (
		t,
		_channel.get_value_as_int() - 1,
		_program.get_value_as_int() - 1,
		_bank.get_value_as_int() - 1
		);
}