@@ -38,7 +38,7 @@ PluginWindow::PluginWindow(QWidget *parent) : QDialog(parent, Qt::Dialog), ui(ne
38
38
configure_table ();
39
39
hide_all_pairs ();
40
40
connect_ui_signals ();
41
-
41
+ reset_to_defaults ();
42
42
starting = false ;
43
43
}
44
44
void PluginWindow::configure_table () const
@@ -68,6 +68,7 @@ void PluginWindow::connect_ui_signals() const
68
68
connect (ui->table_mapping , SIGNAL (cellClicked (int , int )), this , SLOT (edit_mapping ()));
69
69
/* *************Connections to mappper****************/
70
70
connect (ui->btn_add , SIGNAL (clicked ()), this , SLOT (add_new_mapping ()));
71
+ connect (ui->btn_reset , SIGNAL (clicked ()), this , SLOT (reset_to_defaults ()));
71
72
connect (ui->btn_delete , SIGNAL (clicked ()), this , SLOT (delete_mapping ()));
72
73
connect (ui->tabWidget , SIGNAL (currentChanged (int )), this , SLOT (tab_changed (int )));
73
74
connect (ui->outbox , SIGNAL (currentTextChanged (QString)), this , SLOT (select_output_device (QString)));
@@ -450,16 +451,23 @@ void PluginWindow::reset_to_defaults() const
450
451
ui->cb_obs_output_audio_source ->setCurrentIndex (0 );
451
452
ui->cb_obs_output_media_source ->setCurrentIndex (0 );
452
453
ui->sb_channel ->setValue (0 );
453
- ui->sb_norc ->setValue ( 0 );
454
+ ui->sb_norc ->clear ( );
454
455
ui->cb_mtype ->setCurrentIndex (0 );
455
456
ui->slider_value ->setValue (0 );
456
457
ui->btn_add ->setText (" Add Mapping" );
457
458
ui->btn_delete ->setEnabled (false );
459
+ ui->btn_reset ->setEnabled (false );
458
460
ui->table_mapping ->clearSelection ();
461
+ ui->sb_max ->clear ();
462
+ ui->sb_min ->clear ();
463
+ ui->sb_int_override ->clear ();
464
+ clear_table ();
465
+ load_table ();
459
466
this ->ui ->table_mapping ->resizeColumnsToContents ();
460
467
}
461
468
void PluginWindow::obs_actions_select (const QString &action) const
462
469
{
470
+ ui->btn_reset ->setEnabled (true );
463
471
if (!switching) {
464
472
hide_all_pairs ();
465
473
switch (ActionsClass::string_to_action (Utils::untranslate (action))) {
@@ -605,9 +613,9 @@ void PluginWindow::obs_actions_select(const QString &action) const
605
613
ui->label_Int_override ->setText (" Duration * " );
606
614
ui->sb_int_override ->setSuffix (" ms" );
607
615
break ;
608
- case ActionsClass::Actions::Trigger_Hotkey_By_Name:
609
- show_pair (Pairs::Hotkey);
610
- break ;
616
+ case ActionsClass::Actions::Trigger_Hotkey_By_Name:
617
+ show_pair (Pairs::Hotkey);
618
+ break ;
611
619
default :
612
620
hide_all_pairs ();
613
621
break ;
@@ -673,8 +681,6 @@ void PluginWindow::add_new_mapping()
673
681
const auto row = (editmode) ? editrow : ui->table_mapping ->rowCount ();
674
682
if (!editmode)
675
683
ui->table_mapping ->insertRow (row);
676
-
677
- editmode = false ;
678
684
// don't delete it, because the table takes ownership of the items
679
685
const auto channel_item = new QTableWidgetItem (QString::number (ui->sb_channel ->value ()));
680
686
const auto message_type_item = new QTableWidgetItem (ui->cb_mtype ->currentText ());
@@ -690,47 +696,71 @@ void PluginWindow::add_new_mapping()
690
696
const auto int_override = new QTableWidgetItem (QString::number (ui->sb_int_override ->value ()));
691
697
const auto min = new QTableWidgetItem (QString::number (ui->sb_min ->value ()));
692
698
const auto max = new QTableWidgetItem (QString::number (ui->sb_max ->value ()));
693
- const auto hotkey_item = new QTableWidgetItem (ui->cb_obs_output_hotkey ->currentText ());
699
+ const auto hotkey_item = new QTableWidgetItem (ui->cb_obs_output_hotkey ->currentText ());
694
700
ui->table_mapping ->setItem (row, 0 , channel_item);
695
701
ui->table_mapping ->setItem (row, 1 , message_type_item);
696
702
ui->table_mapping ->setItem (row, 2 , norc_item);
697
703
ui->table_mapping ->setItem (row, 3 , action_item);
698
- ui->table_mapping ->setItem (row, 4 , scene_item);
699
- ui->table_mapping ->setItem (row, 5 , source_item);
700
- ui->table_mapping ->setItem (row, 6 , filter_item);
701
- ui->table_mapping ->setItem (row, 7 , transition_item);
702
- ui->table_mapping ->setItem (row, 8 , item_item);
703
- ui->table_mapping ->setItem (row, 9 , audio_item);
704
- ui->table_mapping ->setItem (row, 10 , media_item);
705
- ui->table_mapping ->setItem (row, 11 , int_override);
706
- ui->table_mapping ->setItem (row, 12 , min);
707
- ui->table_mapping ->setItem (row, 13 , max);
708
- ui->table_mapping ->setItem (row, 14 , hotkey_item);
709
-
710
- set_all_cell_colors (row);
711
- auto *new_midi_hook = (editmode) ? find_existing_hook () : new MidiHook ();
704
+
705
+ auto *new_midi_hook = new MidiHook ();
712
706
new_midi_hook->channel = ui->sb_channel ->value ();
713
707
new_midi_hook->message_type = ui->cb_mtype ->currentText ();
714
708
new_midi_hook->norc = ui->sb_norc ->value ();
715
709
new_midi_hook->value_as_filter = ui->check_use_value ->isChecked ();
716
- new_midi_hook->value .emplace (( ui->check_use_value -> isChecked ()) ? ui-> slider_value ->value () : NULL );
710
+ new_midi_hook->value .emplace (ui->slider_value ->value ());
717
711
new_midi_hook->action = ui->cb_obs_output_action ->currentText ();
718
- new_midi_hook->scene = ui->cb_obs_output_scene ->currentText ();
719
- new_midi_hook->source = ui->cb_obs_output_source ->currentText ();
720
- new_midi_hook->filter = ui->cb_obs_output_filter ->currentText ();
721
- new_midi_hook->transition = ui->cb_obs_output_transition ->currentText ();
722
- new_midi_hook->item = ui->cb_obs_output_item ->currentText ();
723
- new_midi_hook->hotkey = ui->cb_obs_output_hotkey ->currentText ();
724
- new_midi_hook->audio_source = ui->cb_obs_output_audio_source ->currentText ();
725
- new_midi_hook->media_source = ui->cb_obs_output_media_source ->currentText ();
726
- new_midi_hook->int_override .emplace (ui->sb_int_override ->value ());
727
- new_midi_hook->range_min .emplace (ui->sb_min ->value ());
728
- new_midi_hook->range_max .emplace (ui->sb_max ->value ());
712
+ if (ui->cb_obs_output_scene ->isVisible ()) {
713
+ ui->table_mapping ->setItem (row, 4 , scene_item);
714
+ new_midi_hook->scene = ui->cb_obs_output_scene ->currentText ();
715
+ }
716
+ if (ui->cb_obs_output_source ->isVisible ()) {
717
+ ui->table_mapping ->setItem (row, 5 , source_item);
718
+ new_midi_hook->source = ui->cb_obs_output_source ->currentText ();
719
+ }
720
+ if (ui->cb_obs_output_filter ->isVisible ()) {
721
+ ui->table_mapping ->setItem (row, 6 , filter_item);
722
+ new_midi_hook->filter = ui->cb_obs_output_filter ->currentText ();
723
+ }
724
+ if (ui->cb_obs_output_transition ->isVisible ()) {
725
+ ui->table_mapping ->setItem (row, 7 , transition_item);
726
+ new_midi_hook->transition = ui->cb_obs_output_transition ->currentText ();
727
+ }
728
+ if (ui->cb_obs_output_item ->isVisible ()) {
729
+ ui->table_mapping ->setItem (row, 8 , item_item);
730
+ new_midi_hook->item = ui->cb_obs_output_item ->currentText ();
731
+ }
732
+ if (ui->cb_obs_output_hotkey ->isVisible ())
733
+ new_midi_hook->hotkey = ui->cb_obs_output_hotkey ->currentText ();
734
+ if (ui->cb_obs_output_audio_source ->isVisible ()) {
735
+ ui->table_mapping ->setItem (row, 9 , audio_item);
736
+ new_midi_hook->audio_source = ui->cb_obs_output_audio_source ->currentText ();
737
+ }
738
+ if (ui->cb_obs_output_media_source ->isVisible ()) {
739
+ ui->table_mapping ->setItem (row, 10 , media_item);
740
+ new_midi_hook->media_source = ui->cb_obs_output_media_source ->currentText ();
741
+ }
742
+ if (ui->sb_int_override ->isVisible ()) {
743
+ ui->table_mapping ->setItem (row, 11 , int_override);
744
+ new_midi_hook->int_override .emplace (ui->sb_int_override ->value ());
745
+ }
746
+ if (ui->sb_min ->isVisible ()) {
747
+ ui->table_mapping ->setItem (row, 12 , min);
748
+ new_midi_hook->range_min .emplace (ui->sb_min ->value ());
749
+ }
750
+ if (ui->sb_max ->isVisible ()) {
751
+ ui->table_mapping ->setItem (row, 13 , max);
752
+ new_midi_hook->range_max .emplace (ui->sb_max ->value ());
753
+ }
754
+ ui->table_mapping ->setItem (row, 14 , hotkey_item);
729
755
new_midi_hook->setAction ();
730
- GetDeviceManager ().get ()->get_midi_device (ui->mapping_lbl_device_name ->text ())->add_MidiHook (new_midi_hook);
731
-
756
+ set_all_cell_colors (row);
757
+ if (editmode) {
758
+ GetDeviceManager ().get ()->get_midi_device (ui->mapping_lbl_device_name ->text ())->edit_midi_hook (edithook, new_midi_hook);
759
+ } else {
760
+ GetDeviceManager ().get ()->get_midi_device (ui->mapping_lbl_device_name ->text ())->add_MidiHook (new_midi_hook);
761
+ }
732
762
GetConfig ().get ()->Save ();
733
- ui-> table_mapping -> selectRow (row );
763
+ reset_to_defaults ( );
734
764
this ->ui ->table_mapping ->resizeColumnsToContents ();
735
765
} else {
736
766
if (ui->sb_channel ->value ()) {
@@ -753,6 +783,8 @@ void PluginWindow::add_new_mapping()
753
783
Utils::alert_popup (mess);
754
784
}
755
785
}
786
+ if (editmode)
787
+ editmode = false ;
756
788
}
757
789
void PluginWindow::add_row_from_hook (const MidiHook *hook) const
758
790
{
@@ -796,7 +828,7 @@ void PluginWindow::set_all_cell_colors(const int row) const
796
828
{
797
829
const QColor midi_color (0 , 170 , 255 );
798
830
const QColor action_color (170 , 0 , 255 );
799
-
831
+
800
832
for (auto col = 0 ; col <= ui->table_mapping ->columnCount (); col++) {
801
833
auto *const rc = ui->table_mapping ->item (row, col);
802
834
(col < 3 ) ? set_cell_colors (midi_color, rc) : set_cell_colors (action_color, rc);
@@ -847,32 +879,36 @@ void PluginWindow::remove_hook(MidiHook *hook) const
847
879
}
848
880
void PluginWindow::delete_mapping () const
849
881
{
850
- if (ui->table_mapping ->rowCount () > 0 ) {
851
- auto row = ui->table_mapping ->selectedItems ().at (0 )->row ();
852
- blog (LOG_DEBUG, " selected row to delete %i" , row);
853
- const auto hooks = GetDeviceManager ()->get_midi_device (ui->mapping_lbl_device_name ->text ())->GetMidiHooks ();
854
- for (auto *hook : hooks) {
855
- if ((hook->channel == ui->sb_channel ->value ()) && (hook->norc == ui->sb_norc ->value ()) &&
856
- (hook->message_type == ui->cb_mtype ->currentText ())) {
857
- if (hook->value_as_filter ) {
858
- if (hook->value == ui->slider_value ->value ()) {
859
- remove_hook (hook);
860
- ui->table_mapping ->removeRow (row);
861
- ui->table_mapping ->clearSelection ();
862
- }
863
- } else {
882
+ if (ui->table_mapping ->rowCount () <= 0 )
883
+ return ;
884
+
885
+ auto row = ui->table_mapping ->selectedItems ().at (0 )->row ();
886
+ blog (LOG_DEBUG, " selected row to delete %i" , row);
887
+ const auto hooks = GetDeviceManager ()->get_midi_device (ui->mapping_lbl_device_name ->text ())->GetMidiHooks ();
888
+ for (auto *hook : hooks) {
889
+ if ((hook->channel == ui->sb_channel ->value ()) && (hook->norc == ui->sb_norc ->value ()) && (hook->message_type == ui->cb_mtype ->currentText ())) {
890
+ if (hook->value_as_filter ) {
891
+ if (hook->value == ui->slider_value ->value ()) {
864
892
remove_hook (hook);
865
893
ui->table_mapping ->removeRow (row);
866
894
ui->table_mapping ->clearSelection ();
867
895
}
896
+ } else {
897
+ remove_hook (hook);
898
+ ui->table_mapping ->removeRow (row);
899
+ ui->table_mapping ->clearSelection ();
868
900
}
869
901
}
870
902
}
903
+ reset_to_defaults ();
871
904
}
872
905
void PluginWindow::edit_mapping ()
873
906
{
874
907
if (ui->table_mapping ->rowCount () != 0 ) {
875
908
editmode = true ;
909
+
910
+ ui->btn_add ->setText (" Save Edits" );
911
+ ui->btn_reset ->setEnabled (true );
876
912
const auto dv = GetDeviceManager ().get ()->get_midi_hooks (ui->mapping_lbl_device_name ->text ());
877
913
blog (LOG_DEBUG, " hook numners: name %s = %i" , ui->mapping_lbl_device_name ->text ().toStdString ().c_str (), dv.count ());
878
914
const auto selected_items = ui->table_mapping ->selectedItems ();
@@ -899,6 +935,7 @@ void PluginWindow::edit_mapping()
899
935
ui->check_int_override ->setChecked (check);
900
936
ui->sb_int_override ->setValue (selected_items.at (11 )->text ().toInt ());
901
937
ui->btn_delete ->setEnabled (true );
938
+ edithook = find_existing_hook ();
902
939
}
903
940
}
904
941
0 commit comments