Skip to content

Commit

Permalink
Fixed the pitch wheel
Browse files Browse the repository at this point in the history
Support for the MIDI output coming from Jack
  • Loading branch information
davy7125 committed Aug 31, 2019
1 parent 34bf5de commit 4b6f090
Show file tree
Hide file tree
Showing 14 changed files with 6,868 additions and 6,790 deletions.
27 changes: 17 additions & 10 deletions sources/clavier/controllerarea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ControllerArea::ControllerArea(QWidget *parent) :
// Initialization of the wheel
ui->sliderPitchWheel->setColorFromMiddle(true);
ui->sliderPitchWheel->setBackToValue(64);
updateBend(64); // Always in the middle
updateBend(0); // Always in the middle

// Initialization of the controllers
ui->comboControl1->blockSignals(true);
Expand Down Expand Up @@ -131,14 +131,20 @@ void ControllerArea::updateController(int num, int value)
}
}

void ControllerArea::updateBend(int value)
void ControllerArea::updateBend(double value, bool stopTimer)
{
if (value < 0)
value = 0;
else if (value > 127)
value = 127;

ui->labelWheelValue->setText(QString::number(value));
if (value < -1)
value = -1;
else if (value > 1)
value = 1;

ui->sliderPitchWheel->blockSignals(true);
ui->sliderPitchWheel->setValue(static_cast<int>((value + 1) * 64));
if (stopTimer)
ui->sliderPitchWheel->stopTimer();
ui->sliderPitchWheel->blockSignals(false);

ui->labelWheelValue->setText(QString::number(value, 'f', 2));
}

void ControllerArea::updateBendSensitivity(double semitones)
Expand All @@ -157,8 +163,9 @@ void ControllerArea::updateBendSensitivity(double semitones)

void ControllerArea::on_sliderPitchWheel_valueChanged(int value)
{
updateBend(value);
emit(bendChanged(value));
double fVal = static_cast<double>(value - 64) / 64;
updateBend(fVal, false);
emit(bendChanged(fVal));
}

void ControllerArea::on_sliderSensitivity_valueChanged(int value)
Expand Down
4 changes: 2 additions & 2 deletions sources/clavier/controllerarea.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ class ControllerArea : public QWidget
public slots:
void updateMonoPressure(int value);
void updateController(int num, int value);
void updateBend(int value);
void updateBend(double value, bool stopTimer = true);
void updateBendSensitivity(double semitones);

signals:
void monoPressureChanged(int value);
void controllerChanged(int num, int value);
void bendChanged(int value);
void bendChanged(double value);
void bendSensitivityChanged(double semitones);

private slots:
Expand Down
3 changes: 3 additions & 0 deletions sources/clavier/styledslider.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class StyledSlider : public QSlider
// If set, the handle will be back to the specified position
void setBackToValue(int middleValue) { _middleValue = middleValue; }

// Stop the timer so that the slider stay in its position
void stopTimer() { _timer.stop(); }

protected:
void paintEvent(QPaintEvent *event);

Expand Down
18 changes: 13 additions & 5 deletions sources/context/audiodevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void AudioDevice::openJackConnection(quint32 bufferSize)

// Ouverture d'une session cliente au serveur Jack
_jack_client = jack_client_open(client_name, JackNullOption, &status);
if (_jack_client == NULL)
if (_jack_client == nullptr)
{
printf ("jack_client_open() failed, status = 0x%2.0x\n", status);
if (status & JackServerFailed)
Expand All @@ -273,7 +273,7 @@ void AudioDevice::openJackConnection(quint32 bufferSize)

// Callback de jack pour la récupération de données et l'arrêt
jack_set_process_callback(_jack_client, jackProcess, this);
jack_on_shutdown(_jack_client, jack_shutdown, 0);
jack_on_shutdown(_jack_client, jack_shutdown, nullptr);

// Enregistrement fréquence d'échantillonnage
_format.setSampleRate((int)jack_get_sample_rate(_jack_client));
Expand All @@ -282,9 +282,9 @@ void AudioDevice::openJackConnection(quint32 bufferSize)
jack_set_buffer_size(_jack_client, bufferSize);

// Nombre de sorties audio
const char ** ports = jack_get_ports(_jack_client, NULL, NULL,
const char ** ports = jack_get_ports(_jack_client, nullptr, nullptr,
JackPortIsPhysical|JackPortIsInput);
if (ports == NULL)
if (ports == nullptr)
{
printf("no physical playback ports\n");
return;
Expand Down Expand Up @@ -416,7 +416,15 @@ void AudioDevice::closeConnections()
#ifndef Q_OS_WIN
if (_jack_client)
{
jack_client_close(_jack_client);
try
{
jack_client_close(_jack_client);
}
catch (std::exception error)
{
Q_UNUSED(error)
}

_jack_client = nullptr;
}
#endif
Expand Down
15 changes: 10 additions & 5 deletions sources/context/bendevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,21 @@
class BendEvent : public QEvent
{
public:
BendEvent(unsigned char val) : QEvent((QEvent::Type)(QEvent::User+4)),
_value(val) {}
BendEvent(unsigned char val1, unsigned char val2) : QEvent((QEvent::Type)(QEvent::User+4)),
_value1(val1),
_value2(val2),
_value((_value2 << 7) | _value1)
{}

unsigned char getValue() const
double getValue() const
{
return _value;
// Result between -1 and 1
return static_cast<double>(_value - 8192) / 8192.0;
}

protected:
unsigned char _value;
unsigned char _value1, _value2;
qint32 _value;
};

#endif // BENDEVENT_H
28 changes: 17 additions & 11 deletions sources/context/interface/configsectiongeneral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void ConfigSectionGeneral::initializeAudio()
bool configFound = false;
int comboboxIndex = 0;
int comboboxDefaultIndex = 0;
ui->comboAudioOuput->clear();
for (int i = 0; i < hostInfos.size(); i++)
{
if (hostInfos[i]._index < 0)
Expand Down Expand Up @@ -151,24 +152,29 @@ void ConfigSectionGeneral::initializeMidi()
// Update the possible midi inputs
ui->comboMidiInput->blockSignals(true);
ui->comboMidiInput->clear();
QStringList listMidi = ContextManager::midi()->getMidiList();
ui->comboMidiInput->addItem("-");
ui->comboMidiInput->addItems(listMidi);
QMap<QString, QString> listMidi = ContextManager::midi()->getMidiList();
ui->comboMidiInput->addItem("-", "-1#-1");
foreach (QString key, listMidi.keys())
ui->comboMidiInput->addItem(listMidi[key], key);

// Select the current one
int numMidiPort = ContextManager::configuration()->getValue(ConfManager::SECTION_MIDI, "index_port", -1).toInt();
if (numMidiPort + 1 < ui->comboMidiInput->count())
ui->comboMidiInput->setCurrentIndex(numMidiPort + 1);
else
ui->comboMidiInput->setCurrentIndex(0); // None
QString indexPort = ContextManager::configuration()->getValue(ConfManager::SECTION_MIDI, "index_port", "-1#-1").toString();
for (int i = 0; i < ui->comboMidiInput->count(); i++)
{
if (ui->comboMidiInput->itemData(i).toString() == indexPort)
{
ui->comboMidiInput->setCurrentIndex(i);
break;
}
}
ui->comboMidiInput->blockSignals(false);
}

void ConfigSectionGeneral::on_comboMidiInput_currentIndexChanged(int index)
{
int numPortMidi = index - 1;
ContextManager::configuration()->setValue(ConfManager::SECTION_MIDI, "index_port", numPortMidi);
ContextManager::midi()->openMidiPort(numPortMidi);
QString indexInput = ui->comboMidiInput->itemData(index).toString();
ContextManager::configuration()->setValue(ConfManager::SECTION_MIDI, "index_port", indexInput);
ContextManager::midi()->openMidiPort(indexInput);
}

void ConfigSectionGeneral::on_checkBoucle_toggled(bool checked)
Expand Down
Loading

0 comments on commit 4b6f090

Please sign in to comment.