Build 121209
46
DrumKit.sln
Normal file
@ -0,0 +1,46 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrumKit", "DrumKit\DrumKit.csproj", "{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|ARM = Debug|ARM
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|ARM = Release|ARM
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Debug|ARM.ActiveCfg = Debug|ARM
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Debug|ARM.Build.0 = Debug|ARM
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Debug|ARM.Deploy.0 = Debug|ARM
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Debug|x64.Build.0 = Debug|x64
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Debug|x64.Deploy.0 = Debug|x64
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Debug|x86.Build.0 = Debug|x86
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Debug|x86.Deploy.0 = Debug|x86
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Release|Any CPU.Deploy.0 = Release|Any CPU
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Release|ARM.ActiveCfg = Release|ARM
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Release|ARM.Build.0 = Release|ARM
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Release|ARM.Deploy.0 = Release|ARM
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Release|x64.ActiveCfg = Release|x64
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Release|x64.Build.0 = Release|x64
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Release|x64.Deploy.0 = Release|x64
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Release|x86.ActiveCfg = Release|x86
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Release|x86.Build.0 = Release|x86
|
||||
{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}.Release|x86.Deploy.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
BIN
DrumKit.v11.suo
Normal file
20
DrumKit/App.xaml
Normal file
@ -0,0 +1,20 @@
|
||||
<Application
|
||||
x:Class="DrumKit.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:DrumKit">
|
||||
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<!--
|
||||
Styles that define common aspects of the platform look and feel
|
||||
Required by Visual Studio project and item templates
|
||||
-->
|
||||
<ResourceDictionary Source="Common/StandardStyles.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
</Application>
|
90
DrumKit/App.xaml.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.ApplicationModel.Activation;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls.Primitives;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
|
||||
// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227
|
||||
|
||||
namespace DrumKit
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides application-specific behavior to supplement the default Application class.
|
||||
/// </summary>
|
||||
sealed partial class App : Application
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the singleton application object. This is the first line of authored code
|
||||
/// executed, and as such is the logical equivalent of main() or WinMain().
|
||||
/// </summary>
|
||||
public App()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.Suspending += OnSuspending;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the application is launched normally by the end user. Other entry points
|
||||
/// will be used when the application is launched to open a specific file, to display
|
||||
/// search results, and so forth.
|
||||
/// </summary>
|
||||
/// <param name="args">Details about the launch request and process.</param>
|
||||
protected override void OnLaunched(LaunchActivatedEventArgs args)
|
||||
{
|
||||
Frame rootFrame = Window.Current.Content as Frame;
|
||||
|
||||
// Do not repeat app initialization when the Window already has content,
|
||||
// just ensure that the window is active
|
||||
if (rootFrame == null)
|
||||
{
|
||||
// Create a Frame to act as the navigation context and navigate to the first page
|
||||
rootFrame = new Frame();
|
||||
|
||||
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
|
||||
{
|
||||
//TODO: Load state from previously suspended application
|
||||
}
|
||||
|
||||
// Place the frame in the current Window
|
||||
Window.Current.Content = rootFrame;
|
||||
}
|
||||
|
||||
if (rootFrame.Content == null)
|
||||
{
|
||||
// When the navigation stack isn't restored navigate to the first page,
|
||||
// configuring the new page by passing required information as a navigation
|
||||
// parameter
|
||||
if (!rootFrame.Navigate(typeof(MainPage), args.Arguments))
|
||||
{
|
||||
throw new Exception("Failed to create initial page");
|
||||
}
|
||||
}
|
||||
// Ensure the current window is active
|
||||
Window.Current.Activate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when application execution is being suspended. Application state is saved
|
||||
/// without knowing whether the application will be terminated or resumed with the contents
|
||||
/// of memory still intact.
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the suspend request.</param>
|
||||
/// <param name="e">Details about the suspend request.</param>
|
||||
private void OnSuspending(object sender, SuspendingEventArgs e)
|
||||
{
|
||||
var deferral = e.SuspendingOperation.GetDeferral();
|
||||
//TODO: Save application state and stop any background activity
|
||||
deferral.Complete();
|
||||
}
|
||||
}
|
||||
}
|
BIN
DrumKit/Assets/Drums/big_drum_of.png
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
DrumKit/Assets/Drums/big_drum_on.png
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
DrumKit/Assets/Drums/drum_of.png
Normal file
After Width: | Height: | Size: 230 KiB |
BIN
DrumKit/Assets/Drums/drum_on.png
Normal file
After Width: | Height: | Size: 228 KiB |
BIN
DrumKit/Assets/Drums/plate_off.png
Normal file
After Width: | Height: | Size: 515 KiB |
BIN
DrumKit/Assets/Drums/plate_on.png
Normal file
After Width: | Height: | Size: 372 KiB |
BIN
DrumKit/Assets/Logos/Logo.png
Normal file
After Width: | Height: | Size: 801 B |
BIN
DrumKit/Assets/Logos/SmallLogo.png
Normal file
After Width: | Height: | Size: 329 B |
BIN
DrumKit/Assets/Logos/SplashScreen.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
DrumKit/Assets/Logos/StoreLogo.png
Normal file
After Width: | Height: | Size: 429 B |
BIN
DrumKit/Assets/Sounds/Crash05.wav
Normal file
BIN
DrumKit/Assets/Sounds/Floor04.wav
Normal file
BIN
DrumKit/Assets/Sounds/Hat04.WAV
Normal file
BIN
DrumKit/Assets/Sounds/HiHatOpen04.wav
Normal file
BIN
DrumKit/Assets/Sounds/Kick07.wav
Normal file
BIN
DrumKit/Assets/Sounds/Ride04.wav
Normal file
BIN
DrumKit/Assets/Sounds/Snare08.wav
Normal file
BIN
DrumKit/Assets/Sounds/TomHigh04.wav
Normal file
BIN
DrumKit/Assets/Sounds/TomLow04.wav
Normal file
BIN
DrumKit/Assets/bg.png
Normal file
After Width: | Height: | Size: 838 KiB |
40
DrumKit/Assets/default
Normal file
@ -0,0 +1,40 @@
|
||||
[Kick]
|
||||
position=.41,.2
|
||||
size=.3
|
||||
image=ms-appx:///Assets/Drums/big_drum_of.png
|
||||
sound,0=ms-appx:///Assets/Sounds/Kick07.wav
|
||||
[Snare]
|
||||
position=.16,.34
|
||||
size=.25
|
||||
image=ms-appx:///Assets/Drums/drum_of.png
|
||||
sound,0=ms-appx:///Assets/Sounds/Snare08.wav
|
||||
[High Tom]
|
||||
position=.33,.05
|
||||
size=.22
|
||||
image=ms-appx:///Assets/Drums/drum_of.png
|
||||
sound,0=ms-appx:///Assets/Sounds/TomHigh04.wav
|
||||
[Low Tom]
|
||||
position=.55,.05
|
||||
size=.22
|
||||
image=ms-appx:///Assets/Drums/drum_of.png
|
||||
sound,0=ms-appx:///Assets/Sounds/TomLow04.wav
|
||||
[Floor Tom]
|
||||
position=.66,.44
|
||||
size=.29
|
||||
image=ms-appx:///Assets/Drums/drum_of.png
|
||||
sound,0=ms-appx:///Assets/Sounds/Floor04.wav
|
||||
[HiHat]
|
||||
position=.03,.55
|
||||
size=.21
|
||||
image=ms-appx:///Assets/Drums/plate_off.png
|
||||
sound,0=ms-appx:///Assets/Sounds/HiHatOpen04.wav
|
||||
[Crash]
|
||||
position=.1,.02
|
||||
size=.25
|
||||
image=ms-appx:///Assets/Drums/plate_off.png
|
||||
sound,0=ms-appx:///Assets/Sounds/Crash05.wav
|
||||
[Ride]
|
||||
position=.72,.04
|
||||
size=.25
|
||||
image=ms-appx:///Assets/Drums/plate_off.png
|
||||
sound,0=ms-appx:///Assets/Sounds/Ride04.wav
|
1833
DrumKit/Common/StandardStyles.xaml
Normal file
107
DrumKit/Drum.cs
Normal file
@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls.Primitives;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
|
||||
namespace DrumKit
|
||||
{
|
||||
class Drum
|
||||
{
|
||||
#region Attributes
|
||||
private Uri imageSource;
|
||||
private Point position;
|
||||
private double size;
|
||||
#endregion
|
||||
|
||||
#region Public properties
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the drum.
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the image uri. If enabled, the image is loaded.
|
||||
/// </summary>
|
||||
public Uri ImageSource {
|
||||
get { return this.imageSource; }
|
||||
set { this.SetImageSource(value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the position of the element on the screen.
|
||||
/// </summary>
|
||||
public Point Position {
|
||||
get { return this.position; }
|
||||
set { this.SetPosition(value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of the image displayed on the screen.
|
||||
/// </summary>
|
||||
public double Size {
|
||||
get { return this.size; }
|
||||
set { this.size = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sound sources
|
||||
/// </summary>
|
||||
public Dictionary<int, Uri> SoundSources
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public Drum()
|
||||
{
|
||||
// Initialize sources
|
||||
this.SoundSources = new Dictionary<int, Uri>();
|
||||
this.imageSource = null;
|
||||
|
||||
// Set up other vars
|
||||
this.position = new Point(0, 0);
|
||||
this.size = 0;
|
||||
this.Name = "<unnamed>";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Setters
|
||||
public void SetImageSource(Uri imagesrc)
|
||||
{
|
||||
// Set property
|
||||
this.imageSource = imagesrc;
|
||||
}
|
||||
|
||||
public void SetPosition(Point location)
|
||||
{
|
||||
// Set property
|
||||
this.position = location;
|
||||
}
|
||||
|
||||
public void SetSoundSource(int intensity, Uri source)
|
||||
{
|
||||
// Set up sound source
|
||||
if (this.SoundSources.ContainsKey(intensity))
|
||||
this.SoundSources[intensity] = source;
|
||||
|
||||
else this.SoundSources.Add(intensity, source);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
181
DrumKit/DrumKit.csproj
Normal file
@ -0,0 +1,181 @@
|
||||
<?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>{9A5D3F55-DFD5-45DB-99FF-C82EFCC3294D}</ProjectGuid>
|
||||
<OutputType>AppContainerExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>DrumKit</RootNamespace>
|
||||
<AssemblyName>DrumKit</AssemblyName>
|
||||
<DefaultLanguage>en-US</DefaultLanguage>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<PackageCertificateKeyFile>DrumKit_TemporaryKey.pfx</PackageCertificateKeyFile>
|
||||
</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;NETFX_CORE</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;NETFX_CORE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\ARM\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>ARM</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
|
||||
<OutputPath>bin\ARM\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>ARM</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Drum.cs" />
|
||||
<Compile Include="MainPage.xaml.cs">
|
||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Recorder.cs" />
|
||||
<Compile Include="Repository\DrumRepository.cs" />
|
||||
<Compile Include="SoundPlayer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SoundPool.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AppxManifest Include="Package.appxmanifest">
|
||||
<SubType>Designer</SubType>
|
||||
</AppxManifest>
|
||||
<None Include="DrumKit_TemporaryKey.pfx" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Assets\bg.png" />
|
||||
<Content Include="Assets\Drums\big_drum_of.png" />
|
||||
<Content Include="Assets\Drums\big_drum_on.png" />
|
||||
<Content Include="Assets\Drums\drum_of.png" />
|
||||
<Content Include="Assets\Drums\drum_on.png" />
|
||||
<Content Include="Assets\Sounds\Crash05.wav" />
|
||||
<Content Include="Assets\Sounds\Hat04.WAV" />
|
||||
<Content Include="Assets\Sounds\HiHatOpen04.wav" />
|
||||
<Content Include="Assets\Sounds\Kick07.wav" />
|
||||
<Content Include="Assets\default">
|
||||
<SubType>Designer</SubType>
|
||||
</Content>
|
||||
<Content Include="Assets\Logos\Logo.png" />
|
||||
<Content Include="Assets\Logos\SmallLogo.png" />
|
||||
<Content Include="Assets\Logos\SplashScreen.png" />
|
||||
<Content Include="Assets\Logos\StoreLogo.png" />
|
||||
<Content Include="Assets\Drums\plate_off.png" />
|
||||
<Content Include="Assets\Drums\plate_on.png" />
|
||||
<Content Include="Assets\Sounds\Ride04.wav" />
|
||||
<Content Include="Assets\Sounds\Snare08.wav" />
|
||||
<Content Include="Assets\Sounds\TomHigh04.wav" />
|
||||
<Content Include="Assets\Sounds\Floor04.wav" />
|
||||
<Content Include="Assets\Sounds\TomLow04.wav" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="App.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Page Include="Common\StandardStyles.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="MainPage.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="SharpDX">
|
||||
<HintPath>C:\Users\Tiberiu\Downloads\SharpDX\Bin\Standard-winrt\SharpDX.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SharpDX.XAudio2">
|
||||
<HintPath>C:\Users\Tiberiu\Downloads\SharpDX\Bin\Standard-winrt\SharpDX.XAudio2.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '11.0' ">
|
||||
<VisualStudioVersion>11.0</VisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.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>
|
6
DrumKit/DrumKit.csproj.user
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||
<UseSimulator>False</UseSimulator>
|
||||
</PropertyGroup>
|
||||
</Project>
|
BIN
DrumKit/DrumKit_TemporaryKey.pfx
Normal file
73
DrumKit/MainPage.xaml
Normal file
@ -0,0 +1,73 @@
|
||||
<Page
|
||||
x:Class="DrumKit.MainPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:DrumKit"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid
|
||||
Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
|
||||
|
||||
<Image Source="ms-appx:///Assets/bg.png"
|
||||
Stretch="UniformToFill"/>
|
||||
|
||||
<Canvas
|
||||
Name="myCanvas" >
|
||||
|
||||
</Canvas>
|
||||
|
||||
<Grid>
|
||||
<Border Margin="7"
|
||||
CornerRadius="10"
|
||||
BorderBrush="Red"
|
||||
BorderThickness="5" />
|
||||
|
||||
<Canvas Name="recCanvas">
|
||||
<Ellipse Width="18" Height="18" Fill="Red"
|
||||
Canvas.Left="20"
|
||||
Canvas.Top="20"/>
|
||||
<TextBlock
|
||||
FontFamily="Consolas"
|
||||
FontSize="16"
|
||||
Foreground="Red"
|
||||
Canvas.Left="42"
|
||||
Canvas.Top="19">REC
|
||||
</TextBlock>
|
||||
|
||||
<Canvas.Triggers>
|
||||
<EventTrigger RoutedEvent="Canvas.Loaded">
|
||||
<BeginStoryboard>
|
||||
<Storyboard RepeatBehavior="Forever" >
|
||||
<DoubleAnimation
|
||||
Storyboard.TargetName="recCanvas"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
Duration="0:0:1" BeginTime="0:0:1" From="1" To="0.1" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</EventTrigger>
|
||||
</Canvas.Triggers>
|
||||
</Canvas>
|
||||
<!--<StackPanel Orientation="Horizontal"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top">
|
||||
<Button>Record</Button>
|
||||
<Button>Stop</Button>
|
||||
</StackPanel>-->
|
||||
</Grid>
|
||||
|
||||
</Grid>
|
||||
|
||||
|
||||
<Page.BottomAppBar>
|
||||
<AppBar>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<ToggleButton
|
||||
Name="buttonEditMode"
|
||||
Click="buttonEditMode_Click_1"
|
||||
Style="{StaticResource EditAppBarButtonStyle}" />
|
||||
</StackPanel>
|
||||
</AppBar>
|
||||
</Page.BottomAppBar>
|
||||
</Page>
|
201
DrumKit/MainPage.xaml.cs
Normal file
@ -0,0 +1,201 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls.Primitives;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
|
||||
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
||||
|
||||
namespace DrumKit
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty page that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
public sealed partial class MainPage : Page
|
||||
{
|
||||
DrumRepository drumRepo;
|
||||
SoundPlayer player = new SoundPlayer();
|
||||
List<Image> uiImages;
|
||||
List<Button> uiButtons;
|
||||
List<Thumb> uiThumbs;
|
||||
|
||||
public MainPage()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
|
||||
drumRepo = new DrumRepository();
|
||||
|
||||
uiImages = new List<Image>();
|
||||
uiButtons = new List<Button>();
|
||||
uiThumbs = new List<Thumb>();
|
||||
|
||||
this.InitializeResources();
|
||||
this.KeyDown += MainPage_KeyDown;
|
||||
}
|
||||
|
||||
void MainPage_KeyDown(object sender, KeyRoutedEventArgs e)
|
||||
{
|
||||
string key = Enum.GetName(typeof(Windows.System.VirtualKey), e.Key);
|
||||
|
||||
if (key != null && key.Length == 1)
|
||||
{
|
||||
int index = Convert.ToInt32(key.ToLower()[0] - 'a');
|
||||
if (this.uiButtons.Count > index)
|
||||
this.DrumClicked(this.uiButtons[index], new RoutedEventArgs());
|
||||
}
|
||||
}
|
||||
|
||||
Image CreateImage(int index, Drum drum)
|
||||
{
|
||||
var img = new Image();
|
||||
var bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage(drum.ImageSource);
|
||||
img.Tag = index.ToString();
|
||||
img.Source = bitmap;
|
||||
img.Width = drum.Size * this.ActualWidth;
|
||||
img.Height = drum.Size * this.ActualWidth;
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
Button CreateButton(int index, Drum drum)
|
||||
{
|
||||
var button = new Button();
|
||||
button.Tag = index.ToString();
|
||||
button.Click += DrumClicked;
|
||||
button.Width = drum.Size * this.ActualWidth;
|
||||
button.Height = drum.Size * this.ActualWidth;
|
||||
button.Background = new SolidColorBrush(Windows.UI.Colors.Orange);
|
||||
button.Opacity = 0;
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
Thumb CreateThumb(int index, Drum drum)
|
||||
{
|
||||
var thumb = new Thumb();
|
||||
thumb.Tag = index.ToString();
|
||||
thumb.DragDelta += DrumMoved;
|
||||
thumb.Width = drum.Size * this.ActualWidth;
|
||||
thumb.Height = drum.Size * this.ActualWidth;
|
||||
thumb.Opacity = .3;
|
||||
thumb.Background = new SolidColorBrush(Windows.UI.Colors.Green);
|
||||
thumb.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
|
||||
|
||||
return thumb;
|
||||
}
|
||||
|
||||
|
||||
async void InitializeResources()
|
||||
{
|
||||
await drumRepo.LoadFile(new Uri("ms-appx:///Assets/default"));
|
||||
|
||||
for (int i = 0; i < drumRepo.Drums.Count; i++)
|
||||
{
|
||||
var drum = drumRepo.Drums[i];
|
||||
|
||||
// Get ui objects
|
||||
var img = CreateImage(i, drum);
|
||||
var button = CreateButton(i, drum);
|
||||
var thumb = CreateThumb(i, drum);
|
||||
|
||||
// Set up layout
|
||||
this.myCanvas.Children.Add(img);
|
||||
this.myCanvas.Children.Add(button);
|
||||
this.myCanvas.Children.Add(thumb);
|
||||
|
||||
Canvas.SetLeft(img, drum.Position.X * this.ActualWidth);
|
||||
Canvas.SetLeft(button, drum.Position.X * this.ActualWidth);
|
||||
Canvas.SetLeft(thumb, drum.Position.X * this.ActualWidth);
|
||||
Canvas.SetTop(img, drum.Position.Y * this.ActualHeight);
|
||||
Canvas.SetTop(button, drum.Position.Y * this.ActualHeight);
|
||||
Canvas.SetTop(thumb, drum.Position.Y * this.ActualHeight);
|
||||
Canvas.SetZIndex(img, 0);
|
||||
Canvas.SetZIndex(button, 1);
|
||||
Canvas.SetZIndex(thumb, 2);
|
||||
|
||||
// Add to our list
|
||||
this.uiImages.Add(img);
|
||||
this.uiButtons.Add(button);
|
||||
this.uiThumbs.Add(thumb);
|
||||
}
|
||||
|
||||
// Add drums
|
||||
this.player.AddDrums(this.drumRepo.Drums);
|
||||
}
|
||||
|
||||
void DrumClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var button = sender as Button;
|
||||
if (button == null) return;
|
||||
|
||||
var tag = button.Tag as string;
|
||||
if (tag == null) return;
|
||||
|
||||
int index = int.Parse(tag);
|
||||
this.player.Play(this.drumRepo.Drums[index].Name + "0");
|
||||
}
|
||||
|
||||
void DrumMoved(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
var thumb = sender as Thumb;
|
||||
if (thumb == null) return;
|
||||
|
||||
var tag = thumb.Tag as string;
|
||||
if (tag == null) return;
|
||||
|
||||
int index = int.Parse(tag);
|
||||
Canvas.SetLeft(uiImages[index], Canvas.GetLeft(uiImages[index]) + e.HorizontalChange);
|
||||
Canvas.SetLeft(uiButtons[index], Canvas.GetLeft(uiButtons[index]) + e.HorizontalChange);
|
||||
Canvas.SetLeft(uiThumbs[index], Canvas.GetLeft(uiThumbs[index]) + e.HorizontalChange);
|
||||
Canvas.SetTop(uiImages[index], Canvas.GetTop(uiImages[index]) + e.VerticalChange);
|
||||
Canvas.SetTop(uiButtons[index], Canvas.GetTop(uiButtons[index]) + e.VerticalChange);
|
||||
Canvas.SetTop(uiThumbs[index], Canvas.GetTop(uiThumbs[index]) + e.VerticalChange);
|
||||
drumRepo.Drums[index].Position = new Point(drumRepo.Drums[index].Position.X + e.HorizontalChange, drumRepo.Drums[index].Position.Y + e.VerticalChange);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when this page is about to be displayed in a Frame.
|
||||
/// </summary>
|
||||
/// <param name="e">Event data that describes how this page was reached. The Parameter
|
||||
/// property is typically used to configure the page.</param>
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
private async void mybutton_Click_1(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var picker = new Windows.Storage.Pickers.FileOpenPicker();
|
||||
picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.MusicLibrary;
|
||||
picker.FileTypeFilter.Add("*");
|
||||
var file = await picker.PickSingleFileAsync();
|
||||
|
||||
//blabla.Source = new Uri(file.Path);
|
||||
//blabla.Play();
|
||||
}
|
||||
|
||||
private void buttonEditMode_Click_1(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var button = sender as ToggleButton;
|
||||
if (button == null) return;
|
||||
|
||||
// Fix togglebuton style bug
|
||||
VisualStateManager.GoToState(button, button.IsChecked.Value ? "Checked" : "Unchecked", false);
|
||||
|
||||
// Change visibility of thumbs
|
||||
bool visible = (buttonEditMode.IsChecked.HasValue && buttonEditMode.IsChecked.Value);
|
||||
|
||||
foreach (var i in this.uiThumbs)
|
||||
if (visible) i.Visibility = Windows.UI.Xaml.Visibility.Visible;
|
||||
else i.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
35
DrumKit/Package.appxmanifest
Normal file
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest">
|
||||
<Identity Name="9e797bd6-ff19-4416-8ec8-f371d6d86244" Publisher="CN=Tiberiu" Version="1.0.0.0" />
|
||||
<Properties>
|
||||
<DisplayName>DrumKit</DisplayName>
|
||||
<PublisherDisplayName>Tiberiu</PublisherDisplayName>
|
||||
<Logo>Assets\StoreLogo.png</Logo>
|
||||
</Properties>
|
||||
<Prerequisites>
|
||||
<OSMinVersion>6.2.1</OSMinVersion>
|
||||
<OSMaxVersionTested>6.2.1</OSMaxVersionTested>
|
||||
</Prerequisites>
|
||||
<Resources>
|
||||
<Resource Language="x-generate" />
|
||||
</Resources>
|
||||
<Applications>
|
||||
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="DrumKit.App">
|
||||
<VisualElements DisplayName="DrumKit" Logo="Assets\Logos\Logo.png" SmallLogo="Assets\Logos\SmallLogo.png" Description="DrumKit" ForegroundText="light" BackgroundColor="#464646">
|
||||
<DefaultTile ShowName="allLogos" />
|
||||
<SplashScreen Image="Assets\Logos\SplashScreen.png" />
|
||||
<InitialRotationPreference>
|
||||
<Rotation Preference="landscape" />
|
||||
<Rotation Preference="landscapeFlipped" />
|
||||
</InitialRotationPreference>
|
||||
</VisualElements>
|
||||
<Extensions>
|
||||
<Extension Category="windows.backgroundTasks" EntryPoint="DrumKit">
|
||||
<BackgroundTasks>
|
||||
<Task Type="audio" />
|
||||
</BackgroundTasks>
|
||||
</Extension>
|
||||
</Extensions>
|
||||
</Application>
|
||||
</Applications>
|
||||
</Package>
|
29
DrumKit/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,29 @@
|
||||
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("DrumKit")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("DrumKit")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2012")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 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")]
|
||||
[assembly: ComVisible(false)]
|
55
DrumKit/Recorder.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DrumKit
|
||||
{
|
||||
class Recorder
|
||||
{
|
||||
private SortedDictionary<double, Uri> hits;
|
||||
private DateTime begin;
|
||||
|
||||
public bool IsRecording { get; private set; }
|
||||
|
||||
public Recorder()
|
||||
{
|
||||
this.IsRecording = false;
|
||||
this.begin = new DateTime();
|
||||
this.hits = new SortedDictionary<double, Uri>();
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
this.IsRecording = true;
|
||||
begin = DateTime.Now;
|
||||
}
|
||||
|
||||
public void Add(Uri uri)
|
||||
{
|
||||
if (!IsRecording)
|
||||
return;
|
||||
|
||||
var time = DateTime.Now - this.begin;
|
||||
this.hits.Add(time.TotalMilliseconds, uri);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
this.IsRecording = false;
|
||||
}
|
||||
|
||||
public void Play()
|
||||
{
|
||||
SoundPlayer player = new SoundPlayer();
|
||||
|
||||
var sounduris = this.hits.Values.Distinct();
|
||||
foreach (var i in sounduris)
|
||||
player.AddWave(i.AbsolutePath, i.AbsolutePath);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
76
DrumKit/Repository/DrumRepository.cs
Normal file
@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
|
||||
namespace DrumKit
|
||||
{
|
||||
class DrumRepository
|
||||
{
|
||||
public List<Drum> Drums { get; private set; }
|
||||
|
||||
public DrumRepository()
|
||||
{
|
||||
this.Drums = new List<Drum>();
|
||||
}
|
||||
|
||||
public async Task LoadFile(Uri path)
|
||||
{
|
||||
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(path);
|
||||
IList<string> lines = await FileIO.ReadLinesAsync(file);
|
||||
|
||||
Drum drum = null;
|
||||
double x, y;
|
||||
|
||||
foreach (var i in lines)
|
||||
{
|
||||
var clean = i.Trim(' ', '\t', '\r', '\n');
|
||||
|
||||
// New drum
|
||||
if (clean[0] == '[')
|
||||
{
|
||||
if (drum != null)
|
||||
this.Drums.Add(drum);
|
||||
|
||||
drum = new Drum();
|
||||
drum.Name = clean.Substring(1, clean.Length - 2);
|
||||
}
|
||||
|
||||
// Attribute
|
||||
else if (drum != null)
|
||||
{
|
||||
var split = clean.Split(new char[] { '=', ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
switch (split[0])
|
||||
{
|
||||
case "position":
|
||||
x = double.Parse(split[1]);
|
||||
y = double.Parse(split[2]);
|
||||
drum.Position = new Windows.Foundation.Point(x, y);
|
||||
break;
|
||||
|
||||
case "size":
|
||||
x = double.Parse(split[1]);
|
||||
drum.Size = x;
|
||||
break;
|
||||
|
||||
case "image":
|
||||
drum.ImageSource = new Uri(split[1]);
|
||||
break;
|
||||
|
||||
case "sound":
|
||||
if (split.Length == 2)
|
||||
drum.SetSoundSource(0, new Uri(split[1]));
|
||||
else drum.SetSoundSource(int.Parse(split[1]), new Uri(split[2]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (drum != null)
|
||||
this.Drums.Add(drum);
|
||||
}
|
||||
}
|
||||
}
|
72
DrumKit/SoundPlayer.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SharpDX;
|
||||
using SharpDX.XAudio2;
|
||||
using SharpDX.IO;
|
||||
using SharpDX.Multimedia;
|
||||
|
||||
namespace DrumKit
|
||||
{
|
||||
class SoundPlayer
|
||||
{
|
||||
private XAudio2 xaudio;
|
||||
private MasteringVoice mvoice;
|
||||
Dictionary<string, MyWave> sounds;
|
||||
SoundPool pool;
|
||||
|
||||
public SoundPlayer()
|
||||
{
|
||||
xaudio = new XAudio2();
|
||||
xaudio.StartEngine();
|
||||
mvoice = new MasteringVoice(xaudio);
|
||||
sounds = new Dictionary<string, MyWave>();
|
||||
}
|
||||
|
||||
public void AddWave(string key, string filepath)
|
||||
{
|
||||
MyWave wave = new MyWave();
|
||||
|
||||
var nativeFileStream = new NativeFileStream(filepath, NativeFileMode.Open, NativeFileAccess.Read, NativeFileShare.Read);
|
||||
var soundStream = new SoundStream(nativeFileStream);
|
||||
var buffer = new AudioBuffer() { Stream = soundStream, AudioBytes = (int)soundStream.Length, Flags = BufferFlags.EndOfStream };
|
||||
|
||||
wave.Buffer = buffer;
|
||||
wave.DecodedPacketsInfo = soundStream.DecodedPacketsInfo;
|
||||
wave.WaveFormat = soundStream.Format;
|
||||
|
||||
this.sounds.Add(key, wave);
|
||||
}
|
||||
|
||||
public void AddDrums(IEnumerable<Drum> drums)
|
||||
{
|
||||
foreach (var d in drums)
|
||||
foreach (var s in d.SoundSources)
|
||||
{
|
||||
string key = d.Name + s.Key.ToString();
|
||||
string path = s.Value.AbsolutePath.TrimStart('\\', '/');
|
||||
this.AddWave(key, path);
|
||||
}
|
||||
}
|
||||
|
||||
public void Play(string key)
|
||||
{
|
||||
if (!this.sounds.ContainsKey(key)) return;
|
||||
MyWave w = this.sounds[key];
|
||||
|
||||
if (pool == null)
|
||||
pool = new SoundPool(xaudio, w.WaveFormat);
|
||||
|
||||
pool.PlayBuffer(w.Buffer, w.DecodedPacketsInfo);
|
||||
}
|
||||
}
|
||||
|
||||
class MyWave
|
||||
{
|
||||
public AudioBuffer Buffer { get; set; }
|
||||
public uint[] DecodedPacketsInfo { get; set; }
|
||||
public WaveFormat WaveFormat { get; set; }
|
||||
}
|
||||
}
|
41
DrumKit/SoundPool.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SharpDX;
|
||||
using SharpDX.XAudio2;
|
||||
using SharpDX.Multimedia;
|
||||
|
||||
namespace DrumKit
|
||||
{
|
||||
class SoundPool
|
||||
{
|
||||
List<SourceVoice> voices;
|
||||
|
||||
public SoundPool(XAudio2 device, WaveFormat format)
|
||||
{
|
||||
voices = new List<SourceVoice>();
|
||||
|
||||
for (int i = 0; i < 64; i++)
|
||||
voices.Add(new SourceVoice(device, format, true));
|
||||
}
|
||||
|
||||
|
||||
public void PlayBuffer(AudioBuffer buffer, uint[] packetinfo)
|
||||
{
|
||||
int preferred = -1;
|
||||
|
||||
for (int i = 0; i < voices.Count; i++)
|
||||
if (voices[i].State.BuffersQueued == 0)
|
||||
preferred = i;
|
||||
|
||||
if (preferred != -1)
|
||||
{
|
||||
// voices[preferred].FlushSourceBuffers();
|
||||
voices[preferred].SubmitSourceBuffer(buffer, packetinfo);
|
||||
voices[preferred].Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|