Reading audio output is stopped when audio visualizers are not in used.
1 using Ear = SharpLib.Ear;
4 using System.Collections.Generic;
5 using System.Diagnostics;
8 using System.Threading.Tasks;
9 using System.Runtime.Serialization;
10 using System.Windows.Forms;
11 using CodeProject.Dialog;
13 namespace SharpDisplayManager
16 [AttributeObject(Id = "Harmony.Command", Name = "Harmony Command", Description = "Send a command to your Logitech Harmony Hub.")]
17 class ActionHarmonyCommand : Ear.Action
20 public string DeviceId { get; set; } = "";
23 public string Command { get; set; } = "";
26 [AttributeObjectProperty(
27 Id = "Harmony.Command.SelectCommand",
28 Name = "Select command",
29 Description = "Click to select a command."
31 public PropertyButton SelectCommand { get; set; } = new PropertyButton { Text = "None" };
36 /// <returns></returns>
37 public override string BriefBase()
39 string brief="Harmony: ";
41 if (Program.HarmonyConfig != null)
43 //What if the device ID is not there anymore?
44 brief += Program.HarmonyConfig.DeviceNameFromId(DeviceId);
48 //No config found just show the device ID then.
52 // TODO: Fetch function label from command
53 brief += " do " + Command;
59 protected override void DoConstruct()
63 if (SelectCommand == null)
65 SelectCommand = new PropertyButton { Text = "None"};
67 SelectCommand.ClickEventHandler = ClickEventHandler;
73 protected override async Task DoExecute()
75 if (Program.HarmonyClient!=null)
77 // Send our command and wait for it async
78 await Program.HarmonyClient.TrySendKeyPressAsync(DeviceId, Command);
82 Trace.WriteLine("WARNING: No Harmony client connection.");
90 /// <returns></returns>
91 public override bool IsValid()
93 if (Program.HarmonyConfig != null)
95 foreach (HarmonyHub.Device d in Program.HarmonyConfig.Devices)
97 if (d.Id.Equals(DeviceId))
99 foreach (HarmonyHub.ControlGroup cg in d.ControlGroups)
101 foreach (HarmonyHub.Function f in cg.Functions)
103 if (f.Action.Command.Equals(Command))
105 //We found our device and our function
120 /// <param name="sender"></param>
121 /// <param name="e"></param>
122 void ClickEventHandler(object sender, EventArgs e)
124 if (Program.HarmonyConfig == null)
126 ErrBox.Show("No Harmony Hub configuration!");
130 FormSelectHarmonyCommand dlg = new FormSelectHarmonyCommand();
131 DialogResult res = CodeProject.Dialog.DlgBox.ShowDialog(dlg);
132 if (res == DialogResult.OK)
134 DeviceId = dlg.DeviceId;
135 Command = dlg.Command;
136 SelectCommand.Text = Brief();
137 //Tell observer the object itself changed
138 OnPropertyChanged("Brief");