HamBook – Diff between revs 10 and 14
?pathlinks?
Rev 10 | Rev 14 | |||
---|---|---|---|---|
Line 15... | Line 15... | |||
15 | using System.Runtime.InteropServices; |
15 | using System.Runtime.InteropServices; |
|
16 | using System.Text; |
16 | using System.Text; |
|
17 | using System.Threading; |
17 | using System.Threading; |
|
18 | using System.Threading.Tasks; |
18 | using System.Threading.Tasks; |
|
19 | using System.Windows.Forms; |
19 | using System.Windows.Forms; |
|
- | 20 | using static System.Windows.Forms.VisualStyles.VisualStyleElement; |
||
Line 20... | Line 21... | |||
20 | |
21 | |
|
21 | namespace HamBook |
22 | namespace HamBook |
|
22 | { |
23 | { |
|
23 | public partial class SpectrogramForm : Form |
24 | public partial class SpectrogramForm : Form |
|
Line 49... | Line 50... | |||
49 | InitializeComponent(); |
50 | InitializeComponent(); |
|
Line 50... | Line 51... | |||
50 | |
51 | |
|
51 | _renderCancellationTokenSource = new CancellationTokenSource(); |
52 | _renderCancellationTokenSource = new CancellationTokenSource(); |
|
52 | _renderCancellationToken = _renderCancellationTokenSource.Token; |
53 | _renderCancellationToken = _renderCancellationTokenSource.Token; |
|
53 | _windowZOrderScheduledContinuation = new ScheduledContinuation(); |
- | ||
54 | |
- | ||
55 | _spectrogramGenerator = new SpectrogramGenerator(8000, fftSize: 1024, stepSize: 1024 / 20); |
- | ||
56 | _spectrogramGenerator.Colormap = Colormap.Viridis; |
- | ||
57 | |
- | ||
Line 58... | Line 54... | |||
58 | pictureBox2.Image = _spectrogramGenerator.GetVerticalScale(pictureBox2.Width); |
54 | _windowZOrderScheduledContinuation = new ScheduledContinuation(); |
|
Line 59... | Line 55... | |||
59 | |
55 | |
|
60 | } |
56 | } |
|
61 | |
57 | |
|
62 | public SpectrogramForm(Configuration.Configuration configuration, CancellationToken cancellationToken) : this() |
58 | public SpectrogramForm(Configuration.Configuration configuration, CancellationToken cancellationToken) : this() |
|
- | 59 | { |
||
- | 60 | _configuration = configuration; |
||
- | 61 | _cancellationToken = cancellationToken; |
||
- | 62 | |
||
- | 63 | _spectrogramGenerator = new SpectrogramGenerator(_configuration.Visualisations.Spectrogram.SampleRate, fftSize: _configuration.Visualisations.Spectrogram.FFTSamples, stepSize: _configuration.Visualisations.Spectrogram.FFTSamples / _configuration.Visualisations.Spectrogram.AudioBufferTimespan); |
||
63 | { |
64 | _spectrogramGenerator.Colormap = Colormap.Viridis; |
|
Line 64... | Line 65... | |||
64 | _configuration = configuration; |
65 | |
|
65 | _cancellationToken = cancellationToken; |
66 | pictureBox2.Image = _spectrogramGenerator.GetVerticalScale(pictureBox2.Width); |
|
66 | } |
67 | } |
|
Line 91... | Line 92... | |||
91 | base.Dispose(disposing); |
92 | base.Dispose(disposing); |
|
92 | } |
93 | } |
|
Line 93... | Line 94... | |||
93 | |
94 | |
|
94 | private void SpectrogramForm_Load(object sender, EventArgs e) |
95 | private void SpectrogramForm_Load(object sender, EventArgs e) |
|
- | 96 | { |
||
- | 97 | pinToDesktopToolStripMenuItem.Checked = _configuration.Visualisations.Spectrogram.PinToDesktop; |
||
95 | { |
98 | |
|
96 | _windowZOrderScheduledContinuation.Schedule(TimeSpan.FromSeconds(1), () => |
99 | if (_configuration.Visualisations.Spectrogram.PinToDesktop) |
|
97 | { |
100 | { |
|
98 | this.InvokeIfRequired(form => |
101 | _windowZOrderScheduledContinuation.Schedule(TimeSpan.FromSeconds(1), () => |
|
- | 102 | { |
||
- | 103 | this.InvokeIfRequired(form => |
||
99 | { |
104 | { |
|
100 | SetWindowPos(Handle, HWND_BOTTOM, 0, 0, Location.X, Location.Y, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); |
105 | SetWindowPos(Handle, HWND_BOTTOM, 0, 0, Location.X, Location.Y, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); |
|
101 | }); |
106 | }); |
|
- | 107 | }, _renderCancellationToken); |
||
Line 102... | Line 108... | |||
102 | }, _renderCancellationToken); |
108 | } |
|
103 | |
109 | |
|
104 | foreach (var deviceNumber in Enumerable.Range(0, WaveIn.DeviceCount)) |
110 | foreach (var deviceNumber in Enumerable.Range(0, WaveIn.DeviceCount)) |
|
105 | { |
111 | { |
|
Line 109... | Line 115... | |||
109 | continue; |
115 | continue; |
|
110 | } |
116 | } |
|
Line 111... | Line 117... | |||
111 | |
117 | |
|
112 | _waveIn = new WaveIn(); |
118 | _waveIn = new WaveIn(); |
|
113 | _waveIn.DeviceNumber = deviceNumber; |
119 | _waveIn.DeviceNumber = deviceNumber; |
|
Line 114... | Line 120... | |||
114 | _waveIn.BufferMilliseconds = 20; |
120 | _waveIn.BufferMilliseconds = _configuration.Visualisations.Spectrogram.AudioBufferTimespan; |
|
115 | |
121 | |
|
116 | _waveIn.DataAvailable += _waveIn_DataAvailable; |
122 | _waveIn.DataAvailable += _waveIn_DataAvailable; |
|
117 | _waveIn.StartRecording(); |
123 | _waveIn.StartRecording(); |
|
Line 144... | Line 150... | |||
144 | } |
150 | } |
|
Line 145... | Line 151... | |||
145 | |
151 | |
|
146 | _spectrogramGenerator.Process(); |
152 | _spectrogramGenerator.Process(); |
|
147 | _spectrogramGenerator.SetFixedWidth(pictureBox1.Width); |
153 | _spectrogramGenerator.SetFixedWidth(pictureBox1.Width); |
|
148 | var bmpSpec = new Bitmap(_spectrogramGenerator.Width, _spectrogramGenerator.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); |
154 | var bmpSpec = new Bitmap(_spectrogramGenerator.Width, _spectrogramGenerator.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); |
|
149 | using (var bmpSpecIndexed = _spectrogramGenerator.GetBitmap(100 / 20.0)) |
155 | using (var bmpSpecIndexed = _spectrogramGenerator.GetBitmap(_configuration.Visualisations.Spectrogram.SpectrumIntensity)) |
|
150 | using (var gfx = Graphics.FromImage(bmpSpec)) |
156 | using (var gfx = Graphics.FromImage(bmpSpec)) |
|
151 | using (var pen = new Pen(Color.White)) |
157 | using (var pen = new Pen(Color.White)) |
|
152 | { |
158 | { |
|
153 | gfx.DrawImage(bmpSpecIndexed, 0, 0); |
159 | gfx.DrawImage(bmpSpecIndexed, 0, 0); |
|
Line 231... | Line 237... | |||
231 | //SetWindowPos(Handle, HWND_BOTTOM, 0, 0, Location.X, Location.Y, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); |
237 | //SetWindowPos(Handle, HWND_BOTTOM, 0, 0, Location.X, Location.Y, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); |
|
232 | } |
238 | } |
|
Line 233... | Line 239... | |||
233 | |
239 | |
|
234 | private void SpectrogramForm_MouseEnter(object sender, EventArgs e) |
240 | private void SpectrogramForm_MouseEnter(object sender, EventArgs e) |
|
235 | { |
241 | { |
|
236 | _windowZOrderScheduledContinuation.Schedule(TimeSpan.FromSeconds(1), () => |
242 | if (_configuration.Visualisations.Spectrogram.PinToDesktop) |
|
237 | { |
243 | { |
|
238 | this.InvokeIfRequired(form => |
244 | _windowZOrderScheduledContinuation.Schedule(TimeSpan.FromSeconds(1), () => |
|
- | 245 | { |
||
- | 246 | this.InvokeIfRequired(form => |
||
239 | { |
247 | { |
|
240 | SetWindowPos(Handle, HWND_TOP, 0, 0, Location.X, Location.Y, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); |
248 | SetWindowPos(Handle, HWND_TOP, 0, 0, Location.X, Location.Y, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); |
|
241 | }); |
249 | }); |
|
- | 250 | }, _renderCancellationToken); |
||
242 | }, _renderCancellationToken); |
251 | } |
|
Line 243... | Line 252... | |||
243 | } |
252 | } |
|
244 | |
253 | |
|
245 | private void SpectrogramForm_MouseLeave(object sender, EventArgs e) |
254 | private void SpectrogramForm_MouseLeave(object sender, EventArgs e) |
|
246 | { |
255 | { |
|
247 | _windowZOrderScheduledContinuation.Schedule(TimeSpan.FromSeconds(1), () => |
256 | if (_configuration.Visualisations.Spectrogram.PinToDesktop) |
|
248 | { |
257 | { |
|
- | 258 | _windowZOrderScheduledContinuation.Schedule(TimeSpan.FromSeconds(1), () => |
||
- | 259 | { |
||
249 | this.InvokeIfRequired(form => |
260 | this.InvokeIfRequired(form => |
|
250 | { |
261 | { |
|
251 | SetWindowPos(form.Handle, HWND_BOTTOM, 0, 0, Location.X, Location.Y, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); |
262 | SetWindowPos(form.Handle, HWND_BOTTOM, 0, 0, Location.X, Location.Y, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); |
|
252 | }); |
263 | }); |
|
- | 264 | |
||
- | 265 | }, _renderCancellationToken); |
||
- | 266 | } |
||
- | 267 | } |
||
- | 268 | |
||
- | 269 | private void pinToDesktopToolStripMenuItem_CheckStateChanged(object sender, EventArgs e) |
||
- | 270 | { |
||
- | 271 | var toolStripMenuItem = (ToolStripMenuItem)sender; |
||
- | 272 | |
||
- | 273 | switch(toolStripMenuItem.CheckState) |
||
- | 274 | { |
||
- | 275 | case CheckState.Checked: |
||
- | 276 | _configuration.Visualisations.Spectrogram.PinToDesktop = true; |
||
- | 277 | break; |
||
- | 278 | case CheckState.Unchecked: |
||
- | 279 | _configuration.Visualisations.Spectrogram.PinToDesktop = false; |
||
253 | |
280 | break; |
|
254 | }, _renderCancellationToken); |
281 | } |
|
255 | } |
282 | } |