git-svn-id: https://svn.code.sf.net/p/pianobooster/code/trunk@20 ba081f5d-443b-49a7-ac4b-446c3f91f371

This commit is contained in:
louisjb 2008-12-31 16:37:42 +00:00
parent 643210f9e1
commit b0ee185f7c
8 changed files with 97 additions and 28 deletions

View File

@ -33,12 +33,12 @@
#include "Cfg.h"
float Cfg::m_staveEndX;
int Cfg::debugLevel;
int Cfg::debugLevel = 0;
bool Cfg::smallScreen = false;
bool Cfg::quickStart = false;
int Cfg::m_appX;
int Cfg::m_appY;
int Cfg::m_appWidth;
int Cfg::m_appHeight;
int Cfg::latencyFix = 0;

View File

@ -99,10 +99,13 @@ public:
static int defualtWrongPatch() {return 7;} // Starts at 1
static int defualtRightPatch() {return 1;} // Starts at 1
static int debugLevel;
static bool smallScreen;
static bool quickStart;
static int latencyFix; // Try to fix the latency (put the time in msec, 0 disables it)
private:
static float m_staveEndX;

View File

@ -55,7 +55,7 @@ CConductor::CConductor()
m_skill = 0;
m_silenceTimeOut = 0;
m_realTimeEventBits = 0;
setPianistChannels(1-1,1-1);
setPianistChannels(1-1,2-1);
for ( i = 0; i < MAX_MIDI_CHANNELS; i++)
{
@ -295,6 +295,21 @@ void CConductor::setActiveChannel(int channel)
autoMute();
}
void CConductor::testWrongNoteSound(bool enable)
{
m_testWrongNoteSound = enable;
CMidiEvent event;
event.controlChangeEvent(0, m_pianistGoodChan, MIDI_MAIN_VOLUME, 127);
playMidiEvent(event); // Play the midi note or event
event.programChangeEvent(0,m_pianistGoodChan, m_cfg_rightNoteSound);
playMidiEvent( event );
event.controlChangeEvent(0, m_pianistBadChan, MIDI_MAIN_VOLUME, 127);
playMidiEvent(event); // Play the midi note or event
event.programChangeEvent(0,m_pianistBadChan, m_cfg_wrongNoteSound);
playMidiEvent( event );
}
void CConductor::playMusic(bool start)
{
@ -304,16 +319,8 @@ void CConductor::playMusic(bool start)
if (start)
{
autoMute();
CMidiEvent event;
event.controlChangeEvent(0, m_pianistGoodChan, MIDI_MAIN_VOLUME, 127);
playMidiEvent(event); // Play the midi note or event
event.programChangeEvent(0,m_pianistGoodChan, m_cfg_rightNoteSound);
playMidiEvent( event );
event.controlChangeEvent(0, m_pianistBadChan, MIDI_MAIN_VOLUME, 127);
playMidiEvent(event); // Play the midi note or event
event.programChangeEvent(0,m_pianistBadChan, m_cfg_wrongNoteSound);
playMidiEvent( event );
testWrongNoteSound(false);
/*
const unsigned char gsModeEnterData[] = {0xf0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7f, 0x00, 0x41, 0xf7};
@ -410,7 +417,7 @@ void CConductor::fetchNextChord()
}
//put the split point in the middle
m_pianistSplitPoint = (lowestTreble + highestBase) /2;
m_pianistSplitPoint = ((lowestTreble + highestBase) /2 ) + m_transpose;
}
bool CConductor::validatePianistNote(CMidiEvent& inputNote)
@ -511,6 +518,7 @@ void CConductor::pianistInput(CMidiEvent inputNote)
/*
// use the same channel for the right and wrong note
int pianoSound = (goodSound == true) ? m_cfg_rightNoteSound : m_cfg_wrongNoteSound;
if (pianoSound != m_lastSound)
@ -523,7 +531,8 @@ void CConductor::pianistInput(CMidiEvent inputNote)
}
*/
playMidiEvent( inputNote );
if (goodSound == false || Cfg::latencyFix == 0)
playMidiEvent( inputNote );
}
// Counts the number of notes the pianist has down
@ -683,7 +692,10 @@ void CConductor::realTimeEngine(int mSecTicks)
}
if (type == MIDI_PB_tempo)
{
m_tempo.setMidiTempo(m_nextMidiEvent.data1());
m_leadLagAdjust = m_tempo.mSecToTicks( -Cfg::latencyFix);
}
else if (type == MIDI_PB_timeSignature)
{
m_currentTimeSigTop = m_nextMidiEvent.data1();

View File

@ -32,7 +32,7 @@
#include "MidiEvent.h"
#include "Queue.h"
#include "MidiDevice.h"
#include "Util.h"
#include "Cfg.h"
#include "Chord.h"
#include "Rating.h"
#include "Tempo.h"
@ -90,7 +90,11 @@ public:
float getSpeed() {return m_tempo.getSpeed();}
void setSpeed(float speed) { m_tempo.setSpeed(speed); }
void setSpeed(float speed)
{
m_tempo.setSpeed(speed);
m_leadLagAdjust = m_tempo.mSecToTicks( -Cfg::latencyFix);
}
void muteChannel(int channel, bool state);
void mutePart(int channel, bool state);
void transpose(int transpose);
@ -147,7 +151,8 @@ public:
}
}
void getCurrentTimeSig(int *top, int *bottom) {*top = m_currentTimeSigTop; *bottom = m_currentTimeSigBottom;}
void testWrongNoteSound(bool enable) {m_testWrongNoteSound = enable;}
void testWrongNoteSound(bool enable);
void setPianoSoundPatches(int rightSound, int wrongSound){
m_cfg_rightNoteSound = rightSound;
m_cfg_wrongNoteSound = wrongSound;
@ -244,6 +249,7 @@ private:
int m_cfg_imminentNotesOffPoint;
int m_cfg_playZoneEarly; // when playing along
int m_cfg_playZoneLate;
bool m_testWrongNoteSound;
int m_boostVolume;
int m_activeChannel; // The current part that is being displayed (used for boost and autoMute)

View File

@ -60,9 +60,9 @@ void GuiKeyboardSetupDialog::init(CSong* song, QSettings* settings)
i++;
}
int program = m_settings->value("Keyboard/RightSound", 1).toInt();
int program = m_settings->value("Keyboard/RightSound", Cfg::defualtRightPatch()).toInt();
rightSoundCombo->setCurrentIndex(program - 1);
program = m_settings->value("Keyboard/WrongSound", 24).toInt();
program = m_settings->value("Keyboard/WrongSound", Cfg::defualtWrongPatch()).toInt();
wrongSoundCombo->setCurrentIndex(program - 1);
int lowestNote = m_settings->value("Keyboard/lowestNote", "0").toInt();
int highestNote = m_settings->value("Keyboard/highestNote", "127").toInt();
@ -157,8 +157,8 @@ void GuiKeyboardSetupDialog::accept()
void GuiKeyboardSetupDialog::reject()
{
m_song->testWrongNoteSound(false);
m_song->setPianoSoundPatches(m_settings->value("Keyboard/RightSound", 1).toInt() - 1,
m_settings->value("Keyboard/WrongSound", 7).toInt() - 1);
m_song->setPianoSoundPatches(m_settings->value("Keyboard/RightSound", Cfg::defualtRightPatch()).toInt() - 1,
m_settings->value("Keyboard/WrongSound", Cfg::defualtWrongPatch()).toInt() - 1);
this->QDialog::reject();
}

View File

@ -78,6 +78,9 @@ void GuiMidiSetupDialog::init(CSong* song, QSettings* settings)
i = midiOutputCombo->findText(m_settings->value("midi/output").toString());
if (i!=-1)
midiOutputCombo->setCurrentIndex(i);
latencyFixEdit->setText(QString().setNum(Cfg::latencyFix));
updateMidiInfoText();
}
@ -101,6 +104,14 @@ void GuiMidiSetupDialog::updateMidiInfoText()
midiInfoText->append("<span style=\"color:black\">Note: the Microsoft SW Synth introduces an unwanted delay!</span>");
else
midiInfoText->append("<span style=\"color:gray\">Midi Output Device: " + midiOutputCombo->currentText() +"</span>");
int latencyFix = latencyFixEdit->text().toInt();
latencyFix = qBound(0, latencyFix, 2000);
latencyFixEdit->setText(QString().setNum(latencyFix));
if (latencyFix > 0)
midiInfoText->append("<span style=\"color:black\">Please see the website for the latency fix instructions.</span>");
}
void GuiMidiSetupDialog::on_midiInputCombo_activated (int index)
@ -116,15 +127,23 @@ void GuiMidiSetupDialog::on_midiOutputCombo_activated (int index)
void GuiMidiSetupDialog::accept()
{
m_settings->setValue("midi/input", midiInputCombo->currentText());
m_settings->setValue("midi/output", midiOutputCombo->currentText());
m_song->openMidiPort(0,string(midiInputCombo->currentText().toAscii()));
m_song->openMidiPort(1,string(midiOutputCombo->currentText().toAscii()));
if (midiInputCombo->currentText().startsWith("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());
if (m_settings->value("midi/output").toString() != midiOutputCombo->currentText())
{
m_settings->setValue("midi/output", midiOutputCombo->currentText());
m_settings->setValue("midi/latency", latencyFixEdit->text().toInt());
m_song->openMidiPort(1,string(midiOutputCombo->currentText().toAscii()));
}
Cfg::latencyFix = latencyFixEdit->text().toInt();
m_song->regenerateChordQueue();
this->QDialog::accept();
}

View File

@ -34,7 +34,10 @@
<item row="0" column="0" >
<widget class="QLabel" name="label" >
<property name="text" >
<string>Midi Input Device</string>
<string>Midi Input Device:</string>
</property>
<property name="alignment" >
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
@ -44,13 +47,36 @@
<item row="1" column="0" >
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Midi Output Device</string>
<string>Midi Output Device:</string>
</property>
<property name="alignment" >
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QComboBox" name="midiOutputCombo" />
</item>
<item row="2" column="0" >
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>Latency fix (mSec):</string>
</property>
<property name="alignment" >
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1" >
<widget class="QLineEdit" name="latencyFixEdit" >
<property name="toolTip" >
<string>A work around for poor latency</string>
</property>
<property name="inputMask" >
<string>0000; </string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
@ -69,7 +95,7 @@
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons" >
<set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>

View File

@ -81,8 +81,8 @@ Window::Window()
show();
m_song->setPianoSoundPatches(m_settings->value("Keyboard/RightSound", 1).toInt() - 1,
m_settings->value("Keyboard/WrongSound", 24).toInt() - 1);
m_song->setPianoSoundPatches(m_settings->value("Keyboard/RightSound", Cfg::defualtRightPatch()).toInt() - 1,
m_settings->value("Keyboard/WrongSound", Cfg::defualtWrongPatch()).toInt() - 1);
QString midiInputName = m_settings->value("midi/input").toString();
if (midiInputName.startsWith("None"))
@ -91,6 +91,9 @@ Window::Window()
CChord::setPianoRange(m_settings->value("Keyboard/lowestNote", 0).toInt(),
m_settings->value("Keyboard/highestNote", 127).toInt());
Cfg::latencyFix = m_settings->value("midi/latency", 0).toInt();
m_song->openMidiPort(0, string(midiInputName.toAscii()));
if (m_song->openMidiPort(1,string(m_settings->value("midi/output").toString().toAscii()))==false)