1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
/*!
@file GuiMidiSetupDialog.cpp
@brief xxx.
@author L. J. Barman
Copyright (c) 2008-2009, L. J. Barman, all rights reserved
This file is part of the PianoBooster application
PianoBooster is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PianoBooster is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PianoBooster. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QtGui>
#include "GuiMidiSetupDialog.h"
GuiMidiSetupDialog::GuiMidiSetupDialog(QWidget *parent)
: QDialog(parent)
{
m_song = 0;
m_settings = 0;
setupUi(this);
m_latencyFix = 0;
m_latencyChanged = false;
m_midiChanged = false;
midiSetupTabWidget->setCurrentIndex(0);
#if !PB_USE_FLUIDSYNTH
midiSetupTabWidget->removeTab(1);
#endif
setWindowTitle(tr("Midi Setup"));
}
void GuiMidiSetupDialog::init(CSong* song, CSettings* settings)
{
m_song = song;
m_settings = settings;
// Check inputs.
QString portName;
int i = 0;
m_latencyFix = m_song->getLatencyFix();
midiInputCombo->addItem(tr("None (PC Keyboard)"));
midiInputCombo->addItems(song->getMidiPortList(CMidiDevice::MIDI_INPUT));
// Check outputs.
midiOutputCombo->addItem(tr("None"));
midiOutputCombo->addItems(song->getMidiPortList(CMidiDevice::MIDI_OUTPUT));
i = midiInputCombo->findText(m_settings->value("Midi/Input").toString());
if (i!=-1)
midiInputCombo->setCurrentIndex(i);
i = midiOutputCombo->findText(m_settings->value("Midi/Output").toString());
if (i!=-1)
midiOutputCombo->setCurrentIndex(i);
sampleRateCombo->addItem("44100");
sampleRateCombo->addItem("22050");
i = sampleRateCombo->findText(m_settings->value("Fliudsynth/SampleRate").toString());
if (i!=-1)
sampleRateCombo->setCurrentIndex(i);
//midiSettingsSetnum
updateMidiInfoText();
}
void GuiMidiSetupDialog::updateMidiInfoText()
{
midiInfoText->clear();
if (midiInputCombo->currentIndex() == 0)
midiInfoText->append("<span style=\"color:black\">" + tr("If you don't have a MIDI keyboard you can use the PC keyboard; 'X' is middle C.</span>"));
else if (midiInputCombo->currentText().contains("Midi Through", Qt::CaseInsensitive))
midiInfoText->append("<span style=\"color:#FF6600\">The use of Midi Through is not recommended!</span>");
else
midiInfoText->append("<span style=\"color:gray\">" + tr("Midi Input Device: " )+ midiInputCombo->currentText() +"</span>");
if (midiOutputCombo->currentText() == tr("None"))
midiInfoText->append("<span style=\"color:red\">" + tr("No Sound Output Device selected; Choose a Midi Output Device") + "</span>");
else if (midiOutputCombo->currentText().contains("Midi Through", Qt::CaseInsensitive))
midiInfoText->append("<span style=\"color:#FF6600\">" + tr("The use of Midi Through is not recommended!") + "</span>");
else if (midiOutputCombo->currentText().contains("Microsoft GS Wavetable", Qt::CaseInsensitive))
midiInfoText->append("<span style=\"color:#FF6600\">" + tr("Note: the Microsoft GS Wavetable Synth introduces an unwanted delay!.\n")
+ tr("(Try a latency fix of 150msc)") + "</span>");
else
midiInfoText->append("<span style=\"color:gray\">" + tr("Midi Output Device: ") + midiOutputCombo->currentText() +"</span>");
latencyFixLabel->setText(tr("%1 mSec").arg(m_latencyFix));
updateFluidInfoText();
}
void GuiMidiSetupDialog::on_midiInputCombo_activated (int index)
{
m_midiChanged = true;
updateMidiInfoText();
}
void GuiMidiSetupDialog::on_midiOutputCombo_activated (int index)
{
m_midiChanged = true;
updateMidiInfoText();
}
void GuiMidiSetupDialog::on_latencyFixButton_clicked ( bool checked )
{
bool ok;
int latencyFix = QInputDialog::getInteger(this, tr("Enter a value for the latency fix in milliseconds"),
tr(
"The latency fix works by running the music ahead of what you<br>"
"are playing to counteract the delay within the sound generator.<br><br>"
"You will need a piano <b>with speakers</b> that are <b>turned up</b>.<br><br>"
"Enter the time in milliseconds for the delay (1000 mSec = 1 sec)<br>"
"(For the Microsoft GS Wavetable SW Synth try a value of 150)<br>"
"If you are not sure enter a value of zero."),
m_latencyFix, 0, 1000, 50, &ok);
if (ok)
{
m_latencyFix = latencyFix;
m_latencyChanged = true;
updateMidiInfoText();
}
}
void GuiMidiSetupDialog::accept()
{
if (m_midiChanged)
{
m_settings->setValue("Midi/Input", midiInputCombo->currentText());
m_song->openMidiPort(CMidiDevice::MIDI_INPUT, midiInputCombo->currentText() );
if (midiInputCombo->currentText().startsWith(tr("None")))
CChord::setPianoRange(PC_KEY_LOWEST_NOTE, PC_KEY_HIGHEST_NOTE);
else
CChord::setPianoRange(m_settings->value("Keyboard/LowestNote", 0).toInt(),
m_settings->value("Keyboard/HighestNote", 127).toInt());
m_settings->setValue("Midi/Output", midiOutputCombo->currentText());
m_song->openMidiPort(CMidiDevice::MIDI_OUTPUT, midiOutputCombo->currentText() );
m_settings->updateWarningMessages();
m_midiChanged = false;
}
m_settings->setValue("Midi/Latency", m_latencyFix);
m_song->setLatencyFix(m_latencyFix);
m_song->regenerateChordQueue();
if (m_latencyChanged)
{
if( m_latencyFix> 0)
{
int rightSound = m_settings->value("Keyboard/RightSound", Cfg::defaultRightPatch()).toInt();
m_settings->setValue("Keyboard/RightSoundPrevious", rightSound); // Save the current right sound
// Mute the Piano if we are using the latency fix;
m_settings->setValue("Keyboard/RightSound", 0);
m_song->setPianoSoundPatches( -1, -2); // -1 means no sound and -2 means ignore this parameter
}
else
{
int previousRightSound = m_settings->value("Keyboard/RightSoundPrevious", Cfg::defaultRightPatch()).toInt();
m_settings->setValue("Keyboard/RightSound", previousRightSound);
m_song->setPianoSoundPatches(previousRightSound, -2); // -2 means ignore this parameter
}
m_latencyChanged = false;
}
this->QDialog::accept();
}
void GuiMidiSetupDialog::updateFluidInfoText()
{
QStringList soundFontNames = m_settings->getFluidSoundFontNames();
soundFontList->clear();
for (int i=0; i < soundFontNames.count(); i++)
{
int n = soundFontNames.at(i).lastIndexOf("/");
soundFontList->addItem(soundFontNames.at(i).mid(n+1));
}
bool fontLoaded = (soundFontList->count() > 0) ? true : false;
fluidRemoveButton->setEnabled(fontLoaded);
fluidAddButton->setEnabled(soundFontList->count() < 2 ? true : false);
fluidSettingsGroupBox->setEnabled(fontLoaded);
}
void GuiMidiSetupDialog::on_fluidAddButton_clicked ( bool checked )
{
QString lastSoundFont;
QStringList sfList = m_settings->getFluidSoundFontNames();
if (sfList.size() > 0)
lastSoundFont = sfList.last();
QString soundFontName = QFileDialog::getOpenFileName(this,tr("Open SoundFont2 File for fluid synth"),
lastSoundFont, tr("SoundFont2 Files (*.sf2)"));
if (!soundFontName.isEmpty())
m_settings->addFluidSoundFontName(soundFontName);
updateFluidInfoText();
}
void GuiMidiSetupDialog::on_fluidRemoveButton_clicked ( bool checked )
{
}
|