-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
161 lines (149 loc) · 5.83 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using AudioSwitcher.AudioApi.CoreAudio;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace SystemVolumeEditer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
CoreAudioDevice defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice;
public static string portName = null;
private void Form1_Load(object sender, EventArgs e)
{
try
{
progressBarAudioVolume.Value = int.Parse(defaultPlaybackDevice.Volume.ToString());
labelVolume.Text = $"Ses Seviyesi: {defaultPlaybackDevice.Volume}";
}
catch (Exception ex)
{
MessageBox.Show("ex.message: " + ex.Message + " stacktrace: " + ex.StackTrace, "Data Received Error");
}
}
private void portSelectionToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
FormPortSelection portSelection = new FormPortSelection();
portSelection.ShowDialog();
if (portName != null) // port seçiminin yapılıp yapılmadığını kontrol eder
{
serialPortVolume.PortName = portName;
try
{
serialPortVolume.Open();
Text = $"{serialPortVolume.PortName} Açık";
timerVolume.Enabled = true;
timerVolume.Start();
}
catch (Exception)
{
MessageBox.Show($"{portName} Portu Açılırken Bir Hata Oluştu!", "HATA", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
catch (Exception ex)
{
MessageBox.Show("ex.message: " + ex.Message + " stacktrace: " + ex.StackTrace, "Port Selection Error");
}
}
private void serialPortVolume_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
try
{
if (serialPortVolume.BytesToRead > 0)
{
//int volume = serialPortVolume.ReadByte();
string data = serialPortVolume.ReadExisting();
if (buttonMute.ImageIndex == 1) // mute butonuna tıklandıktan sonra alınan veride anlık bir parse edememe sorunu oluyordu
{
int.TryParse(data, out int volume);
progressBarAudioVolume.Value = volume;
defaultPlaybackDevice.Volume = volume;
labelVolume.Text = $"Ses Seviyesi: {volume}";
}
}
}
catch (Exception ex)
{
MessageBox.Show("ex.message: " + ex.Message + " stacktrace: " + ex.StackTrace, "Data Received Error");
}
}
private void buttonMute_Click(object sender, EventArgs e)
{
try
{
if (buttonMute.ImageIndex == 1) // unmute
{
defaultPlaybackDevice.Mute(true); // sistem sesi mute edilir
labelVolume.Text = "Sessiz";
progressBarAudioVolume.Value = 0;
buttonMute.ImageIndex = 0; // butonun ikonu mute yapılır
}
else // mute
{
defaultPlaybackDevice.Mute(false); // sistem sesi unmute edilir
labelVolume.Text = $"Ses Seviyesi: {defaultPlaybackDevice.Volume}";
progressBarAudioVolume.Value = int.Parse(defaultPlaybackDevice.Volume.ToString());
buttonMute.ImageIndex = 1; // butonun ikonu unmute yapılır
}
}
catch (Exception ex)
{
MessageBox.Show("ex.message: " + ex.Message + " stacktrace: " + ex.StackTrace, "Mute Error");
}
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
FormAbout about = new FormAbout();
about.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show("ex.message: " + ex.Message + " stacktrace: " + ex.StackTrace, "About Error");
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
DialogResult warning = MessageBox.Show("Çıkmak İstediğinizden Emin Misiniz?", "UYARI", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if (warning == DialogResult.Yes)
serialPortVolume.Close();
else
e.Cancel = true;
}
catch (Exception ex)
{
MessageBox.Show("ex.message: " + ex.Message + " stacktrace: " + ex.StackTrace, "Closing Error");
}
}
private void timerVolume_Tick(object sender, EventArgs e)
{
try
{
progressBarAudioVolume.Value = int.Parse(defaultPlaybackDevice.Volume.ToString());
labelVolume.Text = $"Ses Seviyesi: {defaultPlaybackDevice.Volume}";
}
catch (Exception ex)
{
MessageBox.Show("ex.message: " + ex.Message + " stacktrace: " + ex.StackTrace, "Closing Error");
}
}
}
}