Skip to content

Commit

Permalink
Merge pull request obsproject#12 from Alzy/fixes
Browse files Browse the repository at this point in the history
 Fixes for errors opening ports
  • Loading branch information
cpyarger committed Jun 2, 2020
2 parents 935c8fe + 6a94605 commit 27ea882
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
1 change: 1 addition & 0 deletions device-manager.cpp
Expand Up @@ -149,6 +149,7 @@ DeviceManager::GetMidiHooksByDeviceName(const char *deviceName)
*/
void DeviceManager::RegisterMidiDevice(int port, int outport)
{

MidiAgent *midiA = new MidiAgent();
midiA->OpenPort(port);
midiA->OpenOutPort(outport);
Expand Down
16 changes: 11 additions & 5 deletions forms/settings-dialog.cpp
Expand Up @@ -142,27 +142,33 @@ int SettingsDialog::on_check_enabled_stateChanged(bool state)
{

if (state == true) {

auto selectedDeviceName =
ui->list_midi_dev->currentItem()->text().toStdString();
ui->list_midi_dev->currentItem()
->text()
.toStdString();
auto selectedOutDeviceName =
ui->outbox->currentText().toStdString();
auto device = GetDeviceManager()->GetMidiDeviceByName(
selectedDeviceName.c_str());
blog(LOG_INFO, "Item enabled: %s", selectedDeviceName.c_str());
int devicePort = GetDeviceManager()->GetPortNumberByDeviceName(
blog(LOG_INFO, "Item enabled: %s",
selectedDeviceName.c_str());
int devicePort =
GetDeviceManager()->GetPortNumberByDeviceName(
selectedDeviceName.c_str());
int deviceOutPort =
GetDeviceManager()->GetOutPortNumberByDeviceName(
selectedOutDeviceName.c_str());
if (device == NULL) {
GetDeviceManager()->RegisterMidiDevice(devicePort,
deviceOutPort);
GetDeviceManager()->RegisterMidiDevice(
devicePort, deviceOutPort);
} else {
device->OpenPort(devicePort);
if (deviceOutPort != -1) {
device->OpenOutPort(deviceOutPort);
}
}

}

//ui->outbox->setCurrentText(QString::fromStdString(device->GetOutName()));
Expand Down
25 changes: 17 additions & 8 deletions midi-agent.cpp
Expand Up @@ -27,6 +27,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#include "obs-midi.h"
#include "config.h"
#include "obs-controller.h"
#include "RtMidi17/rtmidi17.hpp"
#include "device-manager.h"
using namespace std;

Expand Down Expand Up @@ -249,22 +250,30 @@ void MidiAgent::SendMessage(std::string name, std::string mType, int mIndex,
*/
void MidiAgent::OpenPort(int inport)
{
midiin->open_port(inport);
try {

name = midiin->get_port_name(inport);
enabled = true;
connected = true;
blog(LOG_INFO, "MIDI device connected In: [%d] %s", inport,
name.c_str());
midiin->open_port(inport);

name = midiin->get_port_name(inport);
enabled = true;
connected = true;
blog(LOG_INFO, "MIDI device connected In: [%d] %s", inport,
name.c_str());

} catch (const rtmidi::midi_exception &error) {


blog(1, "unable to open port %i -- &s", inport, error.what());
}
}
void MidiAgent::OpenOutPort(int outport)
{

try {
midiout->open_port(outport);
} catch (rtmidi::midi_exception &error) {
} catch (const rtmidi::midi_exception &error) {

blog(1, " Opening out port error ");
blog(1, " Opening out port -- %i -- exception -- %s ", outport,error.what());
}
outname = midiout->get_port_name(outport);
enabled = true;
Expand Down

0 comments on commit 27ea882

Please sign in to comment.