Skip to content

Commit

Permalink
Implement #27, #35, #37
Browse files Browse the repository at this point in the history
  • Loading branch information
nhielost committed Nov 11, 2022
1 parent 2ae9270 commit 2904cb5
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 131 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.16...3.21)

# Change obs-plugintemplate to your plugin's name in a machine-readable format
# (e.g.: obs-myawesomeplugin) and set
project(obs-midi-mg VERSION 2.1.0)
project(obs-midi-mg VERSION 2.1.1)
add_library(obs-midi-mg MODULE)

# Replace `Your Name Here` with the name (yours or your organization's) you want
Expand Down Expand Up @@ -103,7 +103,7 @@ elseif(OS_MACOS)

set(MACOSX_PLUGIN_GUI_IDENTIFIER "${MACOS_BUNDLEID}")
set(MACOSX_PLUGIN_BUNDLE_VERSION "${CMAKE_PROJECT_VERSION}")
set(MACOSX_PLUGIN_SHORT_VERSION_STRING "2.1.0")
set(MACOSX_PLUGIN_SHORT_VERSION_STRING "2.1.1")

target_compile_options(obs-midi-mg PRIVATE -Wall)
# --- End of section ---
Expand Down
2 changes: 1 addition & 1 deletion buildspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@
}
},
"name": "obs-midi-mg",
"version": "2.1.0"
"version": "2.1.1"
}
50 changes: 25 additions & 25 deletions src/macros/mmg-window-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
ui->label_double1->setText("Time"); \
lcd_double1.set_range(0.0, 1000.0); \
lcd_double1.set_step(1.0, 10.0); \
lcd_double1.reset(); \
lcd_double1.set_default_value(0.0); \
break; \
default: \
break; \
Expand Down Expand Up @@ -283,15 +283,15 @@ with this program. If not, see <https://www.gnu.org/licenses/>
ui->label_double1->setText("Volume"); \
lcd_double1.set_range(0.0, 100.0); \
lcd_double1.set_step(1.0, 10.0); \
lcd_double1.reset(); \
lcd_double1.set_default_value(0.0); \
break; \
case MMGAction::AudioSources::SOURCE_AUDIO_VOLUME_CHANGEBY: \
set_doubles_visible(true); \
COMBOBOX_ITEM_STATE(editor_double1, 1, false); \
ui->label_double1->setText("Volume Adj."); \
lcd_double1.set_range(-50.0, 50.0); \
lcd_double1.set_step(1.0, 10.0); \
lcd_double1.reset(); \
lcd_double1.set_default_value(0.0); \
break; \
case MMGAction::AudioSources::SOURCE_AUDIO_VOLUME_MUTE_ON: \
case MMGAction::AudioSources::SOURCE_AUDIO_VOLUME_MUTE_OFF: \
Expand All @@ -303,7 +303,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
ui->label_double1->setText("Offset"); \
lcd_double1.set_range(0.0, 20000.0); \
lcd_double1.set_step(25.0, 250.0); \
lcd_double1.reset(); \
lcd_double1.set_default_value(0.0); \
break; \
case MMGAction::AudioSources::SOURCE_AUDIO_MONITOR: \
set_strs_visible(true, true); \
Expand All @@ -330,7 +330,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
0.0, get_obs_media_length( \
current_action->get_str(0))); \
lcd_double1.set_step(1.0, 10.0); \
lcd_double1.reset(); \
lcd_double1.set_default_value(0.0); \
break; \
case MMGAction::MediaSources::SOURCE_MEDIA_SKIP_FORWARD_TRACK: \
case MMGAction::MediaSources::SOURCE_MEDIA_SKIP_BACKWARD_TRACK: \
Expand All @@ -344,7 +344,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
0.0, get_obs_media_length( \
current_action->get_str(0))); \
lcd_double1.set_step(1.0, 10.0); \
lcd_double1.reset(); \
lcd_double1.set_default_value(0.0); \
break; \
default: \
break; \
Expand All @@ -358,15 +358,15 @@ with this program. If not, see <https://www.gnu.org/licenses/>
ui->label_double1->setText("Duration"); \
lcd_double1.set_range(25.0, 20000.0); \
lcd_double1.set_step(25.0, 250.0); \
lcd_double1.reset( \
lcd_double1.set_default_value( \
obs_frontend_get_transition_duration()); \
break; \
/*case MMGAction::Transitions::TRANSITION_TBAR:\
set_doubles_visible(true);\
ui->label_double1->setText("Position (%)");\
lcd_double1.set_range(0.0, 100.0);\
lcd_double1.set_step(0.5, 5.0);\
lcd_double1.reset();\
lcd_double1.set_default_value(0.0);\
break;*/ \
case MMGAction::Transitions::TRANSITION_SOURCE_SHOW: \
case MMGAction::Transitions::TRANSITION_SOURCE_HIDE: \
Expand Down Expand Up @@ -432,11 +432,11 @@ with this program. If not, see <https://www.gnu.org/licenses/>
lcd_double1.set_range(0.0, \
get_obs_dimensions().first); \
lcd_double1.set_step(0.5, 5.0); \
lcd_double1.reset(); \
lcd_double1.set_default_value(0.0); \
lcd_double2.set_range(0.0, \
get_obs_dimensions().second); \
lcd_double2.set_step(0.5, 5.0); \
lcd_double2.reset(); \
lcd_double2.set_default_value(0.0); \
break; \
case MMGAction::VideoSources::SOURCE_VIDEO_DISPLAY: \
set_strs_visible(true, true, true); \
Expand All @@ -463,22 +463,22 @@ with this program. If not, see <https://www.gnu.org/licenses/>
0.0, \
get_obs_source_dimensions(value).second >> 1); \
lcd_double1.set_step(0.5, 5.0); \
lcd_double1.reset(); \
lcd_double1.set_default_value(0.0); \
lcd_double2.set_range( \
0.0, \
get_obs_source_dimensions(value).first >> 1); \
lcd_double2.set_step(0.5, 5.0); \
lcd_double2.reset(); \
lcd_double2.set_default_value(0.0); \
lcd_double3.set_range( \
0.0, \
get_obs_source_dimensions(value).second >> 1); \
lcd_double3.set_step(0.5, 5.0); \
lcd_double3.reset(); \
lcd_double3.set_default_value(0.0); \
lcd_double4.set_range( \
0.0, \
get_obs_source_dimensions(value).first >> 1); \
lcd_double4.set_step(0.5, 5.0); \
lcd_double4.reset(); \
lcd_double4.set_default_value(0.0); \
break; \
case MMGAction::VideoSources::SOURCE_VIDEO_ALIGNMENT: \
set_strs_visible(true, true, true); \
Expand All @@ -500,13 +500,13 @@ with this program. If not, see <https://www.gnu.org/licenses/>
ui->label_double3->setText("Magnitude"); \
lcd_double1.set_range(0.0, 100.0); \
lcd_double1.set_step(1.0, 10.0); \
lcd_double1.reset(0.0); \
lcd_double1.set_default_value(0.0); \
lcd_double2.set_range(0.0, 100.0); \
lcd_double2.set_step(1.0, 10.0); \
lcd_double2.reset(0.0); \
lcd_double2.set_default_value(0.0); \
lcd_double3.set_range(0.5, 100.0); \
lcd_double3.set_step(0.5, 5.0); \
lcd_double3.reset(1.0); \
lcd_double3.set_default_value(1.0); \
break; \
case MMGAction::VideoSources::SOURCE_VIDEO_SCALEFILTER: \
set_strs_visible(true, true, true); \
Expand All @@ -520,7 +520,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
ui->label_double1->setText("Rotation"); \
lcd_double1.set_range(0.0, 360.0); \
lcd_double1.set_step(0.5, 5.0); \
lcd_double1.reset(); \
lcd_double1.set_default_value(0.0); \
break; \
case MMGAction::VideoSources::SOURCE_VIDEO_BOUNDING_BOX_TYPE: \
set_strs_visible(true, true, true); \
Expand All @@ -544,13 +544,13 @@ with this program. If not, see <https://www.gnu.org/licenses/>
ui->editor_str1->currentText()) \
.first); \
lcd_double1.set_step(0.5, 5.0); \
lcd_double1.reset(); \
lcd_double1.set_default_value(0.0); \
lcd_double2.set_range( \
0.0, get_obs_source_dimensions( \
ui->editor_str1->currentText()) \
.second); \
lcd_double2.set_step(0.5, 5.0); \
lcd_double2.reset(); \
lcd_double2.set_default_value(0.0); \
break; \
case MMGAction::VideoSources::SOURCE_VIDEO_BOUNDING_BOX_ALIGN: \
set_strs_visible(true, true, true); \
Expand Down Expand Up @@ -608,7 +608,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
1.0, get_obs_source_filter_count( \
ui->editor_str1->currentText())); \
lcd_double1.set_step(1.0, 5.0); \
lcd_double1.reset(1.0); \
lcd_double1.set_default_value(1.0); \
break; \
default: \
break; \
Expand All @@ -619,13 +619,13 @@ with this program. If not, see <https://www.gnu.org/licenses/>
ui->label_double1->setText("Channel"); \
lcd_double1.set_range(1.0, 16.0); \
lcd_double1.set_step(1.0, 5.0); \
lcd_double1.reset(1.0); \
lcd_double1.set_default_value(1.0); \
lcd_double2.set_range(0.0, 127.0); \
lcd_double2.set_step(1.0, 10.0); \
lcd_double2.reset(); \
lcd_double2.set_default_value(0.0); \
lcd_double3.set_range(0.0, 127.0); \
lcd_double3.set_step(1.0, 10.0); \
lcd_double3.reset(); \
lcd_double3.set_default_value(0.0); \
if (value == "Note On" || value == "Note Off") { \
set_doubles_visible(true, true, true); \
ui->label_double2->setText("Note #"); \
Expand Down Expand Up @@ -686,7 +686,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
ui->label_double1->setText("Duration"); \
lcd_double1.set_range(0.0, 20000.0); \
lcd_double1.set_step(25.0, 250.0); \
lcd_double1.reset(); \
lcd_double1.set_default_value(0.0); \
break; \
default: \
break; \
Expand Down
7 changes: 1 addition & 6 deletions src/mmg-binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ qulonglong MMGBinding::next_default = 1;
MMGBinding::MMGBinding()
{
name = get_next_default_name();
toggling = false;
enabled = true;
message = new MMGMessage;
action = new MMGAction;
Expand All @@ -35,7 +34,6 @@ MMGBinding::MMGBinding(const QJsonObject &obj)
name = obj["name"].toString();
if (name.isEmpty())
name = get_next_default_name();
toggling = obj["toggling"].toBool();
enabled = obj["enabled"].toBool(true);
message = new MMGMessage(obj["message"].toObject());
action = new MMGAction(obj["action"].toObject());
Expand All @@ -45,7 +43,6 @@ MMGBinding::MMGBinding(const QJsonObject &obj)
void MMGBinding::json(QJsonObject &binding_obj) const
{
binding_obj["name"] = name;
binding_obj["toggling"] = toggling;
binding_obj["enabled"] = enabled;
QJsonObject msg;
message->json(msg);
Expand Down Expand Up @@ -79,15 +76,13 @@ void MMGBinding::do_action(const MMGSharedMessage &incoming)

action->do_action(incoming);

if (toggling)
message->toggle();
message->toggle();
}

void MMGBinding::deep_copy(MMGBinding *dest)
{
if (!name.contains("Untitled Binding"))
dest->set_name(name);
dest->set_toggling(get_toggling());
message->deep_copy(dest->get_message());
action->deep_copy(dest->get_action());
}
3 changes: 0 additions & 3 deletions src/mmg-binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ class MMGBinding {
void blog(int log_status, const QString &message) const;

const QString &get_name() const { return name; };
bool get_toggling() const { return toggling; };
bool get_enabled() const { return enabled; };

void set_name(const QString &val) { name = val; };
void set_toggling(bool val) { toggling = val; };
void set_enabled(bool val) { enabled = val; };

MMGMessage *const get_message() const { return message; };
Expand All @@ -54,7 +52,6 @@ class MMGBinding {

private:
QString name;
bool toggling;
bool enabled;
MMGMessage *message;
MMGAction *action;
Expand Down
1 change: 0 additions & 1 deletion src/mmg-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ bool json_old_bindings(const QJsonObject &json, MMGDevice *parent)
} else {
binding->set_name(json["name"].toString());
}
binding->set_toggling(json["toggling"].toBool());
if (message_list.value(i)) {
*(binding->get_message()) = *(message_list[i]);
} else {
Expand Down
41 changes: 30 additions & 11 deletions src/mmg-message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ MMGMessage::MMGMessage()
note = 0;
value = 0;
value_require = false;
value_toggle = false;
type_toggle = false;
blog(LOG_DEBUG, "Empty message created.");
}

Expand All @@ -35,6 +37,8 @@ MMGMessage::MMGMessage(const libremidi::message &message)
note = get_midi_note(message);
value = get_midi_value(message);
value_require = true;
value_toggle = false;
type_toggle = false;
}

MMGMessage::MMGMessage(const QJsonObject &obj)
Expand All @@ -44,6 +48,8 @@ MMGMessage::MMGMessage(const QJsonObject &obj)
note = obj["note"].toInt();
value = obj["value"].toInt();
value_require = obj["value_require"].toBool(value != -1);
value_toggle = obj["value_toggle"].toBool();
type_toggle = obj["type_toggle"].toBool();
blog(LOG_DEBUG, "Message created.");
}

Expand All @@ -54,6 +60,8 @@ void MMGMessage::json(QJsonObject &message_obj) const
message_obj["note"] = note;
message_obj["value"] = value;
message_obj["value_require"] = value_require;
message_obj["value_toggle"] = value_toggle;
message_obj["type_toggle"] = type_toggle;
}

void MMGMessage::blog(int log_status, const QString &message) const
Expand Down Expand Up @@ -147,23 +155,32 @@ QString MMGMessage::get_midi_type(const libremidi::message &mess)

void MMGMessage::toggle()
{
if (type == "Note On") {
type = "Note Off";
} else if (type == "Note Off") {
type = "Note On";
if (type_toggle) {
if (type == "Note On") {
type = "Note Off";
} else if (type == "Note Off") {
type = "Note On";
}
}
if (value_toggle) {
if (value == 127) {
value = 0;
} else if (value == 0) {
value = 127;
}
}
}

bool MMGMessage::is_acceptable(const MMGMessage *test) const
{
bool isTrue = true;
isTrue &= (channel == test->get_channel());
isTrue &= (type == test->get_type());
bool is_true = true;
is_true &= (channel == test->get_channel());
is_true &= (type == test->get_type());
if (type != "Program Change" && type != "Pitch Bend")
isTrue &= (note == test->get_note());
if (value_require)
isTrue &= (value == test->get_value());
return isTrue;
is_true &= (note == test->get_note());
if (value_require || value_toggle)
is_true &= (value == test->get_value());
return is_true;
}

void MMGMessage::deep_copy(MMGMessage *dest)
Expand All @@ -173,4 +190,6 @@ void MMGMessage::deep_copy(MMGMessage *dest)
dest->set_note(note);
dest->set_value(value);
dest->set_value_required(value_require);
dest->set_value_toggle(value_toggle);
dest->set_type_toggle(type_toggle);
}
6 changes: 6 additions & 0 deletions src/mmg-message.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ class MMGMessage {
int get_note() const { return note; };
int get_value() const { return value; };
bool get_value_required() const { return value_require; };
bool get_value_toggle() const { return value_toggle; }
bool get_type_toggle() const { return type_toggle; }

void set_type(const QString &val) { type = val; };
void set_channel(int val) { channel = val; };
void set_note(int val) { note = val; };
void set_value(int val) { value = val; };
void set_value_required(bool val) { value_require = val; };
void set_value_toggle(bool val) { value_toggle = val; };
void set_type_toggle(bool val) { type_toggle = val; };

void toggle();
bool is_acceptable(const MMGMessage *test) const;
Expand All @@ -55,6 +59,8 @@ class MMGMessage {
int note;
int value;
bool value_require;
bool value_toggle;
bool type_toggle;
};

using MMGSharedMessage = QSharedPointer<MMGMessage>;
Loading

0 comments on commit 2904cb5

Please sign in to comment.