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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2610 - (hide annotations) (download)
Sun Jun 8 19:09:26 2014 UTC (9 years, 10 months ago) by schoenebeck
File size: 6002 byte(s)
* GIG SOUND FORMAT EXTENSION: Added support for managing script slots for
  instruments. Script slots define which scripts shall be executed for an
  instrument by the sampler and in which order.

1 schoenebeck 2610 /*
2     Copyright (c) 2014 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     } else {
115     // drop failed
116     context->drop_reply(false, time);
117     }
118     }
119    
120     void ScriptSlots::appendNewSlot(gig::Script* script) {
121     static int slotID = 0;
122    
123     Row row;
124     row.id = slotID++;
125     row.hbox = new Gtk::HBox;
126     row.label = new Gtk::Label;
127     row.downButton = new Gtk::Button(Gtk::Stock::GO_DOWN);
128     row.upButton = new Gtk::Button(Gtk::Stock::GO_UP);
129     row.deleteButton = new Gtk::Button(Gtk::Stock::DELETE);
130     row.script = script;
131    
132     row.hbox->pack_start(*row.label);
133     row.hbox->pack_start(*row.downButton, Gtk::PACK_SHRINK);
134     row.hbox->pack_start(*row.upButton, Gtk::PACK_SHRINK);
135     row.hbox->pack_start(*row.deleteButton, Gtk::PACK_SHRINK);
136    
137     row.label->set_text(ToString(m_slots.size()+1) + ". \"" + script->Name + "\"");
138     //row.label->set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
139    
140     row.upButton->signal_clicked().connect(
141     sigc::bind(
142     sigc::mem_fun(*this, &ScriptSlots::moveSlotUp), row.id
143     )
144     );
145     row.downButton->signal_clicked().connect(
146     sigc::bind(
147     sigc::mem_fun(*this, &ScriptSlots::moveSlotDown), row.id
148     )
149     );
150     row.deleteButton->signal_clicked().connect(
151     sigc::bind(
152     sigc::mem_fun(*this, &ScriptSlots::deleteSlot), row.id
153     )
154     );
155    
156     m_vboxSlots.add(*row.hbox);
157     m_scrolledWindow.show_all_children();
158    
159     m_slots.push_back(row);
160     }
161    
162     void ScriptSlots::moveSlotUp(int slotID) {
163     for (int i = 0; i < m_instrument->ScriptSlotCount(); ++i) {
164     if (m_slots[i].id == slotID) {
165     if (i != 0) {
166     m_instrument->SwapScriptSlots(i, i-1);
167     refreshSlots();
168     }
169     break;
170     }
171     }
172     }
173    
174     void ScriptSlots::moveSlotDown(int slotID) {
175     for (int i = 0; i < m_instrument->ScriptSlotCount(); ++i) {
176     if (m_slots[i].id == slotID) {
177     if (i < m_instrument->ScriptSlotCount() - 1) {
178     m_instrument->SwapScriptSlots(i, i+1);
179     refreshSlots();
180     }
181     break;
182     }
183     }
184     }
185    
186     void ScriptSlots::deleteSlot(int slotID) {
187     for (int i = 0; i < m_instrument->ScriptSlotCount(); ++i) {
188     if (m_slots[i].id == slotID) {
189     m_instrument->RemoveScriptSlot(i);
190     refreshSlots();
191     break;
192     }
193     }
194     }
195    
196     void ScriptSlots::onButtonClose() {
197     hide();
198     }
199    
200     void ScriptSlots::onWindowHide() {
201     delete this; // this is the end, my friend
202     }
203    

  ViewVC Help
Powered by ViewVC