File: add_effect_dialog.cpp

package info (click to toggle)
zytrax 0%2Bgit20201215-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 2,488 kB
  • sloc: cpp: 41,800; ansic: 3,387; makefile: 8; sh: 3
file content (90 lines) | stat: -rw-r--r-- 2,937 bytes parent folder | download | duplicates (2)
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
#include "add_effect_dialog.h"

void AddEffectDialog::_selection_changed() {

	Gtk::TreeModel::iterator iter = tree_selection->get_selected();
	if (!iter)
		return;
	Gtk::TreeModel::Row row = *iter;
	int selected = row[model_columns.index];

	const AudioEffectInfo *info = fx_factory->get_audio_effect(selected);
	String text;
	text = "Name: " + info->caption + "\n";
	text += String() + "Type: " + (info->synth ? "Synth" : "Effect") + "\n";
	text += "Provider: " + info->provider_caption + "\n";
	if (info->category != String())
		text += "Category: " + info->category + "\n";
	if (info->author != String())
		text += "Author: " + info->author + "\n";
	if (info->description != String())
		text += "Description:\n" + info->description;

	description_text->set_text(text.utf8().get_data());
}

void AddEffectDialog::_activated(const Gtk::TreeModel::Path &, Gtk::TreeViewColumn *p_column) {

	response(Gtk::RESPONSE_OK);
}

int AddEffectDialog::get_selected_effect_index() {

	Gtk::TreeModel::iterator iter = tree_selection->get_selected();
	if (!iter)
		return -1;
	Gtk::TreeModel::Row row = *iter;
	return row[model_columns.index];
}

void AddEffectDialog::update_effect_list() {

	list_store->clear();

	for (int i = 0; i < fx_factory->get_audio_effect_count(); i++) {

		Gtk::TreeModel::iterator iter = list_store->append();
		Gtk::TreeModel::Row row = *iter;

		row[model_columns.name] = fx_factory->get_audio_effect(i)->caption.utf8().get_data();
		row[model_columns.provider] = fx_factory->get_audio_effect(i)->provider_caption.utf8().get_data();
		row[model_columns.index] = i;
	}
}

AddEffectDialog::AddEffectDialog(AudioEffectFactory *p_fx_factory) :
		Gtk::MessageDialog("", false /* use_markup */, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_OK_CANCEL) {
	set_title("Choose Effect");
	fx_factory = p_fx_factory;
	Gtk::Box &vbox = *get_vbox();
	//add(vbox);
	description_text = Gtk::TextBuffer::create();
	vbox.pack_start(scroll, Gtk::PACK_EXPAND_WIDGET);
	scroll.add(tree);
	description_label.set_label("Effect Description");
	vbox.pack_start(description_label, Gtk::PACK_SHRINK);
	vbox.pack_start(description, Gtk::PACK_SHRINK);
	description.set_buffer(description_text);

	show_all_children();
	vbox.get_children()[0]->hide();
	vbox.set_spacing(0);

	list_store = Gtk::ListStore::create(model_columns);
	tree_selection = tree.get_selection();
	tree_selection->signal_changed().connect(sigc::mem_fun(this, &AddEffectDialog::_selection_changed));

	tree.set_model(list_store);
	tree.append_column("Effect", model_columns.name);
	tree.get_column(0)->set_expand(true);
	tree.append_column("Provider", model_columns.provider);
	tree.get_column(1)->set_expand(false);

	tree.signal_row_activated().connect(sigc::mem_fun(this, &AddEffectDialog::_activated));

	Glib::RefPtr<Gdk::Screen> screen = Gdk::Screen::get_default();
	int width = screen->get_width();
	int height = screen->get_height();

	set_default_size(width / 4, height / 2);
}