1 //=========================================================
2 //  MusE
3 //  Linux Music Editor
4 //    $Id: functions.cpp,v 1.20.2.19 2011/05/05 20:10 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 "dialogs.h"
24 
25 #include <iostream>
26 
27 // Forwards from header:
28 #include "function_dialogs/gatetime.h"
29 #include "function_dialogs/velocity.h"
30 #include "function_dialogs/quantize.h"
31 #include "function_dialogs/remove.h"
32 #include "function_dialogs/deloverlaps.h"
33 #include "function_dialogs/setlen.h"
34 #include "function_dialogs/move.h"
35 #include "function_dialogs/transpose.h"
36 #include "function_dialogs/crescendo.h"
37 #include "function_dialogs/legato.h"
38 #include "components/pastedialog.h"
39 #include "components/pasteeventsdialog.h"
40 #include "xml.h"
41 
42 using namespace std;
43 
44 namespace MusEGui {
45 
46 GateTime* gatetime_dialog=NULL;
47 Velocity* velocity_dialog=NULL;
48 Quantize* quantize_dialog=NULL;
49 Remove* erase_dialog=NULL;
50 DelOverlaps* del_overlaps_dialog=NULL;
51 Setlen* set_notelen_dialog=NULL;
52 Move* move_notes_dialog=NULL;
53 Transpose* transpose_dialog=NULL;
54 Crescendo* crescendo_dialog=NULL;
55 Legato* legato_dialog=NULL;
56 PasteDialog* paste_dialog=NULL;
57 PasteEventsDialog* paste_events_dialog=NULL;
58 
init_function_dialogs()59 void init_function_dialogs()
60 {
61         // NOTE: For deleting parentless dialogs and widgets, please add them to MusE::deleteParentlessDialogs().
62         gatetime_dialog = new GateTime();
63         velocity_dialog = new Velocity();
64         quantize_dialog = new Quantize();
65         erase_dialog = new Remove();
66         del_overlaps_dialog = new DelOverlaps();
67         set_notelen_dialog = new Setlen();
68         move_notes_dialog = new Move();
69         transpose_dialog = new Transpose();
70         crescendo_dialog = new Crescendo();
71         legato_dialog = new Legato();
72         paste_dialog = new PasteDialog();
73         paste_events_dialog = new PasteEventsDialog();
74 }
75 
76 //
77 // NOTE: This is called by MusE::deleteParentlessDialogs()
78 //
destroy_function_dialogs()79 void destroy_function_dialogs()
80 {
81         if(gatetime_dialog) delete gatetime_dialog;
82         if(velocity_dialog) delete velocity_dialog;
83         if(quantize_dialog) delete quantize_dialog;
84         if(erase_dialog) delete erase_dialog;
85         if(del_overlaps_dialog) delete del_overlaps_dialog;
86         if(set_notelen_dialog) delete set_notelen_dialog;
87         if(move_notes_dialog) delete move_notes_dialog;
88         if(transpose_dialog) delete transpose_dialog;
89         if(crescendo_dialog) delete crescendo_dialog;
90         if(legato_dialog) delete legato_dialog;
91         if(paste_dialog) delete paste_dialog;
92         if(paste_events_dialog) delete paste_events_dialog;
93 }
94 
retranslate_function_dialogs()95 void retranslate_function_dialogs()
96 {
97 	gatetime_dialog->retranslateUi(gatetime_dialog);
98 	velocity_dialog->retranslateUi(velocity_dialog);
99 	quantize_dialog->retranslateUi(quantize_dialog);
100 	erase_dialog->retranslateUi(erase_dialog);
101 	del_overlaps_dialog->retranslateUi(del_overlaps_dialog);
102 	set_notelen_dialog->retranslateUi(set_notelen_dialog);
103 	move_notes_dialog->retranslateUi(move_notes_dialog);
104 	transpose_dialog->retranslateUi(transpose_dialog);
105 	crescendo_dialog->retranslateUi(crescendo_dialog);
106 	legato_dialog->retranslateUi(legato_dialog);
107 	paste_dialog->retranslateUi(paste_dialog);
108 	paste_events_dialog->retranslateUi(paste_events_dialog);
109 }
110 
read_function_dialog_config(MusECore::Xml & xml)111 void read_function_dialog_config(MusECore::Xml& xml)
112 {
113 	for (;;)
114 	{
115 		MusECore::Xml::Token token = xml.parse();
116 		if (token == MusECore::Xml::Error || token == MusECore::Xml::End)
117 			break;
118 
119 		const QString& tag = xml.s1();
120 		switch (token)
121 		{
122 			case MusECore::Xml::TagStart:
123 				if (tag == "mod_len")
124 					gatetime_dialog->read_configuration(xml);
125 				else if (tag == "mod_velo")
126 					velocity_dialog->read_configuration(xml);
127 				else if (tag == "quantize")
128 					quantize_dialog->read_configuration(xml);
129 				else if (tag == "erase")
130 					erase_dialog->read_configuration(xml);
131 				else if (tag == "del_overlaps")
132 					del_overlaps_dialog->read_configuration(xml);
133 				else if (tag == "setlen")
134 					set_notelen_dialog->read_configuration(xml);
135 				else if (tag == "move")
136 					move_notes_dialog->read_configuration(xml);
137 				else if (tag == "transpose")
138 					transpose_dialog->read_configuration(xml);
139 				else if (tag == "crescendo")
140 					crescendo_dialog->read_configuration(xml);
141 				else if (tag == "legato")
142 					legato_dialog->read_configuration(xml);
143 				else if (tag == "pastedialog")
144 					paste_dialog->read_configuration(xml);
145 				else if (tag == "pasteeventsdialog")
146 					paste_events_dialog->read_configuration(xml);
147 				else
148 					xml.unknown("dialogs");
149 				break;
150 
151 			case MusECore::Xml::TagEnd:
152 				if (tag == "dialogs")
153 					return;
154 
155 			default:
156 				break;
157 		}
158 	}
159 }
160 
write_function_dialog_config(int level,MusECore::Xml & xml)161 void write_function_dialog_config(int level, MusECore::Xml& xml)
162 {
163 	xml.tag(level++, "dialogs");
164 
165 	gatetime_dialog->write_configuration(level, xml);
166 	velocity_dialog->write_configuration(level, xml);
167 	quantize_dialog->write_configuration(level, xml);
168 	erase_dialog->write_configuration(level, xml);
169 	del_overlaps_dialog->write_configuration(level, xml);
170 	set_notelen_dialog->write_configuration(level, xml);
171 	move_notes_dialog->write_configuration(level, xml);
172 	transpose_dialog->write_configuration(level, xml);
173 	crescendo_dialog->write_configuration(level, xml);
174 	legato_dialog->write_configuration(level, xml);
175 	paste_dialog->write_configuration(level, xml);
176 	paste_events_dialog->write_configuration(level, xml);
177 
178 	xml.tag(level, "/dialogs");
179 }
180 
181 }
182