├── piano.gif
├── WootingMidi
├── wooting_analog_wrapper.dll
├── App.config
├── Properties
│ ├── Settings.settings
│ ├── Settings.Designer.cs
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ └── Resources.resx
├── App.xaml.cs
├── packages.config
├── App.xaml
├── Octave.xaml.cs
├── MainWindow.xaml
├── PianoKey.cs
├── WootingMidi.csproj
├── ObservableDict.cs
├── Octave.xaml
└── MainWindow.xaml.cs
├── README.md
├── LICENSE
├── WootingMidi.sln
└── .gitignore
/piano.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/simon-wh/WootingPiano/HEAD/piano.gif
--------------------------------------------------------------------------------
/WootingMidi/wooting_analog_wrapper.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/simon-wh/WootingPiano/HEAD/WootingMidi/wooting_analog_wrapper.dll
--------------------------------------------------------------------------------
/WootingMidi/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/WootingMidi/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/WootingMidi/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace WootingMidi
10 | {
11 | ///
12 | /// Interaction logic for App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/WootingMidi/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WootingPiano
2 | Virtual MIDI keyboard for Wooting One mechanical keyboard with velocity, polyphonic aftertouch, channel aftertouch and controller output. Notes are only output for 24 keys roughly in a piano-like layout (you can see from screenshot) but CC is sent from every key using their keycode.
3 |
4 | # Installation:
5 | * go to https://github.com/simon-wh/WootingPiano/releases/latest and download WootingPiano.X.7z.
6 | * Extract with 7zip or any other archiver capable to handle 7zip.
7 | * Run WootingMidi.exe
8 |
9 | It's recommended to be used with https://www.tobias-erichsen.de/software/loopmidi.html
10 |
11 | 
12 |
--------------------------------------------------------------------------------
/WootingMidi/App.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 David Mórász
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/WootingMidi/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace WootingMidi.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/WootingMidi.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29215.179
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WootingMidi", "WootingMidi\WootingMidi.csproj", "{77C574D9-A6D3-42A4-92DC-78461285304C}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Debug|x64 = Debug|x64
12 | Release|Any CPU = Release|Any CPU
13 | Release|x64 = Release|x64
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {77C574D9-A6D3-42A4-92DC-78461285304C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {77C574D9-A6D3-42A4-92DC-78461285304C}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {77C574D9-A6D3-42A4-92DC-78461285304C}.Debug|x64.ActiveCfg = Debug|x64
19 | {77C574D9-A6D3-42A4-92DC-78461285304C}.Debug|x64.Build.0 = Debug|x64
20 | {77C574D9-A6D3-42A4-92DC-78461285304C}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {77C574D9-A6D3-42A4-92DC-78461285304C}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {77C574D9-A6D3-42A4-92DC-78461285304C}.Release|x64.ActiveCfg = Release|x64
23 | {77C574D9-A6D3-42A4-92DC-78461285304C}.Release|x64.Build.0 = Release|x64
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {EBEDAA67-02C5-4757-B499-488EBA898760}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/WootingMidi/Octave.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace WootingMidi
17 | {
18 | ///
19 | /// Interaction logic for Octave.xaml
20 | ///
21 | public partial class Octave : UserControl
22 | {
23 | public Octave()
24 | {
25 | InitializeComponent();
26 | _keyLabels = new[] { CKey, CSharpKey, DKey, DSharpKey, EKey, FKey, FSharpKey, GKey, GSharpKey, AKey, ASharpKey, HKey };
27 | Bars = new[] { C, CSharp, D, DSharp, E, F, FSharp, G, GSharp, A, ASharp, H };
28 | VelBars = new[] { CVel, CSharpVel, DVel, DSharpVel, EVel, FVel, FSharpVel, GVel, GSharpVel, AVel, ASharpVel, HVel };
29 | }
30 |
31 | private TextBlock[] _keyLabels;
32 | public ProgressBar[] Bars { get; }
33 | public ProgressBar[] VelBars { get; }
34 |
35 | public void FillKeys(string keys)
36 | {
37 | for (int i = 0; i < keys.Length && i < _keyLabels.Length; i++)
38 | {
39 | _keyLabels[i].Text = keys[i].ToString();
40 | }
41 | }
42 |
43 | public void UpdateBars(NoteKey[] bars, int offset)
44 | {
45 | for (int i = 0; i < Bars.Length; i++)
46 | {
47 | var ii = i + offset;
48 | if(ii > bars.Length - 1) break;
49 | if(bars[ii] == null) continue;
50 | Bars[i].Value = bars[ii].Pressure * 100;
51 | VelBars[i].Value = bars[ii].Velocity * 100;
52 | }
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/WootingMidi/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("WootingMidi")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("WootingMidi")]
15 | [assembly: AssemblyCopyright("Copyright © 2018")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/WootingMidi/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace WootingMidi.Properties
12 | {
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// Returns the cached ResourceManager instance used by this class.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WootingMidi.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// Overrides the current thread's CurrentUICulture property for all
56 | /// resource lookups using this strongly typed resource class.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/WootingMidi/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
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 |
--------------------------------------------------------------------------------
/WootingMidi/PianoKey.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Runtime.InteropServices;
5 | using System.Security.Cryptography.X509Certificates;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using Commons.Music.Midi;
9 | using static System.Math;
10 |
11 | namespace WootingMidi
12 | {
13 | [StructLayout(LayoutKind.Sequential)]
14 | public struct RawMidiMessage
15 | {
16 | public byte Pre;
17 | public byte Id;
18 | public byte Param;
19 | public bool Valid;
20 |
21 | public void Bytes(byte[] buf, int offs)
22 | {
23 | buf[offs + 0] = Pre;
24 | buf[offs + 1] = Id;
25 | buf[offs + 2] = Param;
26 | }
27 | public static RawMidiMessage None { get; } = new RawMidiMessage {Valid = false};
28 | }
29 |
30 | public static class MidiCc
31 | {
32 | public const byte CcPrefix = 0b1011_0000;
33 |
34 | public static RawMidiMessage Generate(int chan, int cc, double val)
35 | {
36 | var pre = (byte)(CcPrefix | ((byte)chan & 0x0F));
37 | var hi = (byte)((byte)cc & 0b01111111);
38 | var lo = (byte)((byte)(val * 127.0) & 0b01111111);
39 | return Settings.Last.SendCc ? new RawMidiMessage
40 | {
41 | Pre = pre,
42 | Id = hi,
43 | Param = lo,
44 | Valid = true
45 | } : RawMidiMessage.None;
46 | }
47 | }
48 |
49 | public static class MidiChannelAt
50 | {
51 | public const byte AtPrefix = 0b1101_0000;
52 |
53 | public static RawMidiMessage Generate(int chan, double val)
54 | {
55 | var pre = (byte)(AtPrefix | ((byte)chan & 0x0F));
56 | var lo = (byte)((byte)(val * 127.0) & 0b01111111);
57 | return Settings.Last.SendCc ? new RawMidiMessage
58 | {
59 | Pre = pre,
60 | Id = lo,
61 | Param = lo,
62 | Valid = true
63 | } : RawMidiMessage.None;
64 | }
65 | }
66 |
67 | public class NoteKey
68 | {
69 | public const byte NoteOnPrefix = 0b1001_0000;
70 | public const byte AftertouchPrefix = 0b1010_0000;
71 | public const byte NoteOffPrefix = 0b1000_0000;
72 |
73 | public uint NoteId { get; set; }
74 | public uint Channel { get; set; }
75 |
76 | public double Threshold { get; set; } = 0.1;
77 | public double Velocity { get; private set; } = 0.0;
78 | public double Pressure { get; set; }
79 |
80 | public bool NoteOn { get; private set; }
81 | public bool Aftertouching { get; private set; }
82 | public bool NoteOff { get; private set; }
83 |
84 | public RawMidiMessage MidiNoteOn()
85 | {
86 | var pre = (byte)(NoteOnPrefix | (Channel & 0x0F));
87 | var hi = (byte)(NoteId & 0b01111111);
88 | var lo = (byte)((uint)(Velocity * 127.0) & 0b01111111);
89 | return new RawMidiMessage
90 | {
91 | Pre = pre,
92 | Id = hi,
93 | Param = lo,
94 | Valid = true
95 | };
96 | }
97 |
98 | public RawMidiMessage MidiAftertouch()
99 | {
100 | var pre = (byte)(AftertouchPrefix | (Channel & 0x0F));
101 | var hi = (byte)(NoteId & 0b01111111);
102 | var lo = (byte)((uint)(Pressure * 127.0) & 0b01111111);
103 | return new RawMidiMessage
104 | {
105 | Pre = pre,
106 | Id = hi,
107 | Param = lo,
108 | Valid = true
109 | };
110 | }
111 |
112 | public RawMidiMessage MidiNoteOff()
113 | {
114 | var pre = (byte)(NoteOffPrefix | (Channel & 0x0F));
115 | var hi = (byte)(NoteId & 0b01111111);
116 | return new RawMidiMessage
117 | {
118 | Pre = pre,
119 | Id = hi,
120 | Param = 0,
121 | Valid = true
122 | };
123 | }
124 |
125 | public RawMidiMessage Submit(double currval)
126 | {
127 | Velocity = Min(Max(Max(0, currval - Pressure) * 2, Velocity * 0.9), 1);
128 | Pressure = currval;
129 |
130 | if (NoteOff)
131 | {
132 | NoteOff = false;
133 | return RawMidiMessage.None;
134 | }
135 | if (Aftertouching)
136 | {
137 | if (currval == 0.0)
138 | {
139 | Aftertouching = false;
140 | NoteOff = true;
141 | return Settings.Last.SendNote ? MidiNoteOff() : RawMidiMessage.None;
142 | }
143 | else
144 | {
145 | return Settings.Last.SendAt ? MidiAftertouch() : RawMidiMessage.None;
146 | }
147 | }
148 | if (NoteOn)
149 | {
150 | NoteOn = false;
151 | Aftertouching = true;
152 | return Settings.Last.SendAt ? MidiAftertouch() : RawMidiMessage.None;
153 | }
154 | if (currval > Threshold)
155 | {
156 | NoteOn = true;
157 | return Settings.Last.SendNote ? MidiNoteOn() : RawMidiMessage.None;
158 | }
159 | return RawMidiMessage.None;
160 | }
161 | }
162 | }
163 |
--------------------------------------------------------------------------------
/WootingMidi/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015/2017 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # Visual Studio 2017 auto generated files
33 | Generated\ Files/
34 |
35 | # MSTest test Results
36 | [Tt]est[Rr]esult*/
37 | [Bb]uild[Ll]og.*
38 |
39 | # NUNIT
40 | *.VisualState.xml
41 | TestResult.xml
42 |
43 | # Build Results of an ATL Project
44 | [Dd]ebugPS/
45 | [Rr]eleasePS/
46 | dlldata.c
47 |
48 | # Benchmark Results
49 | BenchmarkDotNet.Artifacts/
50 |
51 | # .NET Core
52 | project.lock.json
53 | project.fragment.lock.json
54 | artifacts/
55 | **/Properties/launchSettings.json
56 |
57 | # StyleCop
58 | StyleCopReport.xml
59 |
60 | # Files built by Visual Studio
61 | *_i.c
62 | *_p.c
63 | *_i.h
64 | *.ilk
65 | *.meta
66 | *.obj
67 | *.iobj
68 | *.pch
69 | *.pdb
70 | *.ipdb
71 | *.pgc
72 | *.pgd
73 | *.rsp
74 | *.sbr
75 | *.tlb
76 | *.tli
77 | *.tlh
78 | *.tmp
79 | *.tmp_proj
80 | *.log
81 | *.vspscc
82 | *.vssscc
83 | .builds
84 | *.pidb
85 | *.svclog
86 | *.scc
87 |
88 | # Chutzpah Test files
89 | _Chutzpah*
90 |
91 | # Visual C++ cache files
92 | ipch/
93 | *.aps
94 | *.ncb
95 | *.opendb
96 | *.opensdf
97 | *.sdf
98 | *.cachefile
99 | *.VC.db
100 | *.VC.VC.opendb
101 |
102 | # Visual Studio profiler
103 | *.psess
104 | *.vsp
105 | *.vspx
106 | *.sap
107 |
108 | # Visual Studio Trace Files
109 | *.e2e
110 |
111 | # TFS 2012 Local Workspace
112 | $tf/
113 |
114 | # Guidance Automation Toolkit
115 | *.gpState
116 |
117 | # ReSharper is a .NET coding add-in
118 | _ReSharper*/
119 | *.[Rr]e[Ss]harper
120 | *.DotSettings.user
121 |
122 | # JustCode is a .NET coding add-in
123 | .JustCode
124 |
125 | # TeamCity is a build add-in
126 | _TeamCity*
127 |
128 | # DotCover is a Code Coverage Tool
129 | *.dotCover
130 |
131 | # AxoCover is a Code Coverage Tool
132 | .axoCover/*
133 | !.axoCover/settings.json
134 |
135 | # Visual Studio code coverage results
136 | *.coverage
137 | *.coveragexml
138 |
139 | # NCrunch
140 | _NCrunch_*
141 | .*crunch*.local.xml
142 | nCrunchTemp_*
143 |
144 | # MightyMoose
145 | *.mm.*
146 | AutoTest.Net/
147 |
148 | # Web workbench (sass)
149 | .sass-cache/
150 |
151 | # Installshield output folder
152 | [Ee]xpress/
153 |
154 | # DocProject is a documentation generator add-in
155 | DocProject/buildhelp/
156 | DocProject/Help/*.HxT
157 | DocProject/Help/*.HxC
158 | DocProject/Help/*.hhc
159 | DocProject/Help/*.hhk
160 | DocProject/Help/*.hhp
161 | DocProject/Help/Html2
162 | DocProject/Help/html
163 |
164 | # Click-Once directory
165 | publish/
166 |
167 | # Publish Web Output
168 | *.[Pp]ublish.xml
169 | *.azurePubxml
170 | # Note: Comment the next line if you want to checkin your web deploy settings,
171 | # but database connection strings (with potential passwords) will be unencrypted
172 | *.pubxml
173 | *.publishproj
174 |
175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
176 | # checkin your Azure Web App publish settings, but sensitive information contained
177 | # in these scripts will be unencrypted
178 | PublishScripts/
179 |
180 | # NuGet Packages
181 | *.nupkg
182 | # The packages folder can be ignored because of Package Restore
183 | **/[Pp]ackages/*
184 | # except build/, which is used as an MSBuild target.
185 | !**/[Pp]ackages/build/
186 | # Uncomment if necessary however generally it will be regenerated when needed
187 | #!**/[Pp]ackages/repositories.config
188 | # NuGet v3's project.json files produces more ignorable files
189 | *.nuget.props
190 | *.nuget.targets
191 |
192 | # Microsoft Azure Build Output
193 | csx/
194 | *.build.csdef
195 |
196 | # Microsoft Azure Emulator
197 | ecf/
198 | rcf/
199 |
200 | # Windows Store app package directories and files
201 | AppPackages/
202 | BundleArtifacts/
203 | Package.StoreAssociation.xml
204 | _pkginfo.txt
205 | *.appx
206 |
207 | # Visual Studio cache files
208 | # files ending in .cache can be ignored
209 | *.[Cc]ache
210 | # but keep track of directories ending in .cache
211 | !*.[Cc]ache/
212 |
213 | # Others
214 | ClientBin/
215 | ~$*
216 | *~
217 | *.dbmdl
218 | *.dbproj.schemaview
219 | *.jfm
220 | *.pfx
221 | *.publishsettings
222 | orleans.codegen.cs
223 |
224 | # Including strong name files can present a security risk
225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
226 | #*.snk
227 |
228 | # Since there are multiple workflows, uncomment next line to ignore bower_components
229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
230 | #bower_components/
231 |
232 | # RIA/Silverlight projects
233 | Generated_Code/
234 |
235 | # Backup & report files from converting an old project file
236 | # to a newer Visual Studio version. Backup files are not needed,
237 | # because we have git ;-)
238 | _UpgradeReport_Files/
239 | Backup*/
240 | UpgradeLog*.XML
241 | UpgradeLog*.htm
242 | ServiceFabricBackup/
243 | *.rptproj.bak
244 |
245 | # SQL Server files
246 | *.mdf
247 | *.ldf
248 | *.ndf
249 |
250 | # Business Intelligence projects
251 | *.rdl.data
252 | *.bim.layout
253 | *.bim_*.settings
254 | *.rptproj.rsuser
255 |
256 | # Microsoft Fakes
257 | FakesAssemblies/
258 |
259 | # GhostDoc plugin setting file
260 | *.GhostDoc.xml
261 |
262 | # Node.js Tools for Visual Studio
263 | .ntvs_analysis.dat
264 | node_modules/
265 |
266 | # Visual Studio 6 build log
267 | *.plg
268 |
269 | # Visual Studio 6 workspace options file
270 | *.opt
271 |
272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
273 | *.vbw
274 |
275 | # Visual Studio LightSwitch build output
276 | **/*.HTMLClient/GeneratedArtifacts
277 | **/*.DesktopClient/GeneratedArtifacts
278 | **/*.DesktopClient/ModelManifest.xml
279 | **/*.Server/GeneratedArtifacts
280 | **/*.Server/ModelManifest.xml
281 | _Pvt_Extensions
282 |
283 | # Paket dependency manager
284 | .paket/paket.exe
285 | paket-files/
286 |
287 | # FAKE - F# Make
288 | .fake/
289 |
290 | # JetBrains Rider
291 | .idea/
292 | *.sln.iml
293 |
294 | # CodeRush
295 | .cr/
296 |
297 | # Python Tools for Visual Studio (PTVS)
298 | __pycache__/
299 | *.pyc
300 |
301 | # Cake - Uncomment if you are using it
302 | # tools/**
303 | # !tools/packages.config
304 |
305 | # Tabs Studio
306 | *.tss
307 |
308 | # Telerik's JustMock configuration file
309 | *.jmconfig
310 |
311 | # BizTalk build output
312 | *.btp.cs
313 | *.btm.cs
314 | *.odx.cs
315 | *.xsd.cs
316 |
317 | # OpenCover UI analysis results
318 | OpenCover/
319 |
320 | # Azure Stream Analytics local run output
321 | ASALocalRun/
322 |
323 | # MSBuild Binary and Structured Log
324 | *.binlog
325 |
326 | # NVidia Nsight GPU debugger configuration file
327 | *.nvuser
328 |
329 | # MFractors (Xamarin productivity tool) working folder
330 | .mfractor/
331 |
--------------------------------------------------------------------------------
/WootingMidi/WootingMidi.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {77C574D9-A6D3-42A4-92DC-78461285304C}
8 | WinExe
9 | WootingMidi
10 | WootingMidi
11 | v4.7.2
12 | 512
13 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
14 | 4
15 | true
16 |
17 |
18 |
19 |
20 | AnyCPU
21 | true
22 | full
23 | false
24 | bin\Debug\
25 | DEBUG;TRACE
26 | prompt
27 | 4
28 |
29 |
30 | AnyCPU
31 | pdbonly
32 | true
33 | bin\Release\
34 | TRACE
35 | prompt
36 | 4
37 |
38 |
39 | true
40 | bin\x64\Debug\
41 | DEBUG;TRACE
42 | full
43 | x64
44 | prompt
45 | MinimumRecommendedRules.ruleset
46 | true
47 |
48 |
49 | bin\x64\Release\
50 | TRACE
51 | true
52 | pdbonly
53 | x64
54 | prompt
55 | MinimumRecommendedRules.ruleset
56 | true
57 |
58 |
59 |
60 | ..\packages\managed-midi.1.9.5\lib\net45\alsa-sharp.dll
61 |
62 |
63 | ..\packages\managed-midi.1.9.5\lib\net45\Commons.Music.Midi.dll
64 |
65 |
66 | ..\packages\FluentWPF.0.7.0\lib\net45\FluentWPF.dll
67 |
68 |
69 | ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll
70 |
71 |
72 |
73 |
74 |
75 | ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 | 4.0
87 |
88 |
89 |
90 |
91 |
92 | ..\packages\WootingAnalogSDK.NET.0.1.0\lib\net461\WootingAnalogSDK.NET.dll
93 |
94 |
95 |
96 |
97 | MSBuild:Compile
98 | Designer
99 |
100 |
101 | MSBuild:Compile
102 | Designer
103 |
104 |
105 | App.xaml
106 | Code
107 |
108 |
109 | MainWindow.xaml
110 | Code
111 |
112 |
113 | Designer
114 | MSBuild:Compile
115 |
116 |
117 |
118 |
119 |
120 | Octave.xaml
121 |
122 |
123 |
124 | Code
125 |
126 |
127 | True
128 | True
129 | Resources.resx
130 |
131 |
132 | True
133 | Settings.settings
134 | True
135 |
136 |
137 | ResXFileCodeGenerator
138 | Resources.Designer.cs
139 |
140 |
141 |
142 | SettingsSingleFileGenerator
143 | Settings.Designer.cs
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 | Always
152 |
153 |
154 |
155 |
--------------------------------------------------------------------------------
/WootingMidi/ObservableDict.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.ComponentModel;
4 | using System.Collections.Generic;
5 | using System.Collections.Specialized;
6 |
7 | namespace System.Collections.ObjectModel
8 | {
9 | public class ObservableDictionary : IDictionary, INotifyCollectionChanged, INotifyPropertyChanged
10 | {
11 | private const string CountString = "Count";
12 | private const string IndexerName = "Item[]";
13 | private const string KeysName = "Keys";
14 | private const string ValuesName = "Values";
15 |
16 | private IDictionary _Dictionary;
17 | protected IDictionary Dictionary
18 | {
19 | get { return _Dictionary; }
20 | }
21 |
22 | #region Constructors
23 | public ObservableDictionary()
24 | {
25 | _Dictionary = new Dictionary();
26 | }
27 | public ObservableDictionary(IDictionary dictionary)
28 | {
29 | _Dictionary = new Dictionary(dictionary);
30 | }
31 | public ObservableDictionary(IEqualityComparer comparer)
32 | {
33 | _Dictionary = new Dictionary(comparer);
34 | }
35 | public ObservableDictionary(int capacity)
36 | {
37 | _Dictionary = new Dictionary(capacity);
38 | }
39 | public ObservableDictionary(IDictionary dictionary, IEqualityComparer comparer)
40 | {
41 | _Dictionary = new Dictionary(dictionary, comparer);
42 | }
43 | public ObservableDictionary(int capacity, IEqualityComparer comparer)
44 | {
45 | _Dictionary = new Dictionary(capacity, comparer);
46 | }
47 | #endregion
48 |
49 | #region IDictionary Members
50 |
51 | public void Add(TKey key, TValue value)
52 | {
53 | Insert(key, value, true);
54 | }
55 |
56 | public bool ContainsKey(TKey key)
57 | {
58 | return Dictionary.ContainsKey(key);
59 | }
60 |
61 | public ICollection Keys
62 | {
63 | get { return Dictionary.Keys; }
64 | }
65 |
66 | public bool Remove(TKey key)
67 | {
68 | if (key == null) throw new ArgumentNullException("key");
69 |
70 | TValue value;
71 | Dictionary.TryGetValue(key, out value);
72 | var removed = Dictionary.Remove(key);
73 | if (removed)
74 | //OnCollectionChanged(NotifyCollectionChangedAction.Remove, new KeyValuePair(key, value));
75 | OnCollectionChanged();
76 |
77 | return removed;
78 | }
79 |
80 |
81 | public bool TryGetValue(TKey key, out TValue value)
82 | {
83 | return Dictionary.TryGetValue(key, out value);
84 | }
85 |
86 |
87 | public ICollection Values
88 | {
89 | get { return Dictionary.Values; }
90 | }
91 |
92 |
93 | public TValue this[TKey key]
94 | {
95 | get
96 | {
97 | return Dictionary[key];
98 | }
99 | set
100 | {
101 | Insert(key, value, false);
102 | }
103 | }
104 |
105 |
106 | #endregion
107 |
108 |
109 | #region ICollection> Members
110 |
111 |
112 | public void Add(KeyValuePair item)
113 | {
114 | Insert(item.Key, item.Value, true);
115 | }
116 |
117 |
118 | public void Clear()
119 | {
120 | if (Dictionary.Count > 0)
121 | {
122 | Dictionary.Clear();
123 | OnCollectionChanged();
124 | }
125 | }
126 |
127 |
128 | public bool Contains(KeyValuePair item)
129 | {
130 | return Dictionary.Contains(item);
131 | }
132 |
133 |
134 | public void CopyTo(KeyValuePair[] array, int arrayIndex)
135 | {
136 | Dictionary.CopyTo(array, arrayIndex);
137 | }
138 |
139 |
140 | public int Count
141 | {
142 | get { return Dictionary.Count; }
143 | }
144 |
145 |
146 | public bool IsReadOnly
147 | {
148 | get { return Dictionary.IsReadOnly; }
149 | }
150 |
151 |
152 | public bool Remove(KeyValuePair item)
153 | {
154 | return Remove(item.Key);
155 | }
156 |
157 |
158 | #endregion
159 |
160 |
161 | #region IEnumerable> Members
162 |
163 |
164 | public IEnumerator> GetEnumerator()
165 | {
166 | return Dictionary.GetEnumerator();
167 | }
168 |
169 |
170 | #endregion
171 |
172 |
173 | #region IEnumerable Members
174 |
175 |
176 | IEnumerator IEnumerable.GetEnumerator()
177 | {
178 | return ((IEnumerable)Dictionary).GetEnumerator();
179 | }
180 |
181 |
182 | #endregion
183 |
184 |
185 | #region INotifyCollectionChanged Members
186 |
187 |
188 | public event NotifyCollectionChangedEventHandler CollectionChanged;
189 |
190 |
191 | #endregion
192 |
193 |
194 | #region INotifyPropertyChanged Members
195 |
196 |
197 | public event PropertyChangedEventHandler PropertyChanged;
198 |
199 |
200 | #endregion
201 |
202 |
203 | public void AddRange(IDictionary items)
204 | {
205 | if (items == null) throw new ArgumentNullException("items");
206 |
207 |
208 | if (items.Count > 0)
209 | {
210 | if (Dictionary.Count > 0)
211 | {
212 | if (items.Keys.Any((k) => Dictionary.ContainsKey(k)))
213 | throw new ArgumentException("An item with the same key has already been added.");
214 | else
215 | foreach (var item in items) Dictionary.Add(item);
216 | }
217 | else
218 | _Dictionary = new Dictionary(items);
219 |
220 |
221 | OnCollectionChanged(NotifyCollectionChangedAction.Add, items.ToArray());
222 | }
223 | }
224 |
225 |
226 | private void Insert(TKey key, TValue value, bool add)
227 | {
228 | if (key == null) throw new ArgumentNullException("key");
229 |
230 |
231 | TValue item;
232 | if (Dictionary.TryGetValue(key, out item))
233 | {
234 | if (add) throw new ArgumentException("An item with the same key has already been added.");
235 | if (Equals(item, value)) return;
236 | Dictionary[key] = value;
237 |
238 |
239 | OnCollectionChanged(NotifyCollectionChangedAction.Replace, new KeyValuePair(key, value), new KeyValuePair(key, item));
240 | }
241 | else
242 | {
243 | Dictionary[key] = value;
244 |
245 | OnCollectionChanged(NotifyCollectionChangedAction.Add, new KeyValuePair(key, value));
246 | }
247 | }
248 |
249 |
250 | private void OnPropertyChanged()
251 | {
252 | OnPropertyChanged(CountString);
253 | OnPropertyChanged(IndexerName);
254 | OnPropertyChanged(KeysName);
255 | OnPropertyChanged(ValuesName);
256 | }
257 |
258 |
259 | protected virtual void OnPropertyChanged(string propertyName)
260 | {
261 | if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
262 | }
263 |
264 |
265 | public void OnCollectionChanged()
266 | {
267 | OnPropertyChanged();
268 | if (CollectionChanged != null) CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
269 | }
270 |
271 |
272 | private void OnCollectionChanged(NotifyCollectionChangedAction action, KeyValuePair changedItem)
273 | {
274 | OnPropertyChanged();
275 | if (CollectionChanged != null) CollectionChanged(this, new NotifyCollectionChangedEventArgs(action, changedItem));
276 | }
277 |
278 |
279 | private void OnCollectionChanged(NotifyCollectionChangedAction action, KeyValuePair newItem, KeyValuePair oldItem)
280 | {
281 | OnPropertyChanged();
282 | if (CollectionChanged != null) CollectionChanged(this, new NotifyCollectionChangedEventArgs(action, newItem, oldItem));
283 | }
284 |
285 |
286 | private void OnCollectionChanged(NotifyCollectionChangedAction action, IList newItems)
287 | {
288 | OnPropertyChanged();
289 | if (CollectionChanged != null) CollectionChanged(this, new NotifyCollectionChangedEventArgs(action, newItems));
290 | }
291 | }
292 | }
--------------------------------------------------------------------------------
/WootingMidi/Octave.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
15 |
19 |
34 |
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 |
--------------------------------------------------------------------------------
/WootingMidi/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading;
7 | using System.Threading.Tasks;
8 | using System.Windows;
9 | using System.Windows.Controls;
10 | using System.Windows.Data;
11 | using System.Windows.Documents;
12 | using System.Windows.Forms;
13 | using System.Windows.Input;
14 | using System.Windows.Media;
15 | using System.Windows.Media.Imaging;
16 | using System.Windows.Navigation;
17 | using System.Windows.Shapes;
18 | using System.Xaml;
19 | using Commons.Music.Midi;
20 | using WootingAnalogSDKNET;
21 |
22 | namespace WootingMidi
23 | {
24 | public class CcKeyPress
25 | {
26 | private double _press;
27 | public string KeyCode { get; set; }
28 |
29 | public double Press
30 | {
31 | get => _press;
32 | set
33 | {
34 | if(value > 0) Active = true;
35 | _press = value;
36 | }
37 | }
38 |
39 | public bool Active { get; set; }
40 | }
41 |
42 | public class Settings
43 | {
44 | public static Settings Last;
45 |
46 | public int Octave1 { get; set; } = 0;
47 | public int Octave2 { get; set; } = 1;
48 | public string MidiDevice { get; set; } = "";
49 | public int Channel { get; set; } = 0;
50 | public bool SendNote { get; set; } = true;
51 | public bool SendAt { get; set; } = true;
52 | public bool SendCc { get; set; } = true;
53 |
54 | public Settings()
55 | {
56 | Last = this;
57 | }
58 |
59 | public static string Path()
60 | {
61 | return System.IO.Path.Combine(Environment.CurrentDirectory, "settings.xaml");
62 | }
63 |
64 | public void Save()
65 | {
66 | XamlServices.Save(Path(), this);
67 | }
68 |
69 | public static Settings Load()
70 | {
71 | try
72 | {
73 | return Last = XamlServices.Load(Path()) as Settings ?? new Settings();
74 | }
75 | catch (Exception e)
76 | {
77 | return new Settings();
78 | }
79 | }
80 | }
81 |
82 | ///
83 | /// Interaction logic for MainWindow.xaml
84 | ///
85 | public partial class MainWindow
86 | {
87 | public const byte NOKEY = 255;
88 | public const int WOOTING_ONE_VID = 0x03EB;
89 | public const int WOOTING_ONE_PID = 0xFF01;
90 | public const int WOOTING_ONE_ANALOG_USAGE_PAGE = 0x1338;
91 |
92 | private Settings _settings = new Settings();
93 | private bool _loaded = false;
94 |
95 | public static readonly DependencyProperty ChannelNumberProperty =
96 | DependencyProperty.Register("ChannelNumber", typeof(int), typeof(MainWindow), new PropertyMetadata(0));
97 |
98 | public int ChannelNumber
99 | {
100 | get => (int) GetValue(ChannelNumberProperty);
101 | set => SetValue(ChannelNumberProperty, value);
102 | }
103 |
104 | public static readonly DependencyProperty LowOctaveNumProperty =
105 | DependencyProperty.Register("LowOctaveNum", typeof(int), typeof(MainWindow), new PropertyMetadata(0));
106 |
107 | public int LowOctaveNum
108 | {
109 | get => (int)GetValue(LowOctaveNumProperty);
110 | set => SetValue(LowOctaveNumProperty, value);
111 | }
112 |
113 | public static readonly DependencyProperty HiOctaveNumProperty =
114 | DependencyProperty.Register("HiOctaveNum", typeof(int), typeof(MainWindow), new PropertyMetadata(1));
115 |
116 | public int HiOctaveNum
117 | {
118 | get => (int)GetValue(HiOctaveNumProperty);
119 | set => SetValue(HiOctaveNumProperty, value);
120 | }
121 |
122 | public static readonly DependencyProperty SendNoteProperty =
123 | DependencyProperty.Register("SendNote", typeof(bool), typeof(MainWindow), new PropertyMetadata(true));
124 |
125 | public bool SendNote
126 | {
127 | get => (bool)GetValue(SendNoteProperty);
128 | set => SetValue(SendNoteProperty, value);
129 | }
130 |
131 | public static readonly DependencyProperty SendAtProperty =
132 | DependencyProperty.Register("SendAt", typeof(bool), typeof(MainWindow), new PropertyMetadata(true));
133 |
134 | public bool SendAt
135 | {
136 | get => (bool)GetValue(SendAtProperty);
137 | set => SetValue(SendAtProperty, value);
138 | }
139 |
140 | public static readonly DependencyProperty SendCcProperty =
141 | DependencyProperty.Register("SendCc", typeof(bool), typeof(MainWindow), new PropertyMetadata(true));
142 |
143 | public bool SendCc
144 | {
145 | get => (bool)GetValue(SendCcProperty);
146 | set => SetValue(SendCcProperty, value);
147 | }
148 |
149 | public ObservableDictionary CcPresses { get; } = new ObservableDictionary();
150 | public ObservableCollection CcPressesList { get; } = new ObservableCollection();
151 |
152 | public MainWindow()
153 | {
154 | InitializeComponent();
155 | DataContext = this;
156 | LowOctave.FillKeys(_lowOctKeys);
157 | HighOctave.FillKeys(_highOctKeys);
158 |
159 | _settings = Settings.Load();
160 |
161 | ChannelNumber = _settings.Channel;
162 | LowOctaveNum = _settings.Octave1;
163 | HiOctaveNum = _settings.Octave2;
164 | SendNote = _settings.SendNote;
165 | SendAt = _settings.SendAt;
166 | SendCc = _settings.SendCc;
167 |
168 | UpdateMidi();
169 | WootingAnalogResult res;
170 | if ((res = WootingAnalogSDK.Initialise()) != WootingAnalogResult.Ok && res != WootingAnalogResult.NoDevices)
171 | {
172 | System.Windows.MessageBox.Show("Could not initialize sdk, Error: " + res.ToString());
173 | Environment.Exit(0);
174 | }
175 | WootingAnalogSDK.SetKeycodeMode(KeycodeType.VirtualKey);
176 | _loaded = true;
177 |
178 | Task.Factory.StartNew(() =>
179 | {
180 | while (true)
181 | {
182 | try
183 | {
184 | (List<(short, float)> buffer, WootingAnalogResult result) = WootingAnalogSDK.ReadFullBuffer(50);
185 |
186 | //if (buffer.Count == 0) continue;
187 | Dispatcher.BeginInvoke(new Action(() =>
188 | {
189 |
190 | foreach (var cc in CcPresses.Values)
191 | {
192 | cc.Press = 0.0;
193 | }
194 | for (int i = 0; i < 24; i++)
195 | {
196 | _keyPress[i] = 0;
197 | }
198 |
199 | if (result == WootingAnalogResult.Ok)
200 | {
201 | HidStatus.Fill = new SolidColorBrush(Color.FromRgb(0, 255, 0));
202 |
203 | foreach ((short key, float value) in buffer)
204 | {
205 | Keys vKey = (Keys)key;
206 | if (CcPresses.ContainsKey(key))
207 | {
208 | CcPresses[key].KeyCode = vKey.ToString();
209 | CcPresses[key].Press = value * 100.0;
210 | }
211 | else
212 | {
213 | CcPresses.Add(key, new CcKeyPress()
214 | {
215 | KeyCode = vKey.ToString(),
216 | Press = value * 100.0
217 | });
218 | }
219 |
220 | if (_keyIndex.Contains(vKey))
221 | {
222 | var ki = _keyIndex.IndexOf(vKey);
223 | _keyPress[ki] = value;
224 | }
225 | }
226 |
227 | ProcessNotes();
228 |
229 | CcPresses.OnCollectionChanged();
230 | CcPressesList.Clear();
231 | foreach (var press in CcPresses.Values)
232 | {
233 | if (press.Press > 0.0)
234 | CcPressesList.Add(press);
235 | }
236 |
237 | var looffs = 12 + LowOctaveNum * 12;
238 | var hioffs = 12 + HiOctaveNum * 12;
239 |
240 | LowOctave.UpdateBars(_notes, looffs);
241 | HighOctave.UpdateBars(_notes, hioffs);
242 | }
243 | else
244 | {
245 | HidStatus.Fill = new SolidColorBrush(Color.FromRgb(255, 0, 0));
246 | }
247 | }));
248 | if (result != WootingAnalogResult.Ok)
249 | Thread.Sleep(500);
250 | }
251 | catch (Exception e)
252 | {
253 | Dispatcher.BeginInvoke(new Action(() =>
254 | {
255 | HidStatus.Fill = new SolidColorBrush(Color.FromRgb(255, 0, 0));
256 | }));
257 | throw e;
258 | }
259 | Thread.Sleep(2);
260 | }
261 | });
262 | }
263 |
264 | private IMidiPortDetails[] _midiOutDetails;//{ 65, 50, 66, 51, 67, 68, 53, 69, 54, 70, 55, 71, 34, 19, 35, 20, 36, 37, 22, 38, 23, 39, 24, 40 };
265 | private readonly List _keyIndex = new List { Keys.Z, Keys.S, Keys.X, Keys.D, Keys.C, Keys.V, Keys.G, Keys.B, Keys.H, Keys.N, Keys.J, Keys.M, Keys.W, Keys.D3, Keys.E, Keys.D4, Keys.R, Keys.T, Keys.D6, Keys.Y, Keys.D7, Keys.U, Keys.D8, Keys.I };
266 | private readonly double[] _keyPress = new double[24];
267 | private string _lowOctKeys = "ZSXDCVGBHNJM";
268 | private string _highOctKeys = "W3E4RT6Y7U8I";
269 |
270 | private readonly NoteKey[] _notes = new NoteKey[128];
271 | private readonly byte[] _rawMidiMessageBuf = new byte[3];
272 |
273 | private void ProcessNotes()
274 | {
275 | if(_midiDevice == null) return;
276 |
277 | var looffs = 12 + LowOctaveNum * 12;
278 | var hioffs = 12 + HiOctaveNum * 12;
279 | for (int i = 0; i < 128; i++)
280 | {
281 | if(_notes[i] == null) _notes[i] = new NoteKey() { NoteId = (uint)i };
282 | RawMidiMessage res;
283 | if (i >= looffs && i < looffs + 12)
284 | {
285 | var ii = i - looffs;
286 | res = _notes[i].Submit(_keyPress[ii]);
287 | }
288 | else if (i >= hioffs && i < hioffs + 12)
289 | {
290 | var ii = i - hioffs;
291 | res = _notes[i].Submit(_keyPress[ii + 12]);
292 | }
293 | else
294 | {
295 | res = _notes[i].Submit(0.0);
296 | }
297 |
298 | if (res.Valid)
299 | {
300 | res.Bytes(_rawMidiMessageBuf, 0);
301 | _midiDevice.Send(_rawMidiMessageBuf, 0, 3, 0 /*(long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds*/);
302 | }
303 | }
304 |
305 | foreach (var ccc in CcPresses)
306 | {
307 | var cc = MidiCc.Generate(ChannelNumber, ccc.Key, ccc.Value.Press / 100.0);
308 | if (!cc.Valid || !ccc.Value.Active) continue;
309 | cc.Bytes(_rawMidiMessageBuf, 0);
310 | _midiDevice.Send(_rawMidiMessageBuf, 0, 3, 0 /*(long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds*/);
311 | ccc.Value.Active = false;
312 | }
313 |
314 | if (SendAt)
315 | {
316 | var cat = MidiChannelAt.Generate(ChannelNumber, _notes.Max(cp => cp.Pressure));
317 | cat.Bytes(_rawMidiMessageBuf, 0);
318 | _midiDevice.Send(_rawMidiMessageBuf, 0, 2, 0 /*(long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds*/);
319 | }
320 | }
321 |
322 | private void UpdateMidi()
323 | {
324 | _midiOutDetails = MidiAccessManager.Default.Outputs.ToArray();
325 | MidiSelect.Items.Clear();
326 | foreach (var midiOutDetail in _midiOutDetails)
327 | {
328 | MidiSelect.Items.Add(midiOutDetail.Name);
329 | }
330 | MidiSelect.SelectedItem = _settings.MidiDevice;
331 | }
332 |
333 | /*private void UpdateHid()
334 | {
335 | if (_hidStream != null)
336 | {
337 | _hidStream.Close();
338 | _hidStream.Dispose();
339 | }
340 |
341 | var devices = DeviceList.Local.GetHidDevices(WOOTING_ONE_VID, WOOTING_ONE_PID);
342 | var success = false;
343 | foreach (var candidate in devices)
344 | {
345 | try
346 | {
347 | if (candidate.GetMaxInputReportLength() == 33)
348 | {
349 | success = true;
350 | _hidDevice = candidate;
351 | break;
352 | }
353 | }
354 | catch (Exception e)
355 | { }
356 | }
357 | if (success)
358 | {
359 | _hidStream = _hidDevice.Open();
360 | HidStatus.Fill = new SolidColorBrush(Color.FromRgb(255, 255, 0));
361 | }
362 | else
363 | {
364 | HidStatus.Fill = new SolidColorBrush(Color.FromRgb(255, 0, 0));
365 | _hidDevice = null;
366 | }
367 | }*/
368 |
369 | private IMidiOutput _midiDevice;
370 |
371 | private void OnMidiSelectionChanged(object sender, SelectionChangedEventArgs e)
372 | {
373 | if (_midiDevice != null)
374 | {
375 | var closetask = _midiDevice.CloseAsync();
376 | closetask.Wait();
377 | }
378 | var deviceinfo = _midiOutDetails[MidiSelect.SelectedIndex];
379 | var opentask = MidiAccessManager.Default.OpenOutputAsync(deviceinfo.Id);
380 | opentask.Wait();
381 | _midiDevice = opentask.Result;
382 | _settings.MidiDevice = deviceinfo.Name;
383 | _settings.Save();
384 | }
385 |
386 | protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
387 | {
388 | if (_loaded &&
389 | (e.Property == LowOctaveNumProperty ||
390 | e.Property == HiOctaveNumProperty ||
391 | e.Property == ChannelNumberProperty ||
392 | e.Property == SendNoteProperty ||
393 | e.Property == SendAtProperty ||
394 | e.Property == SendCcProperty)
395 | )
396 | {
397 | _settings.Channel = ChannelNumber;
398 | _settings.Octave1 = LowOctaveNum;
399 | _settings.Octave2 = HiOctaveNum;
400 | _settings.SendNote = SendNote;
401 | _settings.SendAt = SendAt;
402 | _settings.SendCc = SendCc;
403 |
404 | foreach (var note in _notes)
405 | {
406 | note.Channel = (uint)ChannelNumber;
407 | }
408 | _settings.Save();
409 | }
410 | base.OnPropertyChanged(e);
411 | }
412 |
413 | private void OnListKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
414 | {
415 | e.Handled = true;
416 | }
417 |
418 | private void LowOctDecr_Click(object sender, RoutedEventArgs e)
419 | {
420 | LowOctaveNum = Math.Max(0, LowOctaveNum - 1);
421 | }
422 |
423 | private void HighOctDecr_Click(object sender, RoutedEventArgs e)
424 | {
425 | HiOctaveNum = Math.Max(0, HiOctaveNum - 1);
426 | }
427 |
428 | private void LowOctIncr_Click(object sender, RoutedEventArgs e)
429 | {
430 | LowOctaveNum = Math.Min(9, LowOctaveNum + 1);
431 | }
432 |
433 | private void HighOctIncr_Click(object sender, RoutedEventArgs e)
434 | {
435 | HiOctaveNum = Math.Min(9, HiOctaveNum + 1);
436 | }
437 | }
438 | }
439 |
--------------------------------------------------------------------------------