Skip to content

Commit

Permalink
Merge pull request #46 from Alzy/fixes
Browse files Browse the repository at this point in the history
Fix OBS crashing when changing user profile + fix plugin not copying to rundir on debug
  • Loading branch information
Alzy authored Dec 19, 2020
2 parents 9b46f4f + d9f877e commit 1465753
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,8 @@ if(APPLE)
target_link_libraries(obs-midi "${OBS_FRONTEND_LIB}")
endif()
# -- End of section --



# -- Fixes issue where plugin isn't copied to rundir plugins directory on local build --
install_obs_plugin_with_data(obs-midi data)
3 changes: 3 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ void Config::OnFrontendEvent(enum obs_frontend_event event, void *param)
auto config = reinterpret_cast<Config *>(param);

if (event == OBS_FRONTEND_EVENT_PROFILE_CHANGED) {
auto deviceManager = GetDeviceManager();
deviceManager->Unload();

config->SetDefaults();
config->Load();
}
Expand Down
31 changes: 28 additions & 3 deletions src/device-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ DeviceManager::DeviceManager()

DeviceManager::~DeviceManager()
{
rtMidi->~midi_in();
MO->~midi_out();
Unload();
delete rtMidi;
delete MO;
}

/* Load the Device Manager from saved Config Store data.
Expand Down Expand Up @@ -61,6 +62,18 @@ void DeviceManager::Load(obs_data_t *data)
}
}


void DeviceManager::Unload()
{
blog(LOG_INFO, "UNLOADING DEVICE MANAGER");
for (auto agent : midiAgents)
{
delete agent;
}
midiAgents.clear();
}


/* Returns vector list of Port Names
*/
vector<string> DeviceManager::GetPortsList()
Expand All @@ -72,6 +85,8 @@ vector<string> DeviceManager::GetPortsList()
}
return ports;
}


/* Returns vector list of Port Names
*/
vector<string> DeviceManager::GetOutPortsList()
Expand All @@ -89,6 +104,8 @@ QStringList DeviceManager::GetOPL()
{
return opl;
}


/* Returns the port number of the specified device.
* If the device isn't found (possibly due to being disconnected), returns -1
*/
Expand All @@ -103,6 +120,7 @@ int DeviceManager::GetPortNumberByDeviceName(const char *deviceName)
}
}


/* Returns the port number of the specified device.
* If the device isn't found (possibly due to being disconnected), returns -1
*/
Expand All @@ -119,11 +137,13 @@ int DeviceManager::GetOutPortNumberByDeviceName(const char *deviceName)
}
}


vector<MidiAgent *> DeviceManager::GetActiveMidiDevices()
{
return midiAgents;
}


MidiAgent *DeviceManager::GetMidiDeviceByName(const char *deviceName)
{
for (int i = 0; i < midiAgents.size(); i++) {
Expand All @@ -134,6 +154,7 @@ MidiAgent *DeviceManager::GetMidiDeviceByName(const char *deviceName)
return NULL;
}


vector<MidiHook *>
DeviceManager::GetMidiHooksByDeviceName(const char *deviceName)
{
Expand All @@ -144,19 +165,20 @@ DeviceManager::GetMidiHooksByDeviceName(const char *deviceName)
throw("no midi hooks for this device");
}


/* Registers a midi device.
* Will create, store and enable a midi device.
*/
void DeviceManager::RegisterMidiDevice(int port, int outport)
{

MidiAgent *midiA = new MidiAgent();
midiA->OpenPort(port);
midiA->OpenOutPort(outport);

midiAgents.push_back(midiA);
}


/* Get this Device Manager state as OBS Data. (includes devices and their midi hooks)
* This is needed to Serialize the state in the config.
* https://obsproject.com/docs/reference-settings.html
Expand All @@ -175,12 +197,15 @@ obs_data_t *DeviceManager::GetData()
return data;
}


void DeviceManager::SendMidi(QString mtype, int channel, int norc, int value)

{

//***Need to add message Deletion here***//
}


void DeviceManager::broadcast(const RpcEvent &event)
{
OBSDataAutoRelease eventData = obs_data_create();
Expand Down
1 change: 1 addition & 0 deletions src/device-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class DeviceManager : public QObject {
DeviceManager();
~DeviceManager();
void Load(obs_data_t *data);
void Unload();

vector<string> GetPortsList();
int GetPortNumberByDeviceName(const char *deviceName);
Expand Down
1 change: 1 addition & 0 deletions src/midi-agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ MidiAgent::MidiAgent()

MidiAgent::~MidiAgent()
{
ClearMidiHooks();
ClosePort();
delete midiin;
delete midiout;
Expand Down
1 change: 1 addition & 0 deletions src/midi-agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class MidiHook {
: type(midiMessageType),
index(midiChannelIndex),
mchan(midiChannel),
bidirectional(bidirectionals),
command(OBSCommand),
param1(p1),
param2(p2),
Expand Down
3 changes: 1 addition & 2 deletions src/obs-midi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ OBS_DECLARE_MODULE()
OBS_MODULE_USE_DEFAULT_LOCALE("obs-midi", "en-US")
ConfigPtr _config;
DeviceManagerPtr _deviceManager;

eventsPtr _eventsSystem;

bool obs_module_load(void)
{
blog(LOG_INFO, "MIDI LOADED ");
blog(LOG_INFO, "MIDI LOADED :)");

// Device Manager Setup
_deviceManager = DeviceManagerPtr(new DeviceManager());
Expand Down
4 changes: 2 additions & 2 deletions src/version.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef VERSION_H
#define VERSION_H

#define GIT_BRANCH "master"
#define GIT_COMMIT_HASH "d565d6d"
#define GIT_BRANCH "fixes"
#define GIT_COMMIT_HASH "3e9ad09"

#endif

0 comments on commit 1465753

Please sign in to comment.