Initial commit
This commit is contained in:
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
401
.gitignore
vendored
Normal file
401
.gitignore
vendored
Normal file
@@ -0,0 +1,401 @@
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.rsuser
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Mono auto generated files
|
||||
mono_crash.*
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
[Ww][Ii][Nn]32/
|
||||
[Aa][Rr][Mm]/
|
||||
[Aa][Rr][Mm]64/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# Visual Studio 2017 auto generated files
|
||||
Generated\ Files/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUnit
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
nunit-*.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# Benchmark Results
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
# ASP.NET Scaffolding
|
||||
ScaffoldingReadMe.txt
|
||||
|
||||
# StyleCop
|
||||
StyleCopReport.xml
|
||||
|
||||
# Files built by Visual Studio
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_h.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.iobj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.ipdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
# but not Directory.Build.rsp, as it configures directory-level build defaults
|
||||
!Directory.Build.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*_wpftmp.csproj
|
||||
*.log
|
||||
*.tlog
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# Visual Studio Trace Files
|
||||
*.e2e
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# Coverlet is a free, cross platform Code Coverage Tool
|
||||
coverage*.json
|
||||
coverage*.xml
|
||||
coverage*.info
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# NuGet Symbol Packages
|
||||
*.snupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/[Pp]ackages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/[Pp]ackages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
*.appx
|
||||
*.appxbundle
|
||||
*.appxupload
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!?*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Including strong name files can present a security risk
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
#*.snk
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
ServiceFabricBackup/
|
||||
*.rptproj.bak
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
*.rptproj.rsuser
|
||||
*- [Bb]ackup.rdl
|
||||
*- [Bb]ackup ([0-9]).rdl
|
||||
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
|
||||
*.vbp
|
||||
|
||||
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
|
||||
*.dsw
|
||||
*.dsp
|
||||
|
||||
# Visual Studio 6 technical files
|
||||
*.ncb
|
||||
*.aps
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# CodeRush personal settings
|
||||
.cr/personal
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
# OpenCover UI analysis results
|
||||
OpenCover/
|
||||
|
||||
# Azure Stream Analytics local run output
|
||||
ASALocalRun/
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
*.binlog
|
||||
|
||||
# NVidia Nsight GPU debugger configuration file
|
||||
*.nvuser
|
||||
|
||||
# MFractors (Xamarin productivity tool) working folder
|
||||
.mfractor/
|
||||
|
||||
# Local History for Visual Studio
|
||||
.localhistory/
|
||||
|
||||
# Visual Studio History (VSHistory) files
|
||||
.vshistory/
|
||||
|
||||
# BeatPulse healthcheck temp database
|
||||
healthchecksdb
|
||||
|
||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||
MigrationBackup/
|
||||
|
||||
# Ionide (cross platform F# VS Code tools) working folder
|
||||
.ionide/
|
||||
|
||||
# Fody - auto-generated XML schema
|
||||
FodyWeavers.xsd
|
||||
|
||||
# VS Code files for those working on multiple tools
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
*.code-workspace
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
# Windows Installer files from build outputs
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# JetBrains Rider
|
||||
*.sln.iml
|
||||
6
App.config
Normal file
6
App.config
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||
</startup>
|
||||
</configuration>
|
||||
60
Config.cs
Normal file
60
Config.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace VirtualDJ_MidiDeviceBridge
|
||||
{
|
||||
internal class MidiConfig
|
||||
{
|
||||
[JsonInclude]
|
||||
public int ShiftNoteId = 0;
|
||||
|
||||
[JsonInclude]
|
||||
public bool ToggleShift = true;
|
||||
|
||||
[JsonInclude]
|
||||
public Dictionary<string, string> MidiInCommands = new Dictionary<string, string>();
|
||||
|
||||
[JsonInclude]
|
||||
public List<string> MidiOutCommandsSysEx = new List<string>();
|
||||
|
||||
[JsonInclude]
|
||||
public Dictionary<string, string> MidiInShiftCommands = new Dictionary<string, string>();
|
||||
|
||||
[JsonInclude]
|
||||
public List<string> MidiOutShiftCommandsSysEx = new List<string>();
|
||||
|
||||
public static MidiConfig GetDefaultConfig()
|
||||
{
|
||||
MidiConfig conf = new MidiConfig();
|
||||
conf.MidiInCommands.Add("NOTEON_0", "play");
|
||||
conf.MidiInCommands.Add("NOTEOFF_0", "pause");
|
||||
conf.MidiInCommands.Add("CONTROL_0", "set_gain %val%");
|
||||
|
||||
conf.MidiOutCommandsSysEx.Add("deck 1 play ? get_text '0x90,0x20,0x01' : get_text '0x90,0x20,0x00'");
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
||||
public Dictionary<string, string> GetActiveMidiInCommands(bool shift)
|
||||
{
|
||||
if (shift)
|
||||
return MidiInShiftCommands;
|
||||
|
||||
return MidiInCommands;
|
||||
}
|
||||
|
||||
public List<string> GetActiveMidiOutShiftCommandsSysEx(bool shift)
|
||||
{
|
||||
if (shift)
|
||||
return MidiOutShiftCommandsSysEx;
|
||||
|
||||
return MidiOutCommandsSysEx;
|
||||
}
|
||||
}
|
||||
}
|
||||
171
Globals.cs
Normal file
171
Globals.cs
Normal file
@@ -0,0 +1,171 @@
|
||||
using Midi;
|
||||
using Midi.Devices;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using System.Text.Unicode;
|
||||
using System.Threading;
|
||||
|
||||
namespace VirtualDJ_MidiDeviceBridge
|
||||
{
|
||||
internal static class Globals
|
||||
{
|
||||
public static string ConfigPath = "";
|
||||
public static MidiConfig Config = MidiConfig.GetDefaultConfig();
|
||||
|
||||
public static bool ShiftKeyHeld = false;
|
||||
public static IInputDevice MidiInDevice = null;
|
||||
public static IOutputDevice MidiOutDevice = null;
|
||||
|
||||
public static object UdpLock = new object();
|
||||
public static UdpClient UdpClient = new UdpClient();
|
||||
|
||||
public static FileSystemWatcher configWatcher = null;
|
||||
|
||||
static Globals()
|
||||
{
|
||||
UdpClient.Client.SendTimeout = 100;
|
||||
UdpClient.Client.ReceiveTimeout = 100;
|
||||
}
|
||||
|
||||
public static void UserReadConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(ConfigPath))
|
||||
{
|
||||
string json = File.ReadAllText(ConfigPath);
|
||||
Config = JsonSerializer.Deserialize<MidiConfig>(json);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Path doesn't point to a file. Press enter to create a default config file at '{ConfigPath}'");
|
||||
Console.ReadKey();
|
||||
File.WriteAllBytes(ConfigPath, JsonSerializer.SerializeToUtf8Bytes(Config, new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
|
||||
}));
|
||||
Console.WriteLine("Wrote default config!");
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Failed to read config file!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void StartConfigWatcher()
|
||||
{
|
||||
configWatcher = new FileSystemWatcher
|
||||
{
|
||||
Path = Path.GetDirectoryName(Path.GetFullPath(ConfigPath)),
|
||||
Filter = Path.GetFileName(Path.GetFullPath(ConfigPath)),
|
||||
NotifyFilter = NotifyFilters.LastWrite
|
||||
};
|
||||
|
||||
configWatcher.Changed += ConfigWatcher_Changed;
|
||||
|
||||
configWatcher.EnableRaisingEvents = true;
|
||||
}
|
||||
|
||||
private static void ConfigWatcher_Changed(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
if (e.ChangeType != WatcherChangeTypes.Changed)
|
||||
return;
|
||||
|
||||
Thread.Sleep(100);
|
||||
|
||||
UserReadConfig();
|
||||
Console.WriteLine("Config reloaded!");
|
||||
}
|
||||
|
||||
public static string SendCommand(string cmd)
|
||||
{
|
||||
lock (UdpLock)
|
||||
{
|
||||
IPEndPoint remote = new IPEndPoint(IPAddress.Loopback, 54000);
|
||||
//Console.WriteLine($"Sending message: {message}");
|
||||
|
||||
byte[] data = Encoding.ASCII.GetBytes(cmd);
|
||||
|
||||
UdpClient.Send(data, data.Length, remote);
|
||||
data = UdpClient.Receive(ref remote);
|
||||
|
||||
string result = Encoding.ASCII.GetString(data);
|
||||
//Console.WriteLine($"Received message: {result}");
|
||||
|
||||
if (result.Contains("Error"))
|
||||
{
|
||||
Console.WriteLine($"Command resulted in error!");
|
||||
Console.WriteLine($"Command: {cmd}");
|
||||
Console.WriteLine($"Error: {result}");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static void UserSelectDevice()
|
||||
{
|
||||
DeviceManager.UpdateInputDevices();
|
||||
DeviceManager.UpdateOutputDevices();
|
||||
|
||||
Console.WriteLine("Devices: ");
|
||||
int index = 0;
|
||||
foreach(var device in DeviceManager.InputDevices)
|
||||
{
|
||||
Console.WriteLine($"\t{device.Name} [{index}]");
|
||||
index++;
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
|
||||
while (true)
|
||||
{
|
||||
Console.Write("Please select a device: ");
|
||||
|
||||
int selectedIndex;
|
||||
if (!Int32.TryParse(Console.ReadLine(), out selectedIndex))
|
||||
{
|
||||
Console.WriteLine("Not a number");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (selectedIndex < 0 || selectedIndex > DeviceManager.InputDevices.Count - 1)
|
||||
{
|
||||
Console.WriteLine($"Invalid index {selectedIndex}");
|
||||
continue;
|
||||
}
|
||||
|
||||
MidiInDevice = DeviceManager.InputDevices[selectedIndex];
|
||||
MidiOutDevice = DeviceManager.OutputDevices.Where(dev => dev.Name == MidiInDevice.Name).FirstOrDefault();
|
||||
|
||||
Console.Write($"Trying to claim device {MidiInDevice.Name}... ");
|
||||
|
||||
try
|
||||
{
|
||||
MidiInDevice.Open();
|
||||
MidiOutDevice.Open();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Failed! Is the device busy?");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
MidiOutDevice.SendSysEx(new byte[] { 0x90, 0x20, 0x00 });
|
||||
|
||||
Console.WriteLine("Success!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
128
MidiManager.cs
Normal file
128
MidiManager.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using Midi.Devices;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
|
||||
|
||||
namespace VirtualDJ_MidiDeviceBridge
|
||||
{
|
||||
internal static class MidiManager
|
||||
{
|
||||
public static void SetupDevice()
|
||||
{
|
||||
Globals.MidiInDevice.NoteOn += MidiDevice_NoteOn;
|
||||
Globals.MidiInDevice.NoteOff += MidiDevice_NoteOff;
|
||||
Globals.MidiInDevice.ControlChange += MidiDevice_ControlChange;
|
||||
}
|
||||
|
||||
private static void MidiDevice_NoteOn(Midi.Messages.NoteOnMessage msg)
|
||||
{
|
||||
string key = $"NOTEON_{(int)(msg.Pitch)}";
|
||||
|
||||
if ((int)msg.Pitch == Globals.Config.ShiftNoteId)
|
||||
{
|
||||
if (Globals.Config.ToggleShift && Globals.ShiftKeyHeld)
|
||||
Globals.ShiftKeyHeld = false;
|
||||
else
|
||||
Globals.ShiftKeyHeld = true;
|
||||
}
|
||||
|
||||
string cmd = null;
|
||||
Globals.Config.GetActiveMidiInCommands(Globals.ShiftKeyHeld).TryGetValue(key, out cmd);
|
||||
|
||||
if (cmd == null)
|
||||
{
|
||||
Console.WriteLine($"Unbound midi event: {key} (shift: {Globals.ShiftKeyHeld})");
|
||||
return;
|
||||
}
|
||||
|
||||
Globals.SendCommand($"0:(command){cmd}");
|
||||
}
|
||||
|
||||
private static void MidiDevice_NoteOff(Midi.Messages.NoteOffMessage msg)
|
||||
{
|
||||
string key = $"NOTEOFF_{(int)(msg.Pitch)}";
|
||||
|
||||
if ((int)msg.Pitch == Globals.Config.ShiftNoteId)
|
||||
{
|
||||
if (!Globals.Config.ToggleShift)
|
||||
Globals.ShiftKeyHeld = false;
|
||||
|
||||
Globals.MidiOutDevice.SilenceAllNotes();
|
||||
}
|
||||
|
||||
string cmd = null;
|
||||
Globals.Config.GetActiveMidiInCommands(Globals.ShiftKeyHeld).TryGetValue(key, out cmd);
|
||||
|
||||
if (cmd == null)
|
||||
{
|
||||
Console.WriteLine($"Unbound midi event: {key} (shift: {Globals.ShiftKeyHeld})");
|
||||
return;
|
||||
}
|
||||
|
||||
Globals.SendCommand($"0:(command){cmd}");
|
||||
}
|
||||
|
||||
private static void MidiDevice_ControlChange(Midi.Messages.ControlChangeMessage msg)
|
||||
{
|
||||
string key = $"CONTROL_{(int)(msg.Control)}";
|
||||
string cmd = null;
|
||||
|
||||
float normalizedValue = msg.Value / 128.0f * 100f;
|
||||
|
||||
Globals.Config.GetActiveMidiInCommands(Globals.ShiftKeyHeld).TryGetValue(key, out cmd);
|
||||
|
||||
if (cmd == null)
|
||||
{
|
||||
Console.WriteLine($"Unbound midi event: {key} (value: {normalizedValue.ToString(CultureInfo.InvariantCulture)}) (shift: {Globals.ShiftKeyHeld})");
|
||||
return;
|
||||
}
|
||||
|
||||
cmd = cmd.Replace("%val%", normalizedValue.ToString(CultureInfo.InvariantCulture) + "%");
|
||||
Globals.SendCommand($"0:(command){cmd}");
|
||||
}
|
||||
|
||||
public static void Work()
|
||||
{
|
||||
Globals.MidiInDevice.StartReceiving(null);
|
||||
|
||||
while (true)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
|
||||
foreach(var cmd in Globals.Config.GetActiveMidiOutShiftCommandsSysEx(Globals.ShiftKeyHeld))
|
||||
{
|
||||
try
|
||||
{
|
||||
string result = Globals.SendCommand($"1:(string){cmd}");
|
||||
result = result.Substring(2); //skip 0:
|
||||
//result = result.Substring(1, result.Length - 3); //skip [ ... ]
|
||||
|
||||
string[] values = result.Split(',');
|
||||
byte[] sysExBytes = new byte[values.Length];
|
||||
|
||||
for (int i = 0; i < values.Length; i++)
|
||||
{
|
||||
if (values[i].StartsWith("0x"))
|
||||
sysExBytes[i] = byte.Parse(values[i].Substring(2), NumberStyles.HexNumber);
|
||||
else
|
||||
sysExBytes[i] = byte.Parse(values[i], NumberStyles.Integer);
|
||||
}
|
||||
|
||||
Globals.MidiOutDevice.SendSysEx(sysExBytes);
|
||||
}
|
||||
catch (DeviceException ex)
|
||||
{
|
||||
Console.WriteLine("Device lost, you're on your own now!");
|
||||
return;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Failed to read sysex midi out command!\nCommand: {cmd}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Program.cs
Normal file
34
Program.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VirtualDJ_MidiDeviceBridge
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
if (args.Length < 1 || args[0] == "")
|
||||
{
|
||||
Console.WriteLine("Please provide a config path!");
|
||||
return;
|
||||
}
|
||||
|
||||
Globals.ConfigPath = args[0];
|
||||
Console.WriteLine($"Using config from '{Globals.ConfigPath}'");
|
||||
|
||||
Globals.UserReadConfig();
|
||||
|
||||
Globals.UserSelectDevice();
|
||||
|
||||
MidiManager.SetupDevice();
|
||||
Globals.StartConfigWatcher();
|
||||
MidiManager.Work();
|
||||
}
|
||||
}
|
||||
}
|
||||
33
Properties/AssemblyInfo.cs
Normal file
33
Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die einer Assembly zugeordnet sind.
|
||||
[assembly: AssemblyTitle("VirtualDJ_MidiDeviceBridge")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("VirtualDJ_MidiDeviceBridge")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2026")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
|
||||
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
|
||||
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
||||
[assembly: Guid("bcc0e701-cff0-485b-835a-bdad9b55cd2a")]
|
||||
|
||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
//
|
||||
// Hauptversion
|
||||
// Nebenversion
|
||||
// Buildnummer
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
139
VirtualDJ_MidiDeviceBridge.csproj
Normal file
139
VirtualDJ_MidiDeviceBridge.csproj
Normal file
@@ -0,0 +1,139 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{BCC0E701-CFF0-485B-835A-BDAD9B55CD2A}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>VirtualDJ_MidiDeviceBridge</RootNamespace>
|
||||
<AssemblyName>VirtualDJ_MidiDeviceBridge</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>false</MapFileExtensions>
|
||||
<OpenBrowserOnPublish>false</OpenBrowserOnPublish>
|
||||
<ApplicationRevision>3</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<PublishWizardCompleted>true</PublishWizardCompleted>
|
||||
<BootstrapperEnabled>false</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ManifestCertificateThumbprint>8BC1CE173F5D3CA2C891004E5737D3F9C611B34B</ManifestCertificateThumbprint>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ManifestKeyFile>VirtualDJ_MidiDeviceBridge_TemporaryKey.pfx</ManifestKeyFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<GenerateManifests>true</GenerateManifests>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignManifests>true</SignManifests>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=10.0.0.12, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Microsoft.Bcl.AsyncInterfaces.10.0.12\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Midi, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>packages\midi-dot-net2.2.0.1\lib\net461\Midi.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Buffers, Version=4.0.5.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>packages\System.Buffers.4.6.1\lib\net462\System.Buffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.IO.Pipelines, Version=10.0.0.12, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>packages\System.IO.Pipelines.10.0.12\lib\net462\System.IO.Pipelines.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Memory, Version=4.0.5.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>packages\System.Memory.4.6.3\lib\net462\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>packages\System.Numerics.Vectors.4.6.1\lib\net462\System.Numerics.Vectors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>packages\System.Runtime.CompilerServices.Unsafe.6.1.2\lib\net462\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Text.Encodings.Web, Version=10.0.0.12, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>packages\System.Text.Encodings.Web.10.0.12\lib\net462\System.Text.Encodings.Web.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Text.Json, Version=10.0.0.12, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>packages\System.Text.Json.10.0.12\lib\net462\System.Text.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>packages\System.Threading.Tasks.Extensions.4.6.3\lib\net462\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ValueTuple" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Config.cs" />
|
||||
<Compile Include="Globals.cs" />
|
||||
<Compile Include="MidiManager.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Microsoft .NET Framework 4.7.2 %28x86 und x64%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="packages\System.ValueTuple.4.6.2\build\net471\System.ValueTuple.targets" Condition="Exists('packages\System.ValueTuple.4.6.2\build\net471\System.ValueTuple.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}".</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('packages\System.ValueTuple.4.6.2\build\net471\System.ValueTuple.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\System.ValueTuple.4.6.2\build\net471\System.ValueTuple.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
25
VirtualDJ_MidiDeviceBridge.sln
Normal file
25
VirtualDJ_MidiDeviceBridge.sln
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.14.36717.8 d17.14
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VirtualDJ_MidiDeviceBridge", "VirtualDJ_MidiDeviceBridge.csproj", "{BCC0E701-CFF0-485B-835A-BDAD9B55CD2A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{BCC0E701-CFF0-485B-835A-BDAD9B55CD2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BCC0E701-CFF0-485B-835A-BDAD9B55CD2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BCC0E701-CFF0-485B-835A-BDAD9B55CD2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BCC0E701-CFF0-485B-835A-BDAD9B55CD2A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {EC2D5750-7AB9-4D39-8DBC-E02022ACF61A}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
14
packages.config
Normal file
14
packages.config
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Bcl.AsyncInterfaces" version="10.0.12" targetFramework="net472" />
|
||||
<package id="midi-dot-net2" version="2.0.1" targetFramework="net472" />
|
||||
<package id="System.Buffers" version="4.6.1" targetFramework="net472" />
|
||||
<package id="System.IO.Pipelines" version="10.0.12" targetFramework="net472" />
|
||||
<package id="System.Memory" version="4.6.3" targetFramework="net472" />
|
||||
<package id="System.Numerics.Vectors" version="4.6.1" targetFramework="net472" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="6.1.2" targetFramework="net472" />
|
||||
<package id="System.Text.Encodings.Web" version="10.0.12" targetFramework="net472" />
|
||||
<package id="System.Text.Json" version="10.0.12" targetFramework="net472" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.6.3" targetFramework="net472" />
|
||||
<package id="System.ValueTuple" version="4.6.2" targetFramework="net472" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user