1 //=========================================================
2 //  MusE
3 //  Linux Music Editor
4 //    $Id: remove.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 #include "remove.h"
25 #include "xml.h"
26 
27 namespace MusEGui {
28 
29 FunctionReturnDialogFlags_t Remove::_ret_flags = FunctionReturnNoFlags;
30 FunctionDialogElements_t Remove::_elements = FunctionDialogNoElements;
31 int Remove::_range = FunctionSelectedEventsButton;
32 int Remove::_parts = FunctionSelectedPartsButton;
33 int Remove::velo_threshold = 16;
34 bool Remove::velo_thres_used = false;
35 int Remove::len_threshold = 12;
36 bool Remove::len_thres_used = false;
37 
38 
Remove(QWidget * parent)39 Remove::Remove(QWidget* parent)
40   : FunctionDialogBase(parent)
41 {
42   setupUi(this);
43 
44   //--------------------------------------------
45   // Set range and parts containers if available.
46   //--------------------------------------------
47 
48   _range_container = rangeBox;
49   _parts_container = partsBox;
50 
51   //--------------------------------------------
52   // Add element widgets to range and parts groups.
53   //--------------------------------------------
54 
55   _range_group->addButton(all_events_button, FunctionAllEventsButton);
56   _range_group->addButton(selected_events_button,FunctionSelectedEventsButton);
57   _range_group->addButton(looped_events_button, FunctionLoopedButton);
58   _range_group->addButton(selected_looped_button, FunctionSelectedLoopedButton);
59 
60   _parts_group->addButton(not_all_parts_button, FunctionSelectedPartsButton);
61   _parts_group->addButton(all_parts_button, FunctionAllPartsButton);
62 }
63 
pull_values()64 void Remove::pull_values()
65 {
66   //--------------------------------------------
67   // Grab IDs or values from common base object
68   //  (range and parts groups etc.)
69   //--------------------------------------------
70 
71   FunctionDialogBase::pull_values();
72 
73   //--------------------------------------------
74   // Grab this dialog's specific IDs or values.
75   //--------------------------------------------
76 
77   len_thres_used=len_checkbox->isChecked();
78   len_threshold=len_spinbox->value();
79   velo_thres_used=velo_checkbox->isChecked();
80   velo_threshold=velo_spinbox->value();
81 }
82 
setupDialog()83 void Remove::setupDialog()
84 {
85   //------------------------------------
86   // Setup common base object items.
87   //------------------------------------
88 
89   FunctionDialogBase::setupDialog();
90 
91   //------------------------------------
92   // Setup this dialog's specific items.
93   //------------------------------------
94 
95   len_checkbox->setChecked(len_thres_used);
96   len_spinbox->setValue(len_threshold);
97   velo_checkbox->setChecked(velo_thres_used);
98   velo_spinbox->setValue(velo_threshold);
99 }
100 
read_configuration(MusECore::Xml & xml)101 void Remove::read_configuration(MusECore::Xml& xml)
102 {
103 	for (;;)
104 	{
105 		MusECore::Xml::Token token = xml.parse();
106 		if (token == MusECore::Xml::Error || token == MusECore::Xml::End)
107 			break;
108 
109 		const QString& tag = xml.s1();
110 		switch (token)
111 		{
112 			case MusECore::Xml::TagStart:
113 
114 				//-----------------------------------------
115 				// Handle any common base settings.
116 				//-----------------------------------------
117 
118 				if(!FunctionDialogBase::read_configuration(tag, xml))
119 				{
120 					//-----------------------------------------
121 					// Handle this dialog's specific settings.
122 					//-----------------------------------------
123 
124 					if (tag == "range")
125 						_range = xml.parseInt();
126 					else if (tag == "parts")
127 						_parts = xml.parseInt();
128 					else if (tag == "velo_threshold")
129 						velo_threshold=xml.parseInt();
130 					else if (tag == "velo_thres_used")
131 						velo_thres_used=xml.parseInt();
132 					else if (tag == "len_threshold")
133 						len_threshold=xml.parseInt();
134 					else if (tag == "len_thres_used")
135 						len_thres_used=xml.parseInt();
136 					else
137 						xml.unknown("Erase");
138 				}
139 				break;
140 
141 			case MusECore::Xml::TagEnd:
142 				if (tag == "erase")
143 					return;
144 
145 			default:
146 				break;
147 		}
148 	}
149 }
150 
write_configuration(int level,MusECore::Xml & xml)151 void Remove::write_configuration(int level, MusECore::Xml& xml)
152 {
153   xml.tag(level++, "erase");
154 
155   //-----------------------------------------
156   // Write any common base settings.
157   //-----------------------------------------
158 
159   FunctionDialogBase::write_configuration(level, xml);
160 
161   //-----------------------------------------
162   // Write this dialog's specific settings.
163   //-----------------------------------------
164 
165   xml.intTag(level, "range", _range);
166   xml.intTag(level, "parts", _parts);
167   xml.intTag(level, "velo_threshold", velo_threshold);
168   xml.intTag(level, "velo_thres_used", velo_thres_used);
169   xml.intTag(level, "len_threshold", len_threshold);
170   xml.intTag(level, "len_thres_used", len_thres_used);
171 
172   xml.tag(level, "/erase");
173 }
174 
175 } // namespace MusEGui
176 
177