1 //=========================================================
2 // MusE
3 // Linux Music Editor
4 // $Id: mixdowndialog.cpp,v 1.1.1.1 2003/10/27 18:55:02 wschweer Exp $
5 // (C) Copyright 2001 Werner Schweer (ws@seh.de)
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 <QFileDialog>
24
25 #include "globals.h"
26 #include "gconfig.h"
27 #include "mixdowndialog.h"
28 #include "wave.h"
29
30 namespace MusECore {
31
32 //---------------------------------------------------------
33 // sndFileOpen
34 // sf - old soundfile, used to preset file parameters
35 //---------------------------------------------------------
36
getSndFile(const SndFile * sf,QWidget * parent)37 SndFile* getSndFile(const SndFile* sf, QWidget* parent)
38 {
39 MusEGui::MixdownFileDialog* dialog = new MusEGui::MixdownFileDialog(sf, parent);
40 dialog->exec();
41 MusECore::SndFile* sndFile = dialog->sndFile();
42 delete dialog;
43 return sndFile;
44 }
45
46 } // namespace MusECore
47
48 namespace MusEGui {
49
50 //---------------------------------------------------------
51 // MixdownFileDialog
52 //---------------------------------------------------------
53
MixdownFileDialog(const MusECore::SndFile * _sf,QWidget * parent,Qt::WindowFlags fl)54 MixdownFileDialog::MixdownFileDialog(const MusECore::SndFile* _sf,
55 QWidget* parent, Qt::WindowFlags fl)
56 : QDialog(parent, fl)
57 {
58 setupUi(this);
59 sf = 0;
60 connect(buttonPath, SIGNAL(clicked()), SLOT(fdialog()));
61 if (_sf) {
62 int channels = _sf->channels();
63 int format = _sf->format();
64 switch(channels) {
65 case 1: channels = 1; break;
66 case 2: channels = 0; break;
67 case 6: channels = 2; break;
68 }
69 editPath->setText(_sf->path());
70 comboChannel->setCurrentIndex(channels);
71 comboFormat->setCurrentIndex(format);
72 }
73 }
74
75 //---------------------------------------------------------
76 // accept
77 //---------------------------------------------------------
78
accept()79 void MixdownFileDialog::accept()
80 {
81 QString oldpath;
82 unsigned channel = comboChannel->currentIndex();
83 unsigned format = comboFormat->currentIndex();
84 switch (channel) {
85 case 0: channel = 2; break;
86 case 1: channel = 1; break;
87 case 2: channel = 6; break; // not implemented!
88 }
89 switch (format) {
90 case 0: // 16 bit wave
91 format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
92 break;
93 case 1: // 24 bit wave
94 format = SF_FORMAT_WAV | SF_FORMAT_PCM_24;
95 break;
96 case 2: // 32 bit float wave
97 format = SF_FORMAT_WAV | SF_FORMAT_FLOAT;
98 break;
99 }
100 QString path = editPath->text();
101 if (path.isEmpty()) {
102 sf = 0;
103 reject();
104 return;
105 }
106 if (path.right(4) != ".wav")
107 path += ".wav";
108 sf = new MusECore::SndFile(path);
109 sf->setFormat(format, channel, MusEGlobal::sampleRate);
110 done(1);
111 }
112
113 //---------------------------------------------------------
114 // fdialog
115 //---------------------------------------------------------
116
fdialog()117 void MixdownFileDialog::fdialog()
118 {
119 QString oldpath;
120 if (sf) {
121 oldpath = sf->path();
122 }
123 if (!MusEGlobal::config.mixdownPath.isEmpty()) {
124 printf("Setting oldpath to %s\n", MusEGlobal::config.mixdownPath.toLatin1().data());
125 oldpath = MusEGlobal::config.mixdownPath;
126 }
127 QString path = QFileDialog::getSaveFileName(this, 0, oldpath, tr("Wave Files (*.wav);;All Files (*)"));
128 if (!path.isEmpty()) {
129 editPath->setText(path);
130 }
131 // check if the file already exists, which can happen.
132 // Easiest way to get the recording to work as intended we simply remove the old file.
133 if (QFileInfo::exists(path)) {
134 QFile f(path);
135 f.remove();
136 }
137 MusEGlobal::config.mixdownPath = path;
138 }
139
140 } // namespace MusEGui
141