Skip to content

Commit

Permalink
1.0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Mygod committed Feb 22, 2014
1 parent f036549 commit 165a884
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 35 deletions.
8 changes: 5 additions & 3 deletions Musicript.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,23 @@ Global
{0587A090-24B0-462E-B1E7-A932E56FC42A}.Debug|x86.ActiveCfg = Debug|Any CPU
{0587A090-24B0-462E-B1E7-A932E56FC42A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0587A090-24B0-462E-B1E7-A932E56FC42A}.Release|Any CPU.Build.0 = Release|Any CPU
{0587A090-24B0-462E-B1E7-A932E56FC42A}.Release|x86.ActiveCfg = Release|Any CPU
{0587A090-24B0-462E-B1E7-A932E56FC42A}.Release|x86.ActiveCfg = Release|x86
{0587A090-24B0-462E-B1E7-A932E56FC42A}.Release|x86.Build.0 = Release|x86
{D915CED8-AC3F-40D6-8C95-4D176C924A61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D915CED8-AC3F-40D6-8C95-4D176C924A61}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D915CED8-AC3F-40D6-8C95-4D176C924A61}.Debug|x86.ActiveCfg = Debug|x86
{D915CED8-AC3F-40D6-8C95-4D176C924A61}.Debug|x86.Build.0 = Debug|x86
{D915CED8-AC3F-40D6-8C95-4D176C924A61}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D915CED8-AC3F-40D6-8C95-4D176C924A61}.Release|Any CPU.Build.0 = Release|Any CPU
{D915CED8-AC3F-40D6-8C95-4D176C924A61}.Release|x86.ActiveCfg = Release|x86
{D915CED8-AC3F-40D6-8C95-4D176C924A61}.Release|x86.Build.0 = Release|x86
{D915CED8-AC3F-40D6-8C95-4D176C924A61}.Release|x86.ActiveCfg = Release|Any CPU
{D915CED8-AC3F-40D6-8C95-4D176C924A61}.Release|x86.Build.0 = Release|Any CPU
{2A09E67B-423E-4164-83EF-7542CF0A9D42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A09E67B-423E-4164-83EF-7542CF0A9D42}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A09E67B-423E-4164-83EF-7542CF0A9D42}.Debug|x86.ActiveCfg = Debug|Any CPU
{2A09E67B-423E-4164-83EF-7542CF0A9D42}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A09E67B-423E-4164-83EF-7542CF0A9D42}.Release|Any CPU.Build.0 = Release|Any CPU
{2A09E67B-423E-4164-83EF-7542CF0A9D42}.Release|x86.ActiveCfg = Release|Any CPU
{2A09E67B-423E-4164-83EF-7542CF0A9D42}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 3 additions & 2 deletions Musicript/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Windows;
using System.Windows.Threading;
Expand All @@ -11,10 +12,10 @@ public sealed partial class App
static App()
{
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
/*AppDomain.CurrentDomain.SetData("PRIVATE_BINPATH", "Resources\\Libraries");
AppDomain.CurrentDomain.SetData("PRIVATE_BINPATH", "Resources\\Libraries");
var m = typeof(AppDomainSetup).GetMethod("UpdateContextProperty", BindingFlags.NonPublic | BindingFlags.Static);
var fusion = typeof(AppDomain).GetMethod("GetFusionContext", BindingFlags.NonPublic | BindingFlags.Instance);
m.Invoke(null, new[] { fusion.Invoke(AppDomain.CurrentDomain, null), "PRIVATE_BINPATH", "Bin" });*/
m.Invoke(null, new[] { fusion.Invoke(AppDomain.CurrentDomain, null), "PRIVATE_BINPATH", "Bin" });
}

private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
Expand Down
4 changes: 2 additions & 2 deletions Musicript/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.1")]
[assembly: AssemblyVersion("1.0.1.1")]
[assembly: AssemblyFileVersion("1.0.1.1")]
37 changes: 20 additions & 17 deletions Musicript/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,39 @@

namespace Mygod.Musicript
{
public sealed class Instrument
public static class Instrument
{
private Instrument(Assembly assembly, string className)
public static double Sample(string instrumentName, double time)
{
sample = assembly.GetType("Mygod.Musicript.Instruments." + className)
.GetMethod("Sample", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(double) }, null);
return (double) Instruments[instrumentName].Invoke(null, new object[] { time });
}

public double Sample(double time)
private static MethodInfo GetSampleMethod(this IReflect type)
{
return (double) sample.Invoke(null, new object[] { time });
return type.GetMethod("Sample", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(double) }, null);
}

private readonly MethodInfo sample;

private static readonly Dictionary<string, Assembly> ImportedAssemblies = new Dictionary<string, Assembly>();
public static readonly Dictionary<string, Instrument> Instruments = new Dictionary<string, Instrument>();
public static readonly Dictionary<string, MethodInfo> Instruments = new Dictionary<string, MethodInfo>();

private static readonly string Prefix = "Mygod.Musicript.Instruments.";

public static void Import(string path, string classNames, string dir = null)
{
if (string.IsNullOrWhiteSpace(classNames)) return; // MEH I DON'T EVEN CARE
string fullPath;
path += ".dll";
if (dir == null || !File.Exists(fullPath = Path.Combine(dir, "Instruments", path)))
if (!File.Exists(fullPath = Path.Combine(CurrentApp.Directory, "Presets/Instruments", path)))
throw new FileNotFoundException();
var temp = fullPath.ToLowerInvariant();
if (!ImportedAssemblies.ContainsKey(temp)) ImportedAssemblies.Add(temp, Assembly.LoadFrom(fullPath));
foreach (var className in classNames.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
Instruments[className] = new Instrument(ImportedAssemblies[temp], className);
var asm = Assembly.LoadFrom(fullPath);
if (!ImportedAssemblies.ContainsKey(temp)) ImportedAssemblies.Add(temp, asm);
var regex = string.IsNullOrWhiteSpace(classNames) ? null : new Regex(classNames, RegexOptions.Compiled);
foreach (var type in asm.GetTypes()
.Where(type => type.FullName.StartsWith(Prefix) && (regex == null || regex.IsMatch(type.FullName))))
{
var sample = type.GetSampleMethod();
if (sample != null) Instruments[type.FullName.Substring(Prefix.Length)] = sample;
}
}
}

Expand Down Expand Up @@ -125,7 +128,7 @@ public sealed class Track : List<TrackNode>
public Track(XElement element)
{
currentNoteStartTime = BeginAt = element.GetAttributeValueWithDefault<TimeSpan>("BeginAt").TotalSeconds;
Instrument = Instrument.Instruments[element.GetAttributeValue("Instrument")];
InstrumentName = element.GetAttributeValue("Instrument");
Tempo = element.GetAttributeValueWithDefault("Tempo", 60.0);
Dynamics = element.GetAttributeValueWithDefault("Dynamics", 1.0);
var sum = 0.0;
Expand All @@ -139,7 +142,7 @@ public Track(XElement element)
}

public readonly double BeginAt, Length;
public readonly Instrument Instrument;
public readonly string InstrumentName;
public double Tempo, Dynamics;

private int currentNodeIndex;
Expand Down Expand Up @@ -192,7 +195,7 @@ public double Update(double time)
currentNodeIndex++;
}
var freq = ((Note) this[currentNodeIndex]).Frequency;
return freq < 1e-8 ? 0 : Instrument.Sample((time - currentNoteStartTime) * freq) * Dynamics;
return freq < 1e-8 ? 0 : Instrument.Sample(InstrumentName, (time - currentNoteStartTime) * freq) * Dynamics;
}
}
public sealed class Channel : List<Track>
Expand Down
Binary file modified Musicript/Main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 21 additions & 10 deletions Musicript/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
using System.IO;
using System.Media;
using System.Globalization;
using System.IO;
using System.Windows;
using IrrKlang;
using Mygod.Windows;
using Mygod.Windows.Dialogs;

namespace Mygod.Musicript
{
public sealed partial class MainWindow
{
private sealed class SoundStopEventReceiver : ISoundStopEventReceiver
{
public void OnSoundStopped(ISound iSound, StopEventCause reason, object userData)
{
sound = null;
}
}

public MainWindow()
{
InitializeComponent();
Expand All @@ -20,7 +29,10 @@ public MainWindow()
};
private readonly SaveFileDialog wavSaver = new SaveFileDialog { Filter = "波形文件 (*.wav) | *.wav", AddExtension = true };

private SoundPlayer player;
private static readonly ISoundEngine Engine = new ISoundEngine();
private static ISound sound;
private static int index;
private static readonly ISoundStopEventReceiver Receiver = new SoundStopEventReceiver();

private void BrowseProject(object sender, RoutedEventArgs e)
{
Expand All @@ -29,21 +41,20 @@ private void BrowseProject(object sender, RoutedEventArgs e)

private void Play(object sender, RoutedEventArgs e)
{
if (player != null) Stop(sender, e);
if (sound != null) Stop(sender, e);
var proj = new Project(ProjectBox.Text);
player = new SoundPlayer(proj.Compile(BitsPerSampleBox.SelectedIndex >= 8
sound = Engine.Play2D(Engine.AddSoundSourceFromIOStream(proj.Compile(BitsPerSampleBox.SelectedIndex >= 8
? (BitsPerSampleBox.SelectedIndex - 8) << 2 : (BitsPerSampleBox.SelectedIndex + 1),
uint.Parse(SamplingRateBox.Text))) { LoadTimeout = int.MaxValue };
if (proj.Looped) player.PlayLooping();
else player.Play();
uint.Parse(SamplingRateBox.Text)), (++index).ToString(CultureInfo.InvariantCulture)), proj.Looped, false, false);
sound.setSoundStopEventReceiver(Receiver);
StopButton.IsEnabled = true;
}

private void Stop(object sender, RoutedEventArgs e)
{
player.Stop();
player = null;
Engine.StopAllSounds();
StopButton.IsEnabled = false;
sound = null;
}

private void SaveToFile(object sender, RoutedEventArgs e)
Expand Down
28 changes: 27 additions & 1 deletion Musicript/Musicript.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,29 @@
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="irrKlang.NET4">
<HintPath>.\irrKlang.NET4.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
Expand Down Expand Up @@ -155,7 +177,11 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>"C:\Program Files (x86)\Windows Kits\8.1\bin\x86\signtool.exe" sign /v /f "$(ProjectDir)Mygod.pfx" /t http://timestamp.verisign.com/scripts/timestamp.dll "$(TargetDir)$(TargetFileName)"</PostBuildEvent>
<PostBuildEvent>"C:\Program Files (x86)\Windows Kits\8.1\bin\x86\signtool.exe" sign /v /f "$(ProjectDir)Mygod.pfx" /t http://timestamp.verisign.com/scripts/timestamp.dll "$(TargetDir)$(TargetFileName)"
md "$(TargetDir)Bin"
move /y "$(TargetDir)irrKlang.NET4.dll" "$(TargetDir)Bin\irrKlang.NET4.dll"
move /y "$(TargetDir)MygodLibrary.dll" "$(TargetDir)Bin\MygodLibrary.dll"
move /y "$(TargetDir)MygodLibrary.pdb" "$(TargetDir)Bin\MygodLibrary.pdb"</PostBuildEvent>
</PropertyGroup>
<!-- 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.
Expand Down
24 changes: 24 additions & 0 deletions Musicript/Musicript/Presets/Instruments/Waves.XML

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Musicript/Presets/Instruments/Waves.XML

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Musicript/Presets/Instruments/Waves.dll
Binary file not shown.
Binary file added Musicript/irrKlang.NET4.dll
Binary file not shown.

0 comments on commit 165a884

Please sign in to comment.