Skip to content

Commit

Permalink
Default Audio Switcher Added
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisIsBackAU committed Mar 30, 2023
1 parent df021ae commit b48e49b
Show file tree
Hide file tree
Showing 13 changed files with 756 additions and 13 deletions.
18 changes: 18 additions & 0 deletions Oculus VR Dash Manager/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@
<setting name="QuestPolling" serializeAs="String">
<value>False</value>
</setting>
<setting name="Automatic_Audio_Switching" serializeAs="String">
<value>False</value>
</setting>
<setting name="Normal_Speaker_ID" serializeAs="String">
<value>-1</value>
</setting>
<setting name="Quest_Speaker_ID" serializeAs="String">
<value>-1</value>
</setting>
<setting name="Normal_Speaker_GUID" serializeAs="String">
<value>00000000-0000-0000-0000-000000000000</value>
</setting>
<setting name="Quest_Speaker_GUID" serializeAs="String">
<value>00000000-0000-0000-0000-000000000000</value>
</setting>
<setting name="Auto_Audio_Change_DefaultCommunication" serializeAs="String">
<value>False</value>
</setting>
</OVR_Dash_Manager.Properties.Settings>
</userSettings>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<Window x:Class="OVR_Dash_Manager.Forms.Auto_Program_Launch.frm_Auto_Program_Launch_Settings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:OVR_Dash_Manager.Forms.Auto_Program_Launch"
Title="Auto Program Launch Settings" Height="450" Width="800" Loaded="Window_Loaded" Closing="Window_Closing">

<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../../Theme/MetroDark.MSControls.Core.Implicit.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>

<Grid x:Name="gd_Settings" Background="#FF212121">
<ListView x:Name="lv_Programs" Margin="10,45,10,10" AlternationCount="2" >
<ListView.View>
<GridView>
<GridViewColumn Header="Icon" Width="50">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Image x:Name="img_Icon" Width="16" Height="16" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="File Name" Width="Auto"/>
<GridViewColumn Header="File Path" Width="Auto"/>
<GridViewColumn Header="Auto Launch On Startup" Width="50">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox x:Name="chkbx_Auto_Launch_On_Startup" Content="Launch on Startup" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<Button x:Name="btn_Add_Program" Content="Add Program" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="115" Height="23" Click="btn_Add_Program_Click"/>
<Button x:Name="btn_Remove_Program" Content="Remove Program" HorizontalAlignment="Left" Margin="150,10,0,0" VerticalAlignment="Top" Width="140" Height="23" Click="btn_Remove_Program_Click"/>
<Button x:Name="btn_Open_Program_Folder" Content="Open Program Folder" HorizontalAlignment="Left" Margin="316,10,0,0" VerticalAlignment="Top" Width="180" Height="23" Click="btn_Remove_Program_Click"/>

</Grid>
</Window>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace OVR_Dash_Manager.Forms.Auto_Program_Launch
{
/// <summary>
/// Interaction logic for frm_Auto_Program_Launch_Settings.xaml
/// </summary>
public partial class frm_Auto_Program_Launch_Settings : Window
{
public frm_Auto_Program_Launch_Settings()
{
InitializeComponent();
}

private void btn_Add_Program_Click(object sender, RoutedEventArgs e)
{

}

private void btn_Remove_Program_Click(object sender, RoutedEventArgs e)
{

}

private void Window_Loaded(object sender, RoutedEventArgs e)
{

}

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{

}
}
}
19 changes: 17 additions & 2 deletions Oculus VR Dash Manager/Forms/Settings/frm_Settings_v2.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:OVR_Dash_Manager.Forms.Settings"
mc:Ignorable="d"
Title="Settings" Width="863" Height="660.422" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen">
Title="Settings" Width="863" Height="875.24" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen" Loaded="Window_Loaded" Closing="Window_Closing">

<Window.Resources>
<ResourceDictionary>
Expand Down Expand Up @@ -46,8 +46,23 @@
<local:uc_Setting Setting="SteamVRFocusFix" Margin="10,3,0,0" HorizontalAlignment="Left" Width="150" Height="30" VerticalAlignment="Top" />
<Label Content="Fix SteamVR Admin Program Focus Issue When it Occurs (Task View Glitch)" Margin="166,3,10,0" VerticalAlignment="Top" Height="30" />
<local:uc_Setting Setting="ExitLinkOn_UserExit_SteamVR" Margin="10,41,0,0" HorizontalAlignment="Left" Width="150" Height="30" VerticalAlignment="Top" />
<Label Content="Exit Oculus Link when User Closes Steam VR (Stable Link Connection Recommended)" HorizontalAlignment="Left" Margin="166,41,0,0" VerticalAlignment="Top" Height="30" />
<Label Content="Exit Oculus Link when User Closes Steam VR (Stable Link Connection Recommended)" Margin="166,41,10,0" VerticalAlignment="Top" Height="30" />
</Grid>
</GroupBox>
<GroupBox Header="Automatic Audio Switcher" Margin="10,617,10,11">
<Grid Margin="0">
<local:uc_Setting Setting="Automatic_Audio_Switching" HorizontalAlignment="Left" Width="150" Height="30" VerticalAlignment="Top" />
<Label Content="Automatically Switch Audio on Program Launch (to Quest Speaker) &amp; Program Close (to Normal Speaker)" VerticalAlignment="Top" Height="30" Margin="155,0,10,0" />
<local:uc_Setting Setting="Auto_Audio_Change_DefaultCommunication" HorizontalAlignment="Left" Width="150" Height="30" VerticalAlignment="Top" Margin="0,32,0,0" />
<Label Content="Change Default Communications Device As Well" VerticalAlignment="Top" Height="30" Margin="155,33,10,0" />
<ComboBox x:Name="cbo_NormalSpeaker" Margin="155,68,170,0" VerticalAlignment="Top" DisplayMemberPath="Name" SelectionChanged="cbo_NormalSpeaker_SelectionChanged"/>
<Label Content="Normal Speaker" VerticalAlignment="Top" Height="30" Margin="0,68,0,0" HorizontalAlignment="Left" Width="150" />
<ComboBox x:Name="cbo_QuestSpeaker" Margin="155,103,170,0" VerticalAlignment="Top" DisplayMemberPath="Name" SelectionChanged="cbo_QuestSpeaker_SelectionChanged"/>
<Label Content="Quest Speaker" VerticalAlignment="Top" Height="30" Margin="0,103,0,0" HorizontalAlignment="Left" Width="150" />
<Button x:Name="btn_Set_Default_Normal" Margin="650,68,10,0" Content="Set As Current" Click="btn_Set_Default_Normal_Click" Height="30" VerticalAlignment="Top" />
<Button x:Name="btn_Set_Default_Quest" Margin="650,103,10,0" Content="Set As Current" Click="btn_Set_Default_Quest_Click" Height="30" VerticalAlignment="Top" />
</Grid>
</GroupBox>

</Grid>
</Window>
138 changes: 137 additions & 1 deletion Oculus VR Dash Manager/Forms/Settings/frm_Settings_v2.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
using System.Windows;
using PlaybackDeviceSwitcher;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Linq;
using System.Windows.Controls;

namespace OVR_Dash_Manager.Forms.Settings
{
Expand All @@ -7,9 +12,140 @@ namespace OVR_Dash_Manager.Forms.Settings
/// </summary>
public partial class frm_Settings_v2 : Window
{
bool Audio_DevicesChanged = false;
bool FireEvents = false;

public frm_Settings_v2()
{
InitializeComponent();
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
cbo_NormalSpeaker.ItemsSource = Software.Windows_Audio_v2.Speakers;
cbo_QuestSpeaker.ItemsSource = Software.Windows_Audio_v2.Speakers;

cbo_NormalSpeaker.SelectedItem = Software.Windows_Audio_v2.Speakers.FirstOrDefault(a => a.Normal_Speaker);
cbo_QuestSpeaker.SelectedItem = Software.Windows_Audio_v2.Speakers.FirstOrDefault(a => a.Quest_Speaker);

Audio_DevicesChanged = false;
FireEvents = true;
}

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (Audio_DevicesChanged)
{
if (MessageBox.Show(this, "Automatic Audio Devices Changed - Are you sure you want to save this ?", "Confirm Automatic Audio Device Change", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{

Software.Windows_Audio_v2.IDevice_Ext NormalSpeaker = Software.Windows_Audio_v2.Speakers.FirstOrDefault(a => a.Normal_Speaker);
Software.Windows_Audio_v2.IDevice_Ext QuestSpeaker = Software.Windows_Audio_v2.Speakers.FirstOrDefault(a => a.Quest_Speaker);

Properties.Settings.Default.Normal_Speaker_GUID = NormalSpeaker != null ? NormalSpeaker.ID : new System.Guid();
Properties.Settings.Default.Quest_Speaker_GUID = QuestSpeaker != null ? QuestSpeaker.ID : new System.Guid();
Properties.Settings.Default.Save();
}
}
}

private void chkbx_Normal_Speaker_Checked(object sender, RoutedEventArgs e)
{
if (sender is CheckBox Box)
{
if (Box.DataContext is Software.Windows_Audio_v2.IDevice_Ext Speaker)
CheckSpeaker(Speaker, true, true, false);
}
}

private void chkbx_Normal_Speaker_Unchecked(object sender, RoutedEventArgs e)
{
if (sender is CheckBox Box)
{
if (Box.DataContext is Software.Windows_Audio_v2.IDevice_Ext Speaker)
CheckSpeaker(Speaker, false, true, false);
}
}

private void chkbx_Quest_Speaker_Checked(object sender, RoutedEventArgs e)
{
if (sender is CheckBox Box)
{
if (Box.DataContext is Software.Windows_Audio_v2.IDevice_Ext Speaker)
CheckSpeaker(Speaker, true, false, true);
}
}

private void chkbx_Quest_Speaker_Unchecked(object sender, RoutedEventArgs e)
{
if (sender is CheckBox Box)
{
if (Box.DataContext is Software.Windows_Audio_v2.IDevice_Ext Speaker)
CheckSpeaker(Speaker, false, false, true);
}
}

private void CheckSpeaker(Software.Windows_Audio_v2.IDevice_Ext Speaker, bool Checked, bool Normal, bool Quest)
{
if (!FireEvents)
return;

FireEvents = false;

// Force reset to make sure it cant be the same audio device
Audio_DevicesChanged = true;
Speaker.Quest_Speaker = false;
Speaker.Normal_Speaker = false;

if (Normal)
{
Software.Windows_Audio_v2.Speakers.ForEach(a => a.Normal_Speaker = false); // Remove all normals and just set the current
Speaker.Normal_Speaker = Checked;
}

if (Quest)
{
Software.Windows_Audio_v2.Speakers.ForEach(a => a.Quest_Speaker = false); // Remove all quests and just set the current
Speaker.Quest_Speaker = Checked;
}

FireEvents = true;
}

private void btn_Set_Default_Normal_Click(object sender, RoutedEventArgs e)
{
Software.Windows_Audio_v2.IDevice_Ext NormalSpeaker = Software.Windows_Audio_v2.Speakers.FirstOrDefault(a => a.Normal_Speaker);
if (NormalSpeaker != null)
Software.Windows_Audio_v2.Set_Default_PlaybackDevice(NormalSpeaker.ID);
else
MessageBox.Show(this, "Normal Speaker Not Found", "Normal Speaker Not Found", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}

private void btn_Set_Default_Quest_Click(object sender, RoutedEventArgs e)
{
Software.Windows_Audio_v2.IDevice_Ext QuestSpeaker = Software.Windows_Audio_v2.Speakers.FirstOrDefault(a => a.Quest_Speaker);
if (QuestSpeaker != null)
Software.Windows_Audio_v2.Set_Default_PlaybackDevice(QuestSpeaker.ID);
else
MessageBox.Show(this, "Quest Speaker Not Set", "Quest Speaker Not Set", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}

private void cbo_NormalSpeaker_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (cbo_NormalSpeaker.SelectedItem is Software.Windows_Audio_v2.IDevice_Ext Speaker)
{
CheckSpeaker(Speaker, true, true, false);
}
}

private void cbo_QuestSpeaker_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (cbo_QuestSpeaker.SelectedItem is Software.Windows_Audio_v2.IDevice_Ext Speaker)
{
CheckSpeaker(Speaker, true, false, true);
}
}
}


}
21 changes: 16 additions & 5 deletions Oculus VR Dash Manager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using OVR_Dash_Manager.Software;
using PlaybackDeviceSwitcher;
using System;
using System.Globalization;
using System.IO;
using System.Threading;
Expand All @@ -8,7 +9,6 @@
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
using OVR_Dash_Manager.Software;
using WindowsInput;
using WindowsInput.Native;

Expand Down Expand Up @@ -36,11 +36,14 @@ public MainWindow()

Title += " v" + typeof(MainWindow).Assembly.GetName().Version;
Topmost = Properties.Settings.Default.AlwaysOnTop;


}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
btn_Diagnostics.IsEnabled = false;
btn_OpenSettings.IsEnabled = false;
lbl_CurrentSetting.Content = "Starting Up";
Elevated = Functions.Process_Functions.IsCurrentProcess_Elevated();

Expand All @@ -67,6 +70,7 @@ private void Steam_Steam_VR_Running_State_Changed_Event()

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Software.Windows_Audio_v2.Set_To_Normal_Speaker_Auto();
Software.ADB.Stop();
Functions.Process_Watcher.Stop();

Expand Down Expand Up @@ -140,9 +144,16 @@ private void Startup()

CheckRunTime();

Software.Windows_Audio_v2.Setup();
Software.Windows_Audio_v2.Set_To_Quest_Speaker_Auto();

//Software.Windows_Audio.Setup();
//Software.Windows_Audio.Set_To_Quest_Speaker_Auto();

Functions_Old.DoAction(this, new Action(delegate ()
{
btn_Diagnostics.IsEnabled = true;
btn_OpenSettings.IsEnabled = true;
lbl_SteamVR_Status.Content = "Installed: " + Software.Steam.Steam_VR_Installed;
lbl_CurrentSetting.Content = Software.Oculus.Current_Dash_Name;
Update_Dash_Buttons();
Expand Down Expand Up @@ -276,7 +287,7 @@ private void btn_ActivateDash_Click(object sender, RoutedEventArgs e)

if (sender is Button button)
ActivateDash(button);

Thread ReactivateButtons = new Thread(Thread_ReactivateButtons);
ReactivateButtons.IsBackground = true;
ReactivateButtons.Start();
Expand All @@ -286,7 +297,7 @@ private void btn_ActivateDash_Click(object sender, RoutedEventArgs e)

private void Thread_ReactivateButtons()
{
Thread.Sleep(10000);
Thread.Sleep(5000);
Functions_Old.DoAction(this, new Action(delegate () { Update_Dash_Buttons(); }));
}

Expand Down
Loading

0 comments on commit b48e49b

Please sign in to comment.