1 //=========================================================
2 //  MusE
3 //  Linux Music Editor
4 //    $Id: crescendo.cpp,v 1.1.1.1 2011/05/05 18:51:04 flo93 Exp $
5 //  (C) Copyright 2011 Florian Jung (flo93@sourceforge.net)
6 //
7 //  This program is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU General Public License
9 //  as published by the Free Software Foundation; version 2 of
10 //  the License, or (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 //
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 //=========================================================
22 
23 #include <QButtonGroup>
24 
25 #include "crescendo.h"
26 
27 // Forwards from header:
28 #include "xml.h"
29 
30 namespace MusEGui {
31 
32 FunctionReturnDialogFlags_t Crescendo::_ret_flags = FunctionReturnNoFlags;
33 FunctionDialogElements_t Crescendo::_elements = FunctionDialogNoElements;
34 int Crescendo::_range = FunctionLoopedButton;
35 int Crescendo::_parts = FunctionSelectedPartsButton;
36 int Crescendo::start_val = 80;
37 int Crescendo::end_val = 130;
38 bool Crescendo::absolute = 0;
39 
Crescendo(QWidget * parent)40 Crescendo::Crescendo(QWidget* parent)
41 	: FunctionDialogBase(parent)
42 {
43 	setupUi(this);
44 
45   //--------------------------------------------
46   // Set range and parts containers if available.
47   //--------------------------------------------
48 
49   _range_container = rangeBox;
50   _parts_container = partsBox;
51 
52   //--------------------------------------------
53   // Add element widgets to range and parts groups.
54   //--------------------------------------------
55 
56   _range_group->addButton(looped_events_button, FunctionLoopedButton);
57   _range_group->addButton(selected_looped_button, FunctionSelectedLoopedButton);
58 
59   _parts_group->addButton(not_all_parts_button, FunctionSelectedPartsButton);
60   _parts_group->addButton(all_parts_button, FunctionAllPartsButton);
61 
62 
63 	connect(absolute_button, SIGNAL(toggled(bool)), SLOT(absolute_changed(bool)));
64 }
65 
pull_values()66 void Crescendo::pull_values()
67 {
68   //--------------------------------------------
69   // Grab IDs or values from common base object
70   //  (range and parts groups etc.)
71   //--------------------------------------------
72 
73   FunctionDialogBase::pull_values();
74 
75   //--------------------------------------------
76   // Grab this dialog's specific IDs or values.
77   //--------------------------------------------
78 
79 	start_val = start_spinbox->value();
80 	end_val = end_spinbox->value();
81 	absolute = absolute_button->isChecked();
82 }
83 
setupDialog()84 void Crescendo::setupDialog()
85 {
86   //------------------------------------
87   // Setup common base object items.
88   //------------------------------------
89 
90   FunctionDialogBase::setupDialog();
91 
92   //------------------------------------
93   // Setup this dialog's specific items.
94   //------------------------------------
95 
96   start_spinbox->setValue(start_val);
97   end_spinbox->setValue(end_val);
98   absolute_button->setChecked(absolute);
99 }
100 
101 
read_configuration(MusECore::Xml & xml)102 void Crescendo::read_configuration(MusECore::Xml& xml)
103 {
104 	for (;;)
105 	{
106 		MusECore::Xml::Token token = xml.parse();
107 		if (token == MusECore::Xml::Error || token == MusECore::Xml::End)
108 			break;
109 
110 		const QString& tag = xml.s1();
111 		switch (token)
112 		{
113 			case MusECore::Xml::TagStart:
114 
115 				//-----------------------------------------
116 				// Handle any common base settings.
117 				//-----------------------------------------
118 
119 				if(!FunctionDialogBase::read_configuration(tag, xml))
120 				{
121 					//-----------------------------------------
122 					// Handle this dialog's specific settings.
123 					//-----------------------------------------
124 
125 					if (tag == "range")
126 						_range = xml.parseInt();
127 					else if (tag == "parts")
128 						_parts = xml.parseInt();
129 					else if (tag == "start")
130 						start_val=xml.parseInt();
131 					else if (tag == "end")
132 						end_val=xml.parseInt();
133 					else if (tag == "absolute")
134 						absolute=xml.parseInt();
135 					else
136 						xml.unknown("Crescendo");
137 				}
138 				break;
139 
140 			case MusECore::Xml::TagEnd:
141 				if (tag == "crescendo")
142 					return;
143 
144 			default:
145 				break;
146 		}
147 	}
148 }
149 
write_configuration(int level,MusECore::Xml & xml)150 void Crescendo::write_configuration(int level, MusECore::Xml& xml)
151 {
152   xml.tag(level++, "crescendo");
153 
154   //-----------------------------------------
155   // Write any common base settings.
156   //-----------------------------------------
157 
158   FunctionDialogBase::write_configuration(level, xml);
159 
160   //-----------------------------------------
161   // Write this dialog's specific settings.
162   //-----------------------------------------
163 
164   xml.intTag(level, "range", _range);
165   xml.intTag(level, "parts", _parts);
166   xml.intTag(level, "start", start_val);
167   xml.intTag(level, "end", end_val);
168   xml.intTag(level, "absolute", absolute);
169   xml.tag(level, "/crescendo");
170 }
171 
absolute_changed(bool val)172 void Crescendo::absolute_changed(bool val)
173 {
174 	if (val)
175 	{
176 		start_spinbox->setMaximum(127);
177 		start_spinbox->setSuffix("");
178 		end_spinbox->setMaximum(127);
179 		end_spinbox->setSuffix("");
180 	}
181 	else
182 	{
183 		start_spinbox->setMaximum(12700);
184 		start_spinbox->setSuffix(" %");
185 		end_spinbox->setMaximum(12700);
186 		end_spinbox->setSuffix(" %");
187 	}
188 }
189 
190 } // namespace MusEGui
191