-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSumacon.cs
82 lines (70 loc) · 2.41 KB
/
Sumacon.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
using Suconbu.Toolbox;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Suconbu.Sumacon
{
public class Sumacon : IDisposable
{
public DeviceManager DeviceManager = new DeviceManager();
public event Action<string> WriteConsoleRequested = delegate { };
public event Func<Bitmap, string> SaveCapturedImageRequested = delegate { return null; };
public event Action<Mobile.TouchPoint[]> ShowTouchMarkersRequested = delegate { };
public ColorSet ColorSet = ColorSet.Light;
public void WriteConsole(string s)
{
this.WriteConsoleRequested(s);
}
public string SaveCapturedImage(Bitmap bitmap)
{
return this.SaveCapturedImageRequested(bitmap);
}
public void ShowTouchMarkers(params Mobile.TouchPoint[] touchPoints)
{
this.ShowTouchMarkersRequested(touchPoints);
}
#region IDisposable Support
bool disposed = false;
public virtual void Dispose()
{
if (this.disposed) return;
this.DeviceManager.Dispose();
this.disposed = true;
}
#endregion
}
public static class Beep
{
public enum Note { Un, Pu = 440, Po = 880, Pe = 1760, Pi = 3520 }
readonly static Dictionary<char, float> freq = new Dictionary<char, float>()
{
{ 'C', 32.703f }, { 'D', 36.708f }, { 'E', 41.203f }, { 'F', 43.654f }, { 'G', 48.999f }, { 'A', 55.0f }, { 'B', 61.735f }
};
public static CommandContext Play(params Note[] notes)
{
return CommandContext.StartNew(() =>
{
foreach (var note in notes)
{
if (note == Note.Un) Thread.Sleep(100);
else Console.Beep((int)note, 100);
}
});
}
public static CommandContext Play(params string[] notes)
{
return CommandContext.StartNew(() =>
{
foreach (var note in notes)
{
if (string.IsNullOrEmpty(note)) Thread.Sleep(100);
else Console.Beep((int)(freq[char.ToUpper(note[0])] * Math.Pow(2, int.Parse(note[1].ToString())) - 1), 100);
}
});
}
}
}