/[svn]/gigedit/trunk/src/gigedit/scriptslots.cpp
ViewVC logotype

Contents of /gigedit/trunk/src/gigedit/scriptslots.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3197 - (show annotations) (download)
Sat May 20 17:15:36 2017 UTC (6 years, 10 months ago) by schoenebeck
File size: 6414 byte(s)
* Instruments list view: show amount of real-time instruments scripts used
  by instrument.
* Bumped version (1.0.0.svn49).

1 /*
2 Copyright (c) 2014 - 2017 Christian Schoenebeck
3
4 This file is part of "gigedit" and released under the terms of the
5 GNU General Public License version 2.
6 */
7
8 #include "scriptslots.h"
9 #include "global.h"
10
11 ScriptSlots::ScriptSlots() :
12 m_closeButton(Gtk::Stock::CLOSE)
13 {
14 m_instrument = NULL;
15
16 add(m_vbox);
17
18 m_generalInfoLabel.set_text(_(
19 "Each row (\"slot\") references one instrument script that shall be "
20 "executed by the sampler for currently selected instrument. Slots are "
21 "executed consecutively from top down."
22 ));
23 m_generalInfoLabel.set_line_wrap();
24 m_vbox.pack_start(m_generalInfoLabel, Gtk::PACK_SHRINK);
25
26 m_dragHintLabel.set_text(_(
27 "Drag & drop a script from main window to this window to add a new "
28 "script slot for this instrument."
29 ));
30 m_dragHintLabel.set_line_wrap();
31 m_scrolledWindow.add(m_vboxSlots);
32 m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
33 m_vbox.pack_start(m_scrolledWindow);
34
35 m_vbox.pack_start(m_dragHintLabel, Gtk::PACK_SHRINK);
36
37 m_buttonBox.set_layout(Gtk::BUTTONBOX_END);
38 m_buttonBox.pack_start(m_closeButton);
39 m_closeButton.set_can_default();
40 m_closeButton.grab_focus();
41 m_vbox.pack_start(m_buttonBox, Gtk::PACK_SHRINK);
42
43 m_closeButton.signal_clicked().connect(
44 sigc::mem_fun(*this, &ScriptSlots::onButtonClose)
45 );
46
47 signal_hide().connect(
48 sigc::mem_fun(*this, &ScriptSlots::onWindowHide)
49 );
50
51 // establish drag&drop between scripts tree view on main diwno and this
52 // ScriptSlots window
53 std::vector<Gtk::TargetEntry> drag_target_gig_script;
54 drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
55 drag_dest_set(drag_target_gig_script);
56 signal_drag_data_received().connect(
57 sigc::mem_fun(*this, &ScriptSlots::onScriptDragNDropDataReceived)
58 );
59
60 show_all_children();
61
62 resize(460,300);
63 }
64
65 ScriptSlots::~ScriptSlots() {
66 //printf("ScriptSlots destruct\n");
67 clearSlots();
68 }
69
70 void ScriptSlots::clearSlots() {
71 for (int i = 0; i < m_slots.size(); ++i) {
72 delete m_slots[i].deleteButton;
73 delete m_slots[i].downButton;
74 delete m_slots[i].upButton;
75 delete m_slots[i].label;
76 delete m_slots[i].hbox;
77 }
78 m_slots.clear();
79 }
80
81 void ScriptSlots::setInstrument(gig::Instrument* instrument) {
82 m_instrument = instrument;
83 if (!m_instrument) {
84 set_title(_("No Instrument"));
85 return;
86 }
87
88 set_title(std::string(_("Script Slots of Instrument")) + " - \"" + instrument->pInfo->Name + "\"");
89 clearSlots();
90 for (int i = 0; i < instrument->ScriptSlotCount(); ++i) {
91 gig::Script* script = instrument->GetScriptOfSlot(i);
92 if (!script) continue;
93 //printf("script '%s'\n", script->Name.c_str());
94 appendNewSlot(script);
95 }
96 }
97
98 void ScriptSlots::refreshSlots() {
99 clearSlots();
100 setInstrument(m_instrument);
101 }
102
103 void ScriptSlots::onScriptDragNDropDataReceived(
104 const Glib::RefPtr<Gdk::DragContext>& context, int, int,
105 const Gtk::SelectionData& selection_data, guint, guint time)
106 {
107 gig::Script* script = *((gig::Script**) selection_data.get_data());
108 if (script && selection_data.get_length() == sizeof(gig::Script*)) {
109 std::cout << "Drop received script \"" << script->Name << "\"" << std::endl;
110 m_instrument->AddScriptSlot(script);
111 appendNewSlot(script);
112 // drop success
113 context->drop_reply(true, time);
114 // inform i.e. main window
115 script_slots_changed_signal.emit(m_instrument);
116 } else {
117 // drop failed
118 context->drop_reply(false, time);
119 }
120 }
121
122 void ScriptSlots::appendNewSlot(gig::Script* script) {
123 static int slotID = 0;
124
125 Row row;
126 row.id = slotID++;
127 row.hbox = new Gtk::HBox;
128 row.label = new Gtk::Label;
129 row.downButton = new Gtk::Button(Gtk::Stock::GO_DOWN);
130 row.upButton = new Gtk::Button(Gtk::Stock::GO_UP);
131 row.deleteButton = new Gtk::Button(Gtk::Stock::DELETE);
132 row.script = script;
133
134 row.hbox->pack_start(*row.label);
135 row.hbox->pack_start(*row.downButton, Gtk::PACK_SHRINK);
136 row.hbox->pack_start(*row.upButton, Gtk::PACK_SHRINK);
137 row.hbox->pack_start(*row.deleteButton, Gtk::PACK_SHRINK);
138
139 row.label->set_text(ToString(m_slots.size()+1) + ". \"" + script->Name + "\"");
140 //row.label->set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
141
142 row.upButton->signal_clicked().connect(
143 sigc::bind(
144 sigc::mem_fun(*this, &ScriptSlots::moveSlotUp), row.id
145 )
146 );
147 row.downButton->signal_clicked().connect(
148 sigc::bind(
149 sigc::mem_fun(*this, &ScriptSlots::moveSlotDown), row.id
150 )
151 );
152 row.deleteButton->signal_clicked().connect(
153 sigc::bind(
154 sigc::mem_fun(*this, &ScriptSlots::deleteSlot), row.id
155 )
156 );
157
158 m_vboxSlots.add(*row.hbox);
159 m_scrolledWindow.show_all_children();
160
161 m_slots.push_back(row);
162 }
163
164 void ScriptSlots::moveSlotUp(int slotID) {
165 for (int i = 0; i < m_instrument->ScriptSlotCount(); ++i) {
166 if (m_slots[i].id == slotID) {
167 if (i != 0) {
168 m_instrument->SwapScriptSlots(i, i-1);
169 refreshSlots();
170 script_slots_changed_signal.emit(m_instrument);
171 }
172 break;
173 }
174 }
175 }
176
177 void ScriptSlots::moveSlotDown(int slotID) {
178 for (int i = 0; i < m_instrument->ScriptSlotCount(); ++i) {
179 if (m_slots[i].id == slotID) {
180 if (i < m_instrument->ScriptSlotCount() - 1) {
181 m_instrument->SwapScriptSlots(i, i+1);
182 refreshSlots();
183 script_slots_changed_signal.emit(m_instrument);
184 }
185 break;
186 }
187 }
188 }
189
190 void ScriptSlots::deleteSlot(int slotID) {
191 for (int i = 0; i < m_instrument->ScriptSlotCount(); ++i) {
192 if (m_slots[i].id == slotID) {
193 m_instrument->RemoveScriptSlot(i);
194 refreshSlots();
195 script_slots_changed_signal.emit(m_instrument);
196 break;
197 }
198 }
199 }
200
201 sigc::signal<void, gig::Instrument*>& ScriptSlots::signal_script_slots_changed() {
202 return script_slots_changed_signal;
203 }
204
205 void ScriptSlots::onButtonClose() {
206 hide();
207 }
208
209 void ScriptSlots::onWindowHide() {
210 delete this; // this is the end, my friend
211 }
212

  ViewVC Help
Powered by ViewVC