Initial Commit für Launchpad Code

main
Alex 2 years ago
parent b96bd61890
commit 83fc9f632c

@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Launchpad PasswortMaster", "Launchpad PasswortMaster\Launchpad PasswortMaster.csproj", "{7E3C8B4B-791D-4AAB-982B-858952CAF172}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "launchpad-dot-net", "..\..\Launchpad Coding Tests\launchpad-dot-net-master\launchpad-dot-net\launchpad-dot-net.csproj", "{2784C4AF-3B96-471B-91B0-1A11C342D375}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7E3C8B4B-791D-4AAB-982B-858952CAF172}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7E3C8B4B-791D-4AAB-982B-858952CAF172}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7E3C8B4B-791D-4AAB-982B-858952CAF172}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E3C8B4B-791D-4AAB-982B-858952CAF172}.Release|Any CPU.Build.0 = Release|Any CPU
{2784C4AF-3B96-471B-91B0-1A11C342D375}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2784C4AF-3B96-471B-91B0-1A11C342D375}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2784C4AF-3B96-471B-91B0-1A11C342D375}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2784C4AF-3B96-471B-91B0-1A11C342D375}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" 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>{7E3C8B4B-791D-4AAB-982B-858952CAF172}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Launchpad_PasswortMaster</RootNamespace>
<AssemblyName>Launchpad PasswortMaster</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</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>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<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="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Launchpad Coding Tests\launchpad-dot-net-master\launchpad-dot-net\launchpad-dot-net.csproj">
<Project>{2784c4af-3b96-471b-91b0-1a11c342d375}</Project>
<Name>launchpad-dot-net</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LaunchpadNET;
namespace Launchpad_PasswortMaster
{
class Program
{
static void Main(string[] args)
{
Interface LaunchInterface = new Interface();
LaunchpadNET.Interface.LaunchpadDevice Device = new Interface.LaunchpadDevice("Meins");
LaunchInterface.connect(LaunchInterface.getConnectedLaunchpads()[0]); //Connects with your Launchpad
LaunchInterface.clearAllLEDs();
int veloCount = 1;
//for (int indexerX = 0; indexerX < 8; indexerX++)
//{
//for (int indexerY = 0; indexerY < 8; indexerY++)
//{
LaunchInterface.setLED(3,0, 1);
//}
//}
Console.ReadLine();
LaunchInterface.clearAllLEDs();
}
}
}

@ -0,0 +1,36 @@
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("Launchpad PasswortMaster")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Orgname")]
[assembly: AssemblyProduct("Launchpad PasswortMaster")]
[assembly: AssemblyCopyright("Copyright © Orgname 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
// für COM-Komponenten. 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("7e3c8b4b-791d-4aab-982b-858952caf172")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,17 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

@ -0,0 +1,47 @@
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# Windows shortcuts
*.lnk
# =========================
# Operating System Files
# =========================
# OSX
# =========================
.DS_Store
.AppleDouble
.LSOverride
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

@ -0,0 +1,18 @@
# Launchpad.NET
*The easy way to create applications for the NOVATION Launchpad*
**Welcome to LAUNCHPAD.NET**
This is a simple C# library which allows you to interact with the NOVATION LAUNCHPAD.
You can view the GitHub Wiki over here, in order to learn how the functions work together.
This is only possible because of **jstnryan** and his https://github.com/jstnryan/midi-dot-net
**Features**
This comes with a few features right now, but I will extend this in the future!
+ Automatic MIDI Device sorting (you only see Launchpads, not other MIDI devices
+ Easy LED state setting (set LEDs only giving coordinates and velocity)
+ LED rect filling (with start and end coordinates)
+ Easy handling of Launchpads with a own class for Launchpad
+ Easy connecting / disconnecting
**Bugs?**
No problem, thats why GitHub is here. :joy:

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Express 14 for Windows Desktop
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "launchpad-dot-net", "launchpad-dot-net\launchpad-dot-net.csproj", "{2784C4AF-3B96-471B-91B0-1A11C342D375}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2784C4AF-3B96-471B-91B0-1A11C342D375}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2784C4AF-3B96-471B-91B0-1A11C342D375}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2784C4AF-3B96-471B-91B0-1A11C342D375}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2784C4AF-3B96-471B-91B0-1A11C342D375}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

@ -0,0 +1,374 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Midi;
namespace LaunchpadNET
{
public class Interface
{
private Pitch[,] notes = new Pitch[8, 8] {
{ Pitch.A5, Pitch.ASharp5, Pitch.B5, Pitch.C6, Pitch.CSharp6, Pitch.D6, Pitch.DSharp6, Pitch.E6 },
{ Pitch.B4, Pitch.C5, Pitch.CSharp5, Pitch.D5, Pitch.DSharp5, Pitch.E5, Pitch.F5, Pitch.FSharp5 },
{ Pitch.CSharp4, Pitch.D4, Pitch.DSharp4, Pitch.E4, Pitch.F4, Pitch.FSharp4, Pitch.G4, Pitch.GSharp4 },
{ Pitch.DSharp3, Pitch.E3, Pitch.F3, Pitch.FSharp3, Pitch.G3, Pitch.GSharp3, Pitch.A3, Pitch.ASharp3 },
{ Pitch.F2, Pitch.FSharp2, Pitch.G2, Pitch.GSharp2, Pitch.A2, Pitch.ASharp2, Pitch.B2, Pitch.C3 },
{ Pitch.G1, Pitch.GSharp1, Pitch.A1, Pitch.ASharp1, Pitch.B1, Pitch.C2, Pitch.CSharp2, Pitch.D2 },
{ Pitch.A0, Pitch.ASharp0, Pitch.B0, Pitch.C1, Pitch.CSharp1, Pitch.D1, Pitch.DSharp1, Pitch.E1 },
{ Pitch.BNeg1, Pitch.C0, Pitch.CSharp0, Pitch.D0, Pitch.DSharp0, Pitch.E0, Pitch.F0, Pitch.FSharp0 }
};
private Pitch[] rightLEDnotes = new Pitch[] {
Pitch.F6, Pitch.G5, Pitch.A4, Pitch.B3, Pitch.CSharp3, Pitch.DSharp2, Pitch.F1, Pitch.G0
};
public InputDevice targetInput;
public OutputDevice targetOutput;
public delegate void LaunchpadKeyEventHandler(object source, LaunchpadKeyEventArgs e);
public delegate void LaunchpadCCKeyEventHandler(object source, LaunchpadCCKeyEventArgs e);
/// <summary>
/// Event Handler when a Launchpad Key is pressed.
/// </summary>
public event LaunchpadKeyEventHandler OnLaunchpadKeyPressed;
public event LaunchpadCCKeyEventHandler OnLaunchpadCCKeyPressed;
public class LaunchpadCCKeyEventArgs : EventArgs
{
private int val;
public LaunchpadCCKeyEventArgs(int _val)
{
val = _val;
}
public int GetVal()
{
return val;
}
}
/// <summary>
/// EventArgs for pressed Launchpad Key
/// </summary>
public class LaunchpadKeyEventArgs : EventArgs
{
private int x;
private int y;
public LaunchpadKeyEventArgs(int _pX, int _pY)
{
x = _pX;
y = _pY;
}
public int GetX()
{
return x;
}
public int GetY()
{
return y;
}
}
/// <summary>
/// Creates a text scroll.
/// </summary>
/// <param name="text"></param>
/// <param name="speed"></param>
/// <param name="looping"></param>
/// <param name="velo"></param>
public void createTextScroll(string text, int speed, bool looping, int velo)
{
byte[] sysexHeader = { 240, 00, 32, 41, 2, 4 };
byte[] sysexStop = { 247 };
byte operation = 20;
byte _velocity = (byte)velo;
byte _speed = (byte)speed;
byte _loop = Convert.ToByte(looping);
byte[] _text = { };
byte[] finalArgs = { operation, _velocity, _loop, _speed };
List<byte> charList = new List<byte>();
foreach(char c in text)
{
int unicode = c;
if (unicode < 128)
charList.Add(Convert.ToByte(unicode));
}
_text = charList.ToArray();
byte[] finalBytes = sysexHeader.Concat(finalArgs.Concat(_text.Concat(sysexStop))).ToArray();
targetOutput.SendSysEx(finalBytes);
}
public void stopLoopingTextScroll()
{
byte[] stop = { 240, 0, 32, 41, 2, 24, 20, 247 };
targetOutput.SendSysEx(stop);
}
private void sysExAnswer(SysExMessage m)
{
byte[] msg = m.Data;
byte[] stopBytes = { 240, 0, 32, 41, 2, 24, 21, 247 };
}
private void midiPress(Midi.NoteOnMessage msg)
{
if (OnLaunchpadKeyPressed != null && !rightLEDnotes.Contains(msg.Pitch))
{
OnLaunchpadKeyPressed(this, new LaunchpadKeyEventArgs(midiNoteToLed(msg.Pitch)[0], midiNoteToLed(msg.Pitch)[1]));
}
else if (OnLaunchpadKeyPressed != null && rightLEDnotes.Contains(msg.Pitch))
{
OnLaunchpadCCKeyPressed(this, new LaunchpadCCKeyEventArgs(midiNoteToSideLED(msg.Pitch)));
}
}
public int midiNoteToSideLED(Pitch p)
{
for (int y = 0; y <= 7; y++)
{
if (rightLEDnotes[y] == p)
{
return y;
}
}
return 0;
}
/// <summary>
/// Returns the LED coordinates of a MIdi note
/// </summary>
/// <param name="p">The Midi Note.</param>
/// <returns>The X,Y coordinates.</returns>
public int[] midiNoteToLed(Pitch p)
{
for (int x = 0; x <= 7; x++)
{
for (int y = 0; y <= 7; y++)
{
if (notes[x,y] == p)
{
int[] r1 = { x, y };
return r1;
}
}
}
int[] r2 = { 0, 0 };
return r2;
}
/// <summary>
/// Returns the equilavent Midi Note to X and Y coordinates.
/// </summary>
/// <param name="x">The X coordinate of the LED</param>
/// <param name="y">The Y coordinate of the LED</param>
/// <returns>The midi note</returns>
public Pitch ledToMidiNote(int x, int y)
{
return notes[x, y];
}
public void clearAllLEDs()
{
for (int x = 0; x < 8; x++)
{
for (int y = 0; y < 8; y++)
{
setLED(x, y, 0);
}
}
for (int ry = 0; ry < 8; ry++)
{
setSideLED(ry, 0);
}
for (int tx = 1; tx < 9; tx++)
{
setTopLEDs(tx, 0);
}
}
/// <summary>
/// Fills Top Row LEDs.
/// </summary>
/// <param name="startX"></param>
/// <param name="endX"></param>
/// <param name="velo"></param>
public void fillTopLEDs(int startX, int endX, int velo)
{
for (int x = 1; x < 9; x++)
{
if (x >= startX && x <= endX)
{
setTopLEDs(x, velo);
}
}
}
/// <summary>
/// Fills a region of Side LEDs.
/// </summary>
/// <param name="startY"></param>
/// <param name="endY"></param>
/// <param name="velo"></param>
public void fillSideLEDs(int startY, int endY, int velo)
{
for (int y = 0; y < rightLEDnotes.Length; y++)
{
if (y >= startY && y <= endY)
{
setSideLED(y, velo);
}
}
}
/// <summary>
/// Creates a rectangular mesh of LEDs.
/// </summary>
/// <param name="startX">Start X coordinate</param>
/// <param name="startY">Start Y coordinate</param>
/// <param name="endX">End X coordinate</param>
/// <param name="endY">End Y coordinate</param>
/// <param name="velo">Painting velocity</param>
public void fillLEDs(int startX, int startY, int endX, int endY, int velo)
{
for (int x = 0; x < notes.Length; x++)
{
for (int y = 0; y < notes.Length; y++)
{
if (x >= startX && y >= startY && x <= endX && y <= endY)
setLED(x, y, velo);
}
}
}
/// <summary>
/// Sets a Top LED of the launchpad
/// </summary>
/// <param name="x"></param>
/// <param name="velo"></param>
public void setTopLEDs(int x, int velo)
{
byte[] data = { 240, 0, 32, 41, 2, 24, 10, Convert.ToByte(103+x), Convert.ToByte(velo), 247 };
targetOutput.SendSysEx(data);
}
/// <summary>
/// Sets a Side LED of the Launchpad.
/// </summary>
/// <param name="y">The height of the right Side LED.</param>
/// <param name="velo">Velocity index.</param>
public void setSideLED(int y, int velo)
{
targetOutput.SendNoteOn(Channel.Channel1, rightLEDnotes[y], velo);
}
/// <summary>
/// Sets a LED of the Launchpad.
/// </summary>
/// <param name="x">The X coordinate.</param>
/// <param name="y">The Y coordinate.</param>
/// <param name="velo">The velocity.</param>
public void setLED(int x, int y, int velo)
{
try
{
targetOutput.SendNoteOn(Channel.Channel1, notes[x, y], velo);
}
catch (Midi.DeviceException)
{
Console.WriteLine("<< LAUNCHPAD.NET >> Midi.DeviceException");
throw;
}
}
/// <summary>
/// Returns all connected and installed Launchpads.
/// </summary>
/// <returns>Returns LaunchpadDevice array.</returns>
public LaunchpadDevice[] getConnectedLaunchpads()
{
List<LaunchpadDevice> tempDevices = new List<LaunchpadDevice>();
foreach (InputDevice id in Midi.InputDevice.InstalledDevices)
{
foreach (OutputDevice od in Midi.OutputDevice.InstalledDevices)
{
if (id.Name == od.Name)
{
if (id.Name.ToLower().Contains("launchpad"))
{
tempDevices.Add(new LaunchpadDevice(id.Name));
}
}
}
}
return tempDevices.ToArray();
}
/// <summary>
/// Function to connect with a LaunchpadDevice
/// </summary>
/// <param name="device">The Launchpad to connect to.</param>
/// <returns>Returns bool if connection was successful.</returns>
public bool connect(LaunchpadDevice device)
{
foreach(InputDevice id in Midi.InputDevice.InstalledDevices)
{
if (id.Name.ToLower() == device._midiName.ToLower())
{
targetInput = id;
id.Open();
targetInput.NoteOn += new InputDevice.NoteOnHandler(midiPress);
targetInput.StartReceiving(null);
}
}
foreach (OutputDevice od in Midi.OutputDevice.InstalledDevices)
{
if (od.Name.ToLower() == device._midiName.ToLower())
{
targetOutput = od;
od.Open();
}
}
return true; // targetInput.IsOpen && targetOutput.IsOpen;
}
/// <summary>
/// Disconnects a given LaunchpadDevice
/// </summary>
/// <param name="device">The Launchpad to disconnect.</param>
/// <returns>Returns bool if disconnection was successful.</returns>
public bool disconnect(LaunchpadDevice device)
{
if (targetInput.IsOpen && targetOutput.IsOpen)
{
targetInput.StopReceiving();
targetInput.Close();
targetOutput.Close();
}
return !targetInput.IsOpen && !targetOutput.IsOpen;
}
public class LaunchpadDevice
{
public string _midiName;
//public int _midiDeviceId;
public LaunchpadDevice(string name)
{
_midiName = name;
}
}
}
}

@ -0,0 +1,36 @@
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("launchpad-dot-net")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("launchpad-dot-net")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
// für COM-Komponenten. 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(true)]
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("2784c4af-3b96-471b-91b0-1a11c342d375")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" 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>{2784C4AF-3B96-471B-91B0-1A11C342D375}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>launchpad_dot_net</RootNamespace>
<AssemblyName>launchpad-dot-net</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<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' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Midi, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\Debug\Midi.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<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="Interface.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

@ -0,0 +1,120 @@
# App specific
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
[Bb]in/
[Oo]bj/
# mstest test results
TestResults
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
.vs/
*.suo
*.user
*.sln.docstates
*.userprefs
# Build results
[Dd]ebug/
[Rr]elease/
x64/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.log
*.vspscc
*.vssscc
.builds
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*
# NCrunch
*.ncrunch*
.*crunch*.local.xml
# 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
*.Publish.xml
# NuGet Packages Directory
packages
# Windows Azure Build Output
csx
*.build.csdef
# Others
[Bb]in
[Oo]bj
sql
TestResults
[Tt]est[Rr]esult*
*.Cache
ClientBin
[Ss]tyle[Cc]op.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects
# 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

@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntelOrca.Launchpad", "IntelOrca.Launchpad\IntelOrca.Launchpad.csproj", "{FCF77754-C985-4F3D-BE0B-E14011C5DC5B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntelOrca.LaunchpadTests", "IntelOrca.LaunchpadTests\IntelOrca.LaunchpadTests.csproj", "{C2C7FD5A-D56C-4C74-91E3-2D9F5D92FCA3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FCF77754-C985-4F3D-BE0B-E14011C5DC5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FCF77754-C985-4F3D-BE0B-E14011C5DC5B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FCF77754-C985-4F3D-BE0B-E14011C5DC5B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FCF77754-C985-4F3D-BE0B-E14011C5DC5B}.Release|Any CPU.Build.0 = Release|Any CPU
{C2C7FD5A-D56C-4C74-91E3-2D9F5D92FCA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2C7FD5A-D56C-4C74-91E3-2D9F5D92FCA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2C7FD5A-D56C-4C74-91E3-2D9F5D92FCA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2C7FD5A-D56C-4C74-91E3-2D9F5D92FCA3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

@ -0,0 +1,56 @@
using System;
namespace IntelOrca.Launchpad
{
public class ButtonPressEventArgs : EventArgs
{
private ButtonType mType;
private ToolbarButton mToolbarButton;
private SideButton mSidebarButton;
private int mX, mY;
public ButtonPressEventArgs(ToolbarButton toolbarButton)
{
mType = ButtonType.Toolbar;
mToolbarButton = toolbarButton;
}
public ButtonPressEventArgs(SideButton sideButton)
{
mType = ButtonType.Side;
mSidebarButton = sideButton;
}
public ButtonPressEventArgs(int x, int y)
{
mType = ButtonType.Grid;
mX = x;
mY = y;
}
public ButtonType Type
{
get { return mType; }
}
public ToolbarButton ToolbarButton
{
get { return mToolbarButton; }
}
public SideButton SidebarButton
{
get { return mSidebarButton; }
}
public int X
{
get { return mX; }
}
public int Y
{
get { return mY; }
}
}
}

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" 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>{FCF77754-C985-4F3D-BE0B-E14011C5DC5B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>IntelOrca.Launchpad</RootNamespace>
<AssemblyName>IntelOrca.Launchpad</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</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>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="Midi">
<HintPath>..\packages\midi-dot-net.1.1.0\lib\net35\Midi.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="ButtonPressEventArgs.cs" />
<Compile Include="LaunchpadButton.cs" />
<Compile Include="LaunchpadDevice.cs" />
<Compile Include="LaunchpadException.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

@ -0,0 +1,82 @@
using Midi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IntelOrca.Launchpad
{
public enum ButtonType { Grid, Toolbar, Side }
public enum ButtonBrightness { Off, Low, Medium, Full };
public enum ButtonPressState { Up = 0, Down = 127 };
public class LaunchpadButton
{
private LaunchpadDevice mLaunchpadDevice;
private ButtonBrightness mRedBrightness, mGreenBrightness;
private ButtonPressState mState;
private ButtonType mType;
private int mIndex;
internal LaunchpadButton(LaunchpadDevice launchpadDevice, ButtonType type, int index)
{
mLaunchpadDevice = launchpadDevice;
mType = type;
mIndex = index;
}
public void TurnOnLight()
{
SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
}
public void TurnOffLight()
{
SetBrightness(ButtonBrightness.Off, ButtonBrightness.Off);
}
public void SetBrightness(ButtonBrightness red, ButtonBrightness green)
{
if (mRedBrightness == red && mGreenBrightness == green)
return;
mRedBrightness = red;
mGreenBrightness = green;
int vel = ((int)mGreenBrightness << 4) | (int)mRedBrightness;
if (!mLaunchpadDevice.DoubleBuffered)
vel |= 12;
SetLED(vel);
}
private void SetLED(int value)
{
if (mType == ButtonType.Toolbar)
mLaunchpadDevice.OutputDevice.SendControlChange(Channel.Channel1, (Control)mIndex, value);
else
mLaunchpadDevice.OutputDevice.SendNoteOn(Channel.Channel1, (Pitch)mIndex, value);
}
public ButtonBrightness RedBrightness
{
get { return mRedBrightness; }
internal set { mRedBrightness = value; }
}
public ButtonBrightness GreenBrightness
{
get { return mGreenBrightness; }
internal set { mGreenBrightness = value; }
}
public ButtonPressState State
{
get { return mState; }
internal set { mState = value; }
}
}
}

@ -0,0 +1,181 @@
using Midi;
using System;
using System.Collections.Generic;
using System.Linq;
namespace IntelOrca.Launchpad
{
public enum ToolbarButton { Up, Down, Left, Right, Session, User1, User2, Mixer }
public enum SideButton { Volume, Pan, SoundA, SoundB, Stop, TrackOn, Solo, Arm }
public class LaunchpadDevice
{
private InputDevice mInputDevice;
private OutputDevice mOutputDevice;
private bool mDoubleBuffered;
private bool mDoubleBufferedState;
private readonly LaunchpadButton[] mToolbar = new LaunchpadButton[8];
private readonly LaunchpadButton[] mSide = new LaunchpadButton[8];
private readonly LaunchpadButton[,] mGrid = new LaunchpadButton[8, 8];
public event EventHandler<ButtonPressEventArgs> ButtonPressed;
public LaunchpadDevice() : this(0) { }
public LaunchpadDevice(int index)
{
InitialiseButtons();
int i = 0;
mInputDevice = InputDevice.InstalledDevices.Where(x => x.Name.Contains("Launchpad")).
FirstOrDefault(x => i++ == index);
i = 0;
mOutputDevice = OutputDevice.InstalledDevices.Where(x => x.Name.Contains("Launchpad")).
FirstOrDefault(x => i++ == index);
if (mInputDevice == null)
throw new LaunchpadException("Unable to find input device.");
if (mOutputDevice == null)
throw new LaunchpadException("Unable to find output device.");
mInputDevice.Open();
mOutputDevice.Open();
mInputDevice.StartReceiving(new Clock(120));
mInputDevice.NoteOn += mInputDevice_NoteOn;
mInputDevice.ControlChange += mInputDevice_ControlChange;
Reset();
}
private void InitialiseButtons()
{
for (int i = 0; i < 8; i++)
{
mToolbar[i] = new LaunchpadButton(this, ButtonType.Toolbar, 104 + i);
mSide[i] = new LaunchpadButton(this, ButtonType.Side, i * 16 + 8);
}
for (int y = 0; y < 8; y++)
for (int x = 0; x < 8; x++)
mGrid[x, y] = new LaunchpadButton(this, ButtonType.Grid, y * 16 + x);
}
private void StartDoubleBuffering()
{
mDoubleBuffered = true;
mDoubleBufferedState = false;
mOutputDevice.SendControlChange(Channel.Channel1, (Control)0, 32 | 16 | 1);
}
public void Refresh()
{
if (!mDoubleBufferedState)
mOutputDevice.SendControlChange(Channel.Channel1, (Control)0, 32 | 16 | 4);
else
mOutputDevice.SendControlChange(Channel.Channel1, (Control)0, 32 | 16 | 1);
mDoubleBufferedState = !mDoubleBufferedState;
}
private void EndDoubleBuffering()
{
mOutputDevice.SendControlChange(Channel.Channel1, (Control)0, 32 | 16);
mDoubleBuffered = false;
}
public void Reset()
{
mOutputDevice.SendControlChange(Channel.Channel1, (Control)0, 0);
Buttons.ToList().ForEach(x => x.RedBrightness = x.GreenBrightness = ButtonBrightness.Off);
}
private void mInputDevice_NoteOn(NoteOnMessage msg)
{
LaunchpadButton button = GetButton(msg.Pitch);
if (button == null)
return;
button.State = (ButtonPressState)msg.Velocity;
if (ButtonPressed != null && button.State == ButtonPressState.Down)
{
if ((int)msg.Pitch % 16 == 8)
ButtonPressed.Invoke(this, new ButtonPressEventArgs((SideButton)((int)msg.Pitch / 16)));
else
ButtonPressed.Invoke(this, new ButtonPressEventArgs((int)msg.Pitch % 16, (int)msg.Pitch / 16));
}
}
private void mInputDevice_ControlChange(ControlChangeMessage msg)
{
ToolbarButton toolbarButton = (ToolbarButton)((int)msg.Control - 104);
LaunchpadButton button = GetButton(toolbarButton);
if (button == null)
return;
button.State = (ButtonPressState)msg.Value;
if (ButtonPressed != null && button.State == ButtonPressState.Down)
{
ButtonPressed.Invoke(this, new ButtonPressEventArgs(toolbarButton));
}
}
public LaunchpadButton GetButton(ToolbarButton toolbarButton)
{
return mToolbar[(int)toolbarButton];
}
public LaunchpadButton GetButton(SideButton sideButton)
{
return mSide[(int)sideButton];
}
private LaunchpadButton GetButton(Pitch pitch)
{
int x = (int)pitch % 16;
int y = (int)pitch / 16;
if (x < 8 && y < 8)
return mGrid[x, y];
else if (x == 8 && y < 8)
return mSide[y];
return null;
}
public bool DoubleBuffered
{
get { return mDoubleBuffered; }
set
{
if (mDoubleBuffered)
EndDoubleBuffering();
else
StartDoubleBuffering();
}
}
public LaunchpadButton this[int x, int y]
{
get { return mGrid[x, y]; }
}
public IEnumerable<LaunchpadButton> Buttons
{
get
{
for (int y = 0; y < 8; y++)
for (int x = 0; x < 8; x++)
yield return mGrid[x, y];
}
}
internal OutputDevice OutputDevice
{
get { return mOutputDevice; }
}
}
}

@ -0,0 +1,10 @@
using System;
namespace IntelOrca.Launchpad
{
public class LaunchpadException : Exception
{
public LaunchpadException() : base() { }
public LaunchpadException(string message) : base(message) { }
}
}

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("IntelOrca.Launchpad")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("IntelOrca.Launchpad")]
[assembly: AssemblyCopyright("Copyright © Ted John 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("02ec4a3e-47d6-4482-a424-0bde02acc866")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="midi-dot-net" version="1.1.0" targetFramework="net45" />
</packages>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

@ -0,0 +1,158 @@
using IntelOrca.Launchpad;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Media;
namespace IntelOrca.LaunchpadTests
{
class Bulldog
{
private LaunchpadDevice mLaunchpadDevice;
private List<Dog> mDogs = new List<Dog>();
private Random mRandom = new Random();
private long mCurrentTicks = 0;
private long mNextDogTick = 2000;
private int mMisses, mHits;
public Bulldog(LaunchpadDevice device)
{
mLaunchpadDevice = device;
mLaunchpadDevice.ButtonPressed += mLaunchpadDevice_ButtonPressed;
}
private void mLaunchpadDevice_ButtonPressed(object sender, ButtonPressEventArgs e)
{
if (e.Type == ButtonType.Grid) {
var pressedDogs = mDogs.Where(d => (int)d.X == e.X && (int)d.Y == e.Y);
pressedDogs.ToList().ForEach(d => d.Killed = true);
if (pressedDogs.Count() > 0)
SystemSounds.Beep.Play();
}
}
public void Play()
{
long last_tick = Environment.TickCount;
long delay = 12;
while (true) {
if (Environment.TickCount - last_tick < delay)
continue;
mCurrentTicks += Environment.TickCount - last_tick;
last_tick = Environment.TickCount;
Update();
Draw();
}
}
private void Update()
{
mDogs.ForEach(d => d.Update());
var missedDogs = mDogs.Where(d => d.LeftGrid);
var hitDogs = mDogs.Where(d => d.Killed);
mMisses += missedDogs.Count();
mHits += hitDogs.Count();
mDogs.RemoveAll(d => d.LeftGrid || d.Killed);
if (mDogs.Count < 8) {
if (mCurrentTicks > mNextDogTick) {
mDogs.Add(GetNewDog());
mNextDogTick = mCurrentTicks + mRandom.Next(100, 1000);
}
}
Console.Clear();
Console.WriteLine("Misses: {0:0000}", mMisses);
Console.WriteLine("Hits: {0:0000}", mHits);
Console.WriteLine("Score: {0:0000}", (mHits * 10) - (mMisses * 5));
}
private void Draw()
{
ButtonBrightness[,] redgrid = new ButtonBrightness[8, 8];
ButtonBrightness[,] greengrid = new ButtonBrightness[8, 8];
mDogs.ForEach(d => {
if (!(d.X >= 0 && d.X < 8 && d.Y >= 0 && d.Y < 8))
return;
redgrid[(int)d.X, (int)d.Y] = ButtonBrightness.Full;
greengrid[(int)d.X, (int)d.Y] = ButtonBrightness.Full;
});
for (int y = 0; y < 8; y++)
for (int x = 0; x < 8; x++)
mLaunchpadDevice[x, y].SetBrightness(redgrid[x, y], greengrid[x, y]);
mLaunchpadDevice.Refresh();
}
private Dog GetNewDog()
{
Dog dog = new Dog();
if (mRandom.Next(2) == 0) {
// Row
dog.Y = mRandom.Next(8);
dog.VX = mRandom.NextDouble() / 5;
dog.X = 0;
if (mRandom.Next(2) == 0) {
dog.X = 7;
dog.VX *= -1;
}
} else {
// Column
dog.X = mRandom.Next(8);
dog.VY = mRandom.NextDouble() / 5;
dog.Y = 0;
if (mRandom.Next(2) == 0) {
dog.Y = 7;
dog.VY *= -1;
}
}
return dog;
}
class Dog
{
public Dog() { }
public void Update()
{
X += VX;
Y += VY;
}
public bool LeftGrid
{
get
{
if (X < 0 && VX <= 0)
return true;
if (Y < 0 && VY <= 0)
return true;
if (X >= 8 && VX >= 0)
return true;
if (Y >= 8 && VY >= 0)
return true;
return false;
}
}
public bool Killed { get; set; }
public int Colour { get; set; }
public double X { get; set; }
public double Y { get; set; }
public double VX { get; set; }
public double VY { get; set; }
}
}
}

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" 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>{C2C7FD5A-D56C-4C74-91E3-2D9F5D92FCA3}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>IntelOrca.LaunchpadTests</RootNamespace>
<AssemblyName>IntelOrca.LaunchpadTests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</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>
<ItemGroup>
<Reference Include="Midi">
<HintPath>..\packages\midi-dot-net.1.1.0\lib\net35\Midi.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Bulldog.cs" />
<Compile Include="GeometrischeTests.cs" />
<Compile Include="PWGenerator.cs" />
<Compile Include="Snake.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RainSequencer.cs" />
<Compile Include="Reversi.cs" />
<Compile Include="ScrollingLetters.cs" />
<Compile Include="ToggleGrid.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IntelOrca.Launchpad\IntelOrca.Launchpad.csproj">
<Project>{fcf77754-c985-4f3d-be0b-e14011c5dc5b}</Project>
<Name>IntelOrca.Launchpad</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="text.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

File diff suppressed because it is too large Load Diff

@ -0,0 +1,90 @@
using IntelOrca.Launchpad;
using System;
namespace IntelOrca.LaunchpadTests
{
class Program
{
static void Main(string[] args)
{
LaunchpadDevice device;
Console.WriteLine("Launchpad Tests");
Console.WriteLine("Ted John 2013");
Console.WriteLine("");
try
{
device = new LaunchpadDevice();
device.DoubleBuffered = true;
Console.WriteLine("Launchpad found");
}
catch
{
Console.WriteLine("No launchpad found");
Console.ReadLine();
return;
}
Console.WriteLine("");
Console.WriteLine("0: Grid toggle");
Console.WriteLine("1: Scrolling message");
Console.WriteLine("2: Bulldog");
Console.WriteLine("3: Rain sequencer");
Console.WriteLine("4: Reversi");
Console.WriteLine("5: Snake");
Console.WriteLine("6: Geometrische Tests");
Console.WriteLine("7: Super Safe Password Generator");
int i;
while (!Int32.TryParse(Console.ReadLine(), out i))
{
Console.WriteLine("Try again...");
}
switch (i)
{
case 0:
ToggleGrid toggleGrid = new ToggleGrid(device);
toggleGrid.Run();
break;
case 1:
Console.Write("Type a message:");
string message = Console.ReadLine();
ScrollingLetters scrollingLetters = new ScrollingLetters(device);
scrollingLetters.Text = message.ToUpper();
scrollingLetters.ScrollText();
break;
case 2:
Bulldog bulldog = new Bulldog(device);
bulldog.Play();
break;
case 3:
RainSequencer rain = new RainSequencer(device);
rain.Run();
break;
case 4:
Reversi reversi = new Reversi(device);
reversi.Run();
break;
case 5:
Snake snake = new Snake(device);
snake.Run();
break;
case 6:
GeometrischeTests geoTest = new GeometrischeTests(device);
geoTest.Run();
break;
case 7:
PWGenerator pwGen = new PWGenerator(device);
pwGen.Run();
break;
default:
Console.WriteLine("No such application");
break;
}
}
}
}

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("IntelOrca.LaunchpadTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("IntelOrca.LaunchpadTests")]
[assembly: AssemblyCopyright("Copyright © Ted John 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3ca042d4-ea08-4d51-a0c7-1f1ef0ece762")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,266 @@
using IntelOrca.Launchpad;
using Midi;
using System;
using System.Threading;
namespace IntelOrca.LaunchpadTests
{
class RainSequencer
{
const int NumCols = 16;
const int NumRows = 8;
private LaunchpadDevice mLaunchpadDevice;
private bool[,] mSequence = new bool[NumCols, NumRows];
private bool[] mRemove = new bool[NumCols];
private int mSequenceOffset;
private int mColumnOffset;
private int mMode, mSoundType;
private int mConfirmTime;
private bool mForceDraw;
private int mTempo = 8 * 60;
OutputDevice mOutputDevice;
private int mInstrument = 0;
private int mPercussion = 0;
public RainSequencer(LaunchpadDevice device)
{
mLaunchpadDevice = device;
mOutputDevice = OutputDevice.InstalledDevices[0];
mOutputDevice.Open();
mLaunchpadDevice.ButtonPressed += mLaunchpadDevice_ButtonPressed;
/*
Random rand = new Random();
for (int y = 0; y < NumRows; y++)
for (int x = 0; x < NumRows; x++)
if (rand.Next(0, 12) == 0)
mSequence[x, y] = true;
* */
}
private int SeqYtoButtonY(int y)
{
return 0;
}
private int ButtonYtoSeqY(int y)
{
return (y + NumRows - mSequenceOffset) % NumRows;
}
private int ButtonXtoColX(int x)
{
return (x + NumCols - mColumnOffset) % NumCols;
}
private void mLaunchpadDevice_ButtonPressed(object sender, ButtonPressEventArgs e)
{
if (e.Type == ButtonType.Grid) {
if (e.Y == 7) {
mRemove[ButtonXtoColX(e.X)] = !mRemove[ButtonXtoColX(e.X)];
if (mMode == 1)
PlayNoise(e.X);
} else {
mSequence[ButtonXtoColX(e.X), ButtonYtoSeqY(e.Y)] = !mSequence[ButtonXtoColX(e.X), ButtonYtoSeqY(e.Y)];
}
mForceDraw = true;
} else if (e.Type == ButtonType.Toolbar) {
switch (e.ToolbarButton) {
case ToolbarButton.Up:
mSequenceOffset = (mSequenceOffset + NumRows - 1) % NumRows;
break;
case ToolbarButton.Down:
mSequenceOffset = (mSequenceOffset + 1) % NumRows;
break;
case ToolbarButton.Left:
mColumnOffset = (mColumnOffset + NumCols - 1) % NumCols;
break;
case ToolbarButton.Right:
mColumnOffset = (mColumnOffset + 1) % NumCols;
break;
case ToolbarButton.Mixer:
mMode = (mMode == 0 ? 1 : 0);
break;
case ToolbarButton.Session:
if (mConfirmTime > 0) {
for (int y = 0; y < NumRows; y++)
for (int x = 0; x < NumCols; x++)
mSequence[x, y] = false;
mConfirmTime = 0;
} else {
mConfirmTime = 1000;
}
break;
}
mForceDraw = true;
} else if (e.Type == ButtonType.Side) {
switch (e.SidebarButton) {
case SideButton.Volume:
if (mTempo < 1980)
mTempo += 20;
break;
case SideButton.Pan:
if (mTempo > 20)
mTempo -= 20;
break;
case SideButton.SoundA:
if (mSoundType == 0) {
mPercussion = (mPercussion + 1) % (Percussion.OpenTriangle - Percussion.BassDrum2 + 1);
mOutputDevice.SendProgramChange(Channel.Channel1, (Instrument)mInstrument);
} else {
mSoundType = 0;
}
break;
case SideButton.SoundB:
if (mSoundType == 1) {
mInstrument = (mInstrument + 1) % 127;
mOutputDevice.SendProgramChange(Channel.Channel1, (Instrument)mInstrument);
} else {
mSoundType = 1;
}
break;
case SideButton.Arm:
mSequenceOffset = 0;
mColumnOffset = 0;
break;
}
}
}
public void Run()
{
long last_tick = Environment.TickCount;
long delay = 1;
long duration = 0;
while (true) {
delay = (int)(1000.0 / (mTempo / 60.0));
duration = Environment.TickCount - last_tick;
if (duration < delay) {
if (mForceDraw) {
Draw();
mForceDraw = false;
}
continue;
}
last_tick = Environment.TickCount;
mConfirmTime = Math.Max(0, mConfirmTime - (int)duration);
Update();
Draw();
}
}
private void PlayNoise(int tone)
{
new Thread(new ThreadStart(() => {
if (mSoundType == 0) {
mOutputDevice.SendPercussion(Percussion.BassDrum2 + mPercussion + tone, 127);
} else {
mOutputDevice.SendNoteOn(Channel.Channel1, Pitch.A4 + tone, 127);
Thread.Sleep((int)(1000.0 / (mTempo / 60.0)));
mOutputDevice.SendNoteOff(Channel.Channel1, Pitch.A4 + tone, 127);
}
// Console.Beep(100 * (tone + 3), 100);
})).Start();
}
private void DiscardRedBeats()
{
int y = ButtonYtoSeqY(7);
for (int x = 0; x < NumCols; x++)
if (mSequence[x, y] && mRemove[x])
mSequence[x, y] = false;
}
private void PlayBeats()
{
int y = ButtonYtoSeqY(7);
for (int x = 0; x < NumCols; x++)
if (mSequence[x, y])
PlayNoise(x);
}
private void Update()
{
if (mMode == 1)
return;
DiscardRedBeats();
mSequenceOffset = (mSequenceOffset + 1) % NumRows;
PlayBeats();
}
private void Draw()
{
ButtonBrightness[,] redgrid = new ButtonBrightness[8, 8];
ButtonBrightness[,] greengrid = new ButtonBrightness[8, 8];
for (int y = 0; y < 7; y++)
for (int x = 0; x < 8; x++)
if (mSequence[ButtonXtoColX(x), ButtonYtoSeqY(y)])
redgrid[x, y] = greengrid[x, y] = ButtonBrightness.Full;
for (int x = 0; x < 8; x++) {
ButtonBrightness brightness = (mSequence[ButtonXtoColX(x), ButtonYtoSeqY(7)] ? ButtonBrightness.Full : ButtonBrightness.Low);
if (!mRemove[ButtonXtoColX(x)])
greengrid[x, 7] = brightness;
else
redgrid[x, 7] = brightness;
}
for (int y = 0; y < 8; y++)
for (int x = 0; x < 8; x++)
mLaunchpadDevice[x, y].SetBrightness(redgrid[x, y], greengrid[x, y]);
if (mConfirmTime > 0)
mLaunchpadDevice.GetButton(ToolbarButton.Session).TurnOnLight();
else
mLaunchpadDevice.GetButton(ToolbarButton.Session).TurnOffLight();
if (mMode == 1)
mLaunchpadDevice.GetButton(ToolbarButton.Mixer).SetBrightness(ButtonBrightness.Full, ButtonBrightness.Off);
else
mLaunchpadDevice.GetButton(ToolbarButton.Mixer).SetBrightness(ButtonBrightness.Off, ButtonBrightness.Full);
if (mSoundType == 0) {
mLaunchpadDevice.GetButton(SideButton.SoundA).TurnOnLight();
mLaunchpadDevice.GetButton(SideButton.SoundB).TurnOffLight();
} else {
mLaunchpadDevice.GetButton(SideButton.SoundA).TurnOffLight();
mLaunchpadDevice.GetButton(SideButton.SoundB).TurnOnLight();
}
mLaunchpadDevice.GetButton(ToolbarButton.Up).TurnOnLight();
mLaunchpadDevice.GetButton(ToolbarButton.Down).TurnOnLight();
mLaunchpadDevice.GetButton(ToolbarButton.Left).TurnOnLight();
mLaunchpadDevice.GetButton(ToolbarButton.Right).TurnOnLight();
mLaunchpadDevice.GetButton(SideButton.Volume).TurnOnLight();
mLaunchpadDevice.GetButton(SideButton.Pan).TurnOnLight();
mLaunchpadDevice.GetButton(SideButton.Arm).TurnOnLight();
mLaunchpadDevice.Refresh();
Console.SetCursorPosition(0, 0);
for (int y = 0; y < NumRows; y++) {
for (int x = 0; x < NumCols; x++) {
if (mSequence[x, y])
Console.Write("X");
else
Console.Write(".");
}
Console.WriteLine();
}
}
}
}

@ -0,0 +1,279 @@
using IntelOrca.Launchpad;
using Midi;
using System;
using System.Collections.Generic;
namespace IntelOrca.LaunchpadTests
{
class Reversi
{
private Random mRandom = new Random();
private LaunchpadDevice mLaunchpadDevice;
private int[,] mGrid = new int[8, 8];
private int mPlayerTurn = 1;
private int mPlayerWinning = 0;
private int mConfirmTime;
private bool mForceDraw;
private int mGameState = 0;
private bool mShowPossibleMoves = true;
private bool mSolo = false;
private int mFlashCounter = 0;
private List<Tuple<int, int>> mPossiblePlaces = new List<Tuple<int, int>>();
OutputDevice mOutputDevice;
public Reversi(LaunchpadDevice device)
{
mLaunchpadDevice = device;
mLaunchpadDevice.DoubleBuffered = false;
mLaunchpadDevice.ButtonPressed += mLaunchpadDevice_ButtonPressed;
mOutputDevice = OutputDevice.InstalledDevices[0];
mOutputDevice.Open();
Restart();
}
private void mLaunchpadDevice_ButtonPressed(object sender, ButtonPressEventArgs e)
{
if (e.Type == ButtonType.Grid) {
if (CanPlaceAt(e.X, e.Y))
PlaceAt(e.X, e.Y);
} else if (e.Type == ButtonType.Side) {
if (e.SidebarButton == SideButton.TrackOn) {
mShowPossibleMoves = !mShowPossibleMoves;
mForceDraw = true;
} else if (e.SidebarButton == SideButton.Solo) {
mSolo = !mSolo;
}
} else if (e.Type == ButtonType.Toolbar) {
if (e.ToolbarButton == ToolbarButton.Session) {
if (mConfirmTime > 0) {
Restart();
mConfirmTime = 0;
} else {
mConfirmTime = 1000;
}
}
}
}
private void Restart()
{
for (int y = 0; y < 8; y++)
for (int x = 0; x < 8; x++)
mGrid[x, y] = 0;
mGrid[3, 3] = 1;
mGrid[4, 3] = 2;
mGrid[3, 4] = 2;
mGrid[4, 4] = 1;
mGameState = 0;
SetPlayerGo(1);
mOutputDevice.SendPercussion(Percussion.LongWhistle, 127);
}
private bool CanPlaceAt(int x, int y)
{
if (mGrid[x, y] != 0)
return false;
for (int dy = -1; dy <= 1; dy++)
for (int dx = -1; dx <= 1; dx++)
if (CheckDirection(x, y, dx, dy))
return true;
return false;
}
private bool CheckDirection(int x, int y, int dx, int dy, int state = 0)
{
x += dx;
y += dy;
if (!InBounds(x, y))
return false;
if (state == 0) {
if (mGrid[x, y] == 0 || mGrid[x, y] == mPlayerTurn)
return false;
return CheckDirection(x, y, dx, dy, 1);
} else if (state == 1) {
if (mGrid[x, y] == 0)
return false;
if (mGrid[x, y] == mPlayerTurn)
return true;
return CheckDirection(x, y, dx, dy, 1);
}
return false;
}
private bool InBounds(int x, int y)
{
return (x >= 0 && y >= 0 && x < 8 && y < 8);
}
private void PlaceAt(int x, int y)
{
if (mPlayerTurn == 1)
mOutputDevice.SendPercussion(Percussion.SnareDrum1, 127);
else if (mPlayerTurn == 2)
mOutputDevice.SendPercussion(Percussion.SnareDrum2, 127);
for (int dy = -1; dy <= 1; dy++)
for (int dx = -1; dx <= 1; dx++)
if (CheckDirection(x, y, dx, dy))
SwapDirection(x, y, dx, dy);
mGrid[x, y] = mPlayerTurn;
SetPlayerGo((mPlayerTurn == 1 ? 2 : 1));
}
private void SwapDirection(int x, int y, int dx, int dy)
{
x += dx;
y += dy;
if (mGrid[x, y] != mPlayerTurn) {
mGrid[x, y] = mPlayerTurn;
SwapDirection(x, y, dx, dy);
}
}
private void UpdatePossiblePlaces()
{
mPossiblePlaces.Clear();
for (int y = 0; y < 8; y++)
for (int x = 0; x < 8; x++)
if (CanPlaceAt(x, y))
mPossiblePlaces.Add(new Tuple<int, int>(x, y));
}
private void SetPlayerGo(int n)
{
mPlayerTurn = n;
UpdatePossiblePlaces();
if (mPossiblePlaces.Count == 0) {
mPlayerTurn = (mPlayerTurn == 1 ? 2 : 1);
UpdatePossiblePlaces();
if (mPossiblePlaces.Count == 0) {
mGameState = 1;
mConfirmTime = int.MaxValue;
mOutputDevice.SendPercussion(Percussion.CrashCymbal1, 127);
}
}
mPlayerWinning = GetWinner();
if (mPossiblePlaces.Count > 0 && mSolo && mPlayerTurn == 2) {
int p = mRandom.Next(0, mPossiblePlaces.Count);
PlaceAt(mPossiblePlaces[p].Item1, mPossiblePlaces[p].Item2);
}
mForceDraw = true;
}
private int GetWinner()
{
int p1 = 0, p2 = 0;
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
if (mGrid[x, y] == 1)
p1++;
else if (mGrid[x, y] == 2)
p2++;
}
}
if (p1 > p2)
return 1;
else if (p2 > p1)
return 2;
else
return 0;
}
public void Run()
{
long last_tick = Environment.TickCount;
long delay = 1;
long duration = 0;
while (true) {
delay = (int)(1000.0 / 60.0);
duration = Environment.TickCount - last_tick;
if (duration < delay) {
if (mForceDraw) {
Draw();
mForceDraw = false;
}
continue;
}
last_tick = Environment.TickCount;
mConfirmTime = Math.Max(0, mConfirmTime - (int)duration);
mFlashCounter = (mFlashCounter + 1) % 20;
Draw();
}
}
private void Draw()
{
ButtonBrightness[,] redgrid = new ButtonBrightness[8, 8];
ButtonBrightness[,] greengrid = new ButtonBrightness[8, 8];
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
if (mGrid[x, y] == 1) {
redgrid[x, y] = ButtonBrightness.Full;
} else if (mGrid[x, y] == 2) {
greengrid[x, y] = ButtonBrightness.Full;
} else if (mShowPossibleMoves && mFlashCounter < 10) {
if (mPossiblePlaces.Exists(p => p.Item1 == x && p.Item2 == y)) {
redgrid[x, y] = ButtonBrightness.Low;
greengrid[x, y] = ButtonBrightness.Low;
}
}
}
}
for (int y = 0; y < 8; y++)
for (int x = 0; x < 8; x++)
mLaunchpadDevice[x, y].SetBrightness(redgrid[x, y], greengrid[x, y]);
if (mPlayerTurn == 1) {
mLaunchpadDevice.GetButton(ToolbarButton.User1).SetBrightness(ButtonBrightness.Full, ButtonBrightness.Off);
mLaunchpadDevice.GetButton(ToolbarButton.User2).SetBrightness(ButtonBrightness.Off, ButtonBrightness.Off);
} else if (mPlayerTurn == 2) {
mLaunchpadDevice.GetButton(ToolbarButton.User1).SetBrightness(ButtonBrightness.Off, ButtonBrightness.Off);
mLaunchpadDevice.GetButton(ToolbarButton.User2).SetBrightness(ButtonBrightness.Off, ButtonBrightness.Full);
}
if (mPlayerWinning == 1) {
mLaunchpadDevice.GetButton(ToolbarButton.Mixer).SetBrightness(ButtonBrightness.Full, ButtonBrightness.Off);
} else if (mPlayerWinning == 2) {
mLaunchpadDevice.GetButton(ToolbarButton.Mixer).SetBrightness(ButtonBrightness.Off, ButtonBrightness.Full);
} else {
mLaunchpadDevice.GetButton(ToolbarButton.Mixer).SetBrightness(ButtonBrightness.Off, ButtonBrightness.Off);
}
if (mShowPossibleMoves)
mLaunchpadDevice.GetButton(SideButton.TrackOn).TurnOnLight();
else
mLaunchpadDevice.GetButton(SideButton.TrackOn).TurnOffLight();
if (mConfirmTime > 0)
mLaunchpadDevice.GetButton(ToolbarButton.Session).TurnOnLight();
else
mLaunchpadDevice.GetButton(ToolbarButton.Session).TurnOffLight();
if (mSolo)
mLaunchpadDevice.GetButton(SideButton.Solo).TurnOnLight();
else
mLaunchpadDevice.GetButton(SideButton.Solo).TurnOffLight();
}
}
}

@ -0,0 +1,177 @@
using IntelOrca.Launchpad;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace IntelOrca.LaunchpadTests
{
class ScrollingLetters
{
class CharacterDefinition
{
private char mKey;
private int mWidth;
private int mHeight;
private List<Point> mPoints = new List<Point>();
public CharacterDefinition(StringReader sr)
{
string key;
// Read key
while ((key = sr.ReadLine()).Length == 0);
mKey = key[0];
// Read characters
mHeight = 5;
for (int y = 0; y < mHeight; y++) {
string line = sr.ReadLine();
for (int x = 0; x < line.Length; x++)
if (line[x] == 'X')
mPoints.Add(new Point(x, y));
}
mWidth = mPoints.Max(p => p.X) + 1;
}
public override int GetHashCode()
{
return mKey.GetHashCode();
}
public char Key
{
get { return mKey; }
}
public int Width
{
get { return mWidth; }
set { mWidth = value; }
}
public int Height
{
get { return mHeight; }
set { mHeight = value; }
}
public Point[] Points
{
get { return mPoints.ToArray(); }
}
public struct Point
{
public Point(int x, int y) : this() { X = x; Y = y; }
public int X { get; set; }
public int Y { get; set; }
public override string ToString()
{
return String.Format("X = {0} Y = {1}", X, Y);
}
}
}
private static Dictionary<char, CharacterDefinition> mCharacterDefinitions = GetCharacterDefinitions();
private LaunchpadDevice mLaunchpadDevice;
private string mText = String.Empty;
private int mTextOffset = 8;
private bool[,] mGrid = new bool[8, 8];
private static Dictionary<char, CharacterDefinition> GetCharacterDefinitions()
{
var defs = new Dictionary<char, CharacterDefinition>();
StringReader sr = new StringReader(File.ReadAllText("text.txt"));
while (sr.Peek() != -1) {
if (Char.IsWhiteSpace((char)sr.Peek())) {
sr.Read();
continue;
}
CharacterDefinition cd = new CharacterDefinition(sr);
defs.Add(cd.Key, cd);
}
return defs;
}
public ScrollingLetters(LaunchpadDevice device)
{
mLaunchpadDevice = device;
}
private void SetGrid(int x, int y, bool value)
{
if (x >= 0 && y >= 0 && x < 8 && y < 8)
mGrid[x, y] = value;
}
private int RenderCharacter(char c, int x, int y)
{
if (mCharacterDefinitions.ContainsKey(c)) {
CharacterDefinition cd = mCharacterDefinitions[c];
if (x + cd.Width >= 0 && x < 8)
Array.ForEach(cd.Points, p => SetGrid(x + p.X, y + p.Y, true));
return cd.Width;
}
return 4;
}
private void RenderGrid()
{
int x, y;
for (y = 0; y < 8; y++)
for (x = 0; x < 8; x++)
mGrid[x, y] = false;
x = mTextOffset;
y = 1;
foreach (char c in mText) {
x += RenderCharacter(c, x, y) + 1;
}
for (y = 0; y < 8; y++) {
for (x = 0; x < 8; x++) {
if (mGrid[x, y])
mLaunchpadDevice[x, y].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
else
mLaunchpadDevice[x, y].SetBrightness(ButtonBrightness.Off, ButtonBrightness.Off);
}
}
mLaunchpadDevice.Refresh();
}
public void ScrollText()
{
long last_tick = 0;
long delay = 100;
while (true) {
if (Environment.TickCount - last_tick < delay)
continue;
last_tick = Environment.TickCount;
RenderGrid();
mTextOffset--;
if (mTextOffset < -(mText.Length * 5 + 2))
mTextOffset = 8;
}
}
public string Text
{
get { return mText; }
set { mText = value; }
}
}
}

@ -0,0 +1,233 @@
using IntelOrca.Launchpad;
using System;
using System.Collections.Generic;
using System.Linq;
namespace IntelOrca.LaunchpadTests
{
struct Point
{
public Point(int x, int y)
: this()
{
X = x;
Y = y;
}
public int X { get; set; }
public int Y { get; set; }
}
class Snake
{
private LaunchpadDevice mLaunchpadDevice;
private Random mRandom = new Random();
private long mCurrentTicks = 0;
private Point[] mBody;
private Point mDirection;
private bool mFoodActive;
private Point mFood;
private bool snakeFrozen = false;
private bool gameEnd = false;
public Snake(LaunchpadDevice device)
{
mLaunchpadDevice = device;
mLaunchpadDevice.ButtonPressed += mLaunchpadDevice_ButtonPressed;
mLaunchpadDevice.GetButton(SideButton.Arm).SetBrightness(ButtonBrightness.Full, ButtonBrightness.Off);
mLaunchpadDevice.GetButton(SideButton.Solo).SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
Restart();
}
private void mLaunchpadDevice_ButtonPressed(object sender, ButtonPressEventArgs e)
{
if (e.Type == ButtonType.Grid) {
mFood.X = e.X;
mFood.Y = e.Y;
mFoodActive = true;
}
if (e.Type == ButtonType.Side)
{
if(e.SidebarButton == SideButton.Solo)
{
if (snakeFrozen)
snakeFrozen = false;
else
snakeFrozen = true;
}
}
if (e.Type == ButtonType.Side)
{
if (e.SidebarButton == SideButton.Arm)
{
mLaunchpadDevice.Reset();
gameEnd = true;
}
}
}
public void Run()
{
// Kontrolle des internen Ticks (6*12 Frames werden pro "nächster" aktion verstreichen gelassen)
long last_tick = Environment.TickCount;
long delay = 12;
delay = 12 * 6;
// GameLoop
while (true && !gameEnd) {
if (Environment.TickCount - last_tick < delay)
continue;
mCurrentTicks += Environment.TickCount - last_tick;
last_tick = Environment.TickCount;
// Spielroutine (mit "Pause" Funktion [bei einem Snake Spiel natürlich quasi cheaten xD])
if(!snakeFrozen)
{
// Update aller Positionen
Update();
// Neu Zeichnen des Brettes
Draw();
}
}
}
private void Update()
{
SetSnakeDirection();
MoveSnake();
}
private void Draw()
{
ButtonBrightness[,] redgrid = new ButtonBrightness[8, 8];
ButtonBrightness[,] greengrid = new ButtonBrightness[8, 8];
// Draw snake
foreach (Point p in mBody)
if (InBounds(p))
greengrid[p.X, p.Y] = ButtonBrightness.Full;
if (InBounds(mBody[0]))
redgrid[mBody[0].X, mBody[0].Y] = ButtonBrightness.Full;
// Draw food
if (mFoodActive)
redgrid[mFood.X, mFood.Y] = ButtonBrightness.Full;
// Invalidate (Neu Zeichnen aller Kacheln anhand was in red/greengrid drin steht
for (int y = 0; y < 8; y++)
for (int x = 0; x < 8; x++)
mLaunchpadDevice[x, y].SetBrightness(redgrid[x, y], greengrid[x, y]);
// Refresh um neue Konstellation anzuzeigen
mLaunchpadDevice.Refresh();
}
private void Restart()
{
mBody = new Point[4];
for (int y = 8; y < 8 + 4; y++)
mBody[y - 8] = new Point(3, y);
mDirection = new Point(0, -1);
mFoodActive = false;
// PlaceFood();
}
private void MoveSnake()
{
// Nachrücken aller Steine nach vorne (Letzer wird entfernt)
for (int i = mBody.Length - 1; i > 0; i--)
mBody[i] = mBody[i - 1];
//Kopf wird in Richtung bewegt
mBody[0].X += mDirection.X;
mBody[0].Y += mDirection.Y;
// Wenn
for (int i = 1; i < mBody.Length; i++) {
if (mBody[0].X == mBody[i].X && mBody[0].Y == mBody[i].Y)
Restart();
}
if (mBody[0].X == mFood.X && mBody[0].Y == mFood.Y) {
mFoodActive = false;
ExtendSnake();
// PlaceFood();
}
}
public void SetSnakeDirection()
{
bool danger = false;
Point head = mBody[0];
if (head.X == 7 && mDirection.X > 0) {
if (head.Y < 7) mDirection = new Point(0, 1);
else mDirection = new Point(0, -1);
danger = true;
} else if (head.X == 0 && mDirection.X < 0) {
if (head.Y < 7) mDirection = new Point(0, 1);
else mDirection = new Point(0, -1);
danger = true;
}
if (head.Y == 7 && mDirection.Y > 0) {
if (head.X < 7) mDirection = new Point(1, 0);
else mDirection = new Point(-1, 0);
danger = true;
} else if (head.Y == 0 && mDirection.Y < 0) {
if (head.X < 7) mDirection = new Point(1, 0);
else mDirection = new Point(-1, 0);
danger = true;
}
if (!danger && mFoodActive) {
if (mDirection.X != 0) {
if (mBody[0].X == mFood.X) {
if (mBody[0].Y < mFood.Y) mDirection = new Point(0, 1);
else mDirection = new Point(0, -1);
}
} else {
if (mBody[0].Y == mFood.Y) {
if (mBody[0].X < mFood.X) mDirection = new Point(1, 0);
else mDirection = new Point(-1, 0);
}
}
}
}
private void ExtendSnake()
{
Point[] newBody = new Point[mBody.Length + 1];
newBody[0] = mBody[0];
Array.Copy(mBody, 0, newBody, 1, mBody.Length);
mBody = newBody;
}
private void PlaceFood()
{
List<Point> possiblePlaces = new List<Point>();
for (int y = 0; y < 8; y++)
for (int x = 0; x < 8; x++)
if (!mBody.Contains(new Point(x, y)))
possiblePlaces.Add(new Point(x, y));
int index = mRandom.Next(possiblePlaces.Count);
mFood = possiblePlaces[index];
}
private bool InBounds(Point p)
{
return (p.X >= 0 && p.Y >= 0 && p.X < 8 && p.Y < 8);
}
}
}

@ -0,0 +1,60 @@
using IntelOrca.Launchpad;
namespace IntelOrca.LaunchpadTests
{
class ToggleGrid
{
private LaunchpadDevice mLaunchpadDevice;
public ToggleGrid(LaunchpadDevice device)
{
mLaunchpadDevice = device;
mLaunchpadDevice.DoubleBuffered = false;
mLaunchpadDevice.ButtonPressed += mLaunchpadDevice_ButtonPressed;
mLaunchpadDevice.GetButton(ToolbarButton.Session).SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
for (int y = 0; y < 4; y++) {
for (int x = 0; x < 4; x++) {
mLaunchpadDevice[x, y].SetBrightness((ButtonBrightness)x, (ButtonBrightness)y);
}
}
}
private void mLaunchpadDevice_ButtonPressed(object sender, ButtonPressEventArgs e)
{
if (e.Type == ButtonType.Grid) {
LaunchpadButton button = mLaunchpadDevice[e.X, e.Y];
if (button.RedBrightness == ButtonBrightness.Off && button.GreenBrightness == ButtonBrightness.Off)
button.SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
else
button.SetBrightness(ButtonBrightness.Off, ButtonBrightness.Off);
/*
if (button.RedBrightness == ButtonBrightness.Off && button.GreenBrightness == ButtonBrightness.Off)
button.SetBrightness(ButtonBrightness.Full, ButtonBrightness.Off);
else if (button.RedBrightness == ButtonBrightness.Full && button.GreenBrightness == ButtonBrightness.Off)
button.SetBrightness(ButtonBrightness.Off, ButtonBrightness.Full);
else if (button.RedBrightness == ButtonBrightness.Off && button.GreenBrightness == ButtonBrightness.Full)
button.SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
else
button.SetBrightness(ButtonBrightness.Off, ButtonBrightness.Off);
*/
} else if (e.Type == ButtonType.Toolbar) {
if (e.ToolbarButton == ToolbarButton.Session) {
for (int y = 0; y < 8; y++)
for (int x = 0; x < 8; x++)
mLaunchpadDevice[x, y].TurnOffLight();
}
}
}
public void Run()
{
while (true) ;
}
}
}

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="midi-dot-net" version="1.1.0" targetFramework="net45" />
</packages>

@ -0,0 +1,293 @@
!
X
X
X
X
"
X X
X X
#
X X
XXXXX
X X
XXXXX
X X
'
X
X
,
X
X
.
X
0
XX
X X
X X
X X
XX
1
X
X
X
X
X
2
XXX
X
X
X
XXXX
3
XXX
X
XX
X
XXX
4
X
XX
X X
XXXXX
X
5
XXXX
X
XXX
X
XXX
6
XX
X
XXX
X X
XX
7
XXXX
X
X
X
X
8
XXXX
X X
XXXX
X X
XXXX
9
XX
X X
XXX
X
XX
A
XXXX
X X
XXXX
X X
X X
B
XXX
X X
XXXX
X X
XXX
C
XXX
X
X
X
XXX
D
XXX
X X
X X
X X
XXX
E
XXXX
X
XXX
X
XXXX
F
XXXX
X
XXX
X
X
G
XXX
X
X XX
X X
XXX
H
X X
X X
XXXX
X X
X X
I
X
X
X
X
X
J
XXXX
X
X
X
XXX
K
X X
X X
XX
X X
X X
L
X
X
X
X
XXXX
M
X X
XX XX
X X X
X X
X X
N
X X
XX X
X X X
X XX
X X
O
XXX
X X
X X
X X
XXX
P
XXX
X X
XXX
X
X
Q
XX
X X
X X
XX
XX
R
XXX
X X
XXX
X X
X X
S
XXX
X
XX
X
XXX
T
XXXXX
X
X
X
X
U
X X
X X
X X
X X
XXX
V
X X
X X
X X
X X
X
W
X X
X X
X X
X X X
X X
X
X X
X X
X
X X
X X
Y
X X
X X
X
X
X
Z
XXXXX
X
X
X
XXXXX

@ -0,0 +1,8 @@
IntelOrca.Launchpad
=====================
A .NET framework library written in C# for utilising the Novation Launchpad
using MidiDotNet. Also includes various cool demos such as the rain sequencer.
Demonstration
-----------------------
http://www.youtube.com/watch?v=leYmmiVL1nU
Loading…
Cancel
Save