Skip to content

Commit

Permalink
MEF removed from NAudioDemo and lots of code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
markheath committed Sep 12, 2015
1 parent 94b752a commit 0c37b66
Show file tree
Hide file tree
Showing 62 changed files with 356 additions and 470 deletions.
9 changes: 4 additions & 5 deletions AudioFileInspector/AudioFileInspector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
Expand All @@ -39,6 +39,7 @@
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -63,10 +64,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition, Version=2008.11.24.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Lib\MEF\System.ComponentModel.Composition.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
Expand Down Expand Up @@ -134,6 +132,7 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="app.config" />
<None Include="InstallScript.nsi" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand Down
2 changes: 1 addition & 1 deletion AudioFileInspector/Properties/Resources.Designer.cs

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

4 changes: 2 additions & 2 deletions AudioFileInspector/Properties/Settings.Designer.cs

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

3 changes: 3 additions & 0 deletions AudioFileInspector/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/></startup></configuration>
Binary file not shown.
Binary file removed Lib/MEF/System.ComponentModel.Composition.dll
Binary file not shown.
2 changes: 0 additions & 2 deletions Lib/MEF/readme.txt

This file was deleted.

10 changes: 5 additions & 5 deletions NAudioDemo/AcmDemo/AcmPanel.Designer.cs

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

21 changes: 7 additions & 14 deletions NAudioDemo/AcmDemo/AcmPanel.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using NAudio.Wave;
using NAudio.Wave.Compression;
using System.ComponentModel.Composition;

namespace NAudioDemo
namespace NAudioDemo.AcmDemo
{
public partial class AcmPanel : UserControl
{
Expand All @@ -18,7 +13,7 @@ public AcmPanel()
InitializeComponent();
}

private void AcmForm_Load(object sender, EventArgs e)
private void OnAcmFormLoad(object sender, EventArgs e)
{
RefreshDriversList();
}
Expand All @@ -32,7 +27,7 @@ private void RefreshDriversList()
}
}

private void buttonEncode_Click(object sender, EventArgs args)
private void OnButtonEncodeClick(object sender, EventArgs args)
{
try
{
Expand Down Expand Up @@ -62,7 +57,7 @@ private WaveFormat GetTargetFormat(WaveFormat inputFormat)
string formatDescription;
string formatTagDescription;
AcmDriver.ShowFormatChooseDialog(
this.Handle,
Handle,
"Select Compressed Format:",
AcmFormatEnumFlags.Convert,
inputFormat,
Expand Down Expand Up @@ -161,18 +156,18 @@ private string GetOutputFileName(string title)
return null;
}

private void listBoxAcmDrivers_SelectedIndexChanged(object sender, EventArgs e)
private void OnListBoxAcmDriversSelectedIndexChanged(object sender, EventArgs e)
{
var driver = listBoxAcmDrivers.SelectedItem as AcmDriver;
richTextBox1.Text = DescribeCodec(driver);
}

private void buttonChooseFormat_Click(object sender, EventArgs e)
private void OnButtonChooseFormatClick(object sender, EventArgs e)
{
WaveFormat selectedFormat;
string selectedFormatDescription;
string selectedFormatTagDescription;
if(AcmDriver.ShowFormatChooseDialog(this.Handle,"Choose a WaveFormat",AcmFormatEnumFlags.None,
if(AcmDriver.ShowFormatChooseDialog(Handle,"Choose a WaveFormat",AcmFormatEnumFlags.None,
null,out selectedFormat,
out selectedFormatDescription, out selectedFormatTagDescription))
{
Expand Down Expand Up @@ -266,8 +261,6 @@ private void buttonAdd_Click(object sender, EventArgs args)
}
}


[Export(typeof(INAudioDemoPlugin))]
public class AcmPanelPlugin : INAudioDemoPlugin
{
public string Name
Expand Down
10 changes: 5 additions & 5 deletions NAudioDemo/AsioDirectDemo/AsioDirectPanel.Designer.cs

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

71 changes: 32 additions & 39 deletions NAudioDemo/AsioDirectDemo/AsioDirectPanel.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NAudio.Wave;
using System.ComponentModel.Composition;

namespace NAudioDemo
namespace NAudioDemo.AsioDirectDemo
{
public partial class AsioDirectPanel : UserControl
{
Expand All @@ -19,48 +13,48 @@ public partial class AsioDirectPanel : UserControl
public AsioDirectPanel()
{
InitializeComponent();
this.Disposed += new EventHandler(AsioDirectPanel_Disposed);
Disposed += OnAsioDirectPanelDisposed;
foreach(var device in AsioOut.GetDriverNames())
{
this.comboBoxAsioDevice.Items.Add(device);
comboBoxAsioDevice.Items.Add(device);
}
if (this.comboBoxAsioDevice.Items.Count > 0)
if (comboBoxAsioDevice.Items.Count > 0)
{
this.comboBoxAsioDevice.SelectedIndex = 0;
comboBoxAsioDevice.SelectedIndex = 0;
}
}

void AsioDirectPanel_Disposed(object sender, EventArgs e)
void OnAsioDirectPanelDisposed(object sender, EventArgs e)
{
Cleanup();
}

private void Cleanup()
{
if (this.asioOut != null)
if (asioOut != null)
{
this.asioOut.Dispose();
this.asioOut = null;
asioOut.Dispose();
asioOut = null;
}
if (this.reader != null)
if (reader != null)
{
this.reader.Dispose();
this.reader = null;
reader.Dispose();
reader = null;
}
}

private void buttonSelectFile_Click(object sender, EventArgs e)
private void OnButtonSelectFileClick(object sender, EventArgs e)
{
Cleanup();
var ofd = new OpenFileDialog();
ofd.Filter = "Audio files|*.wav;*.mp3";
if (ofd.ShowDialog() == DialogResult.OK)
{
this.reader = new AudioFileReader(ofd.FileName);
reader = new AudioFileReader(ofd.FileName);
}
}

private void buttonPlay_Click(object sender, EventArgs args)
private void OnButtonPlayClick(object sender, EventArgs args)
{
try
{
Expand All @@ -74,33 +68,33 @@ private void buttonPlay_Click(object sender, EventArgs args)

private int GetUserSpecifiedChannelOffset()
{
int channelOffset = 0;
int channelOffset;
int.TryParse(textBoxChannelOffset.Text, out channelOffset);
return channelOffset;
}

private void Play()
{
// allow change device
if (this.asioOut != null &&
(this.asioOut.DriverName != comboBoxAsioDevice.Text ||
this.asioOut.ChannelOffset != GetUserSpecifiedChannelOffset()))
if (asioOut != null &&
(asioOut.DriverName != comboBoxAsioDevice.Text ||
asioOut.ChannelOffset != GetUserSpecifiedChannelOffset()))
{
this.asioOut.Dispose();
this.asioOut = null;
asioOut.Dispose();
asioOut = null;
}

// create device if necessary
if (this.asioOut == null)
if (asioOut == null)
{
this.asioOut = new AsioOut(comboBoxAsioDevice.Text);
this.asioOut.ChannelOffset = GetUserSpecifiedChannelOffset();
this.asioOut.Init(this.reader);
asioOut = new AsioOut(comboBoxAsioDevice.Text);
asioOut.ChannelOffset = GetUserSpecifiedChannelOffset();
asioOut.Init(reader);
}

this.reader.Position = 0;
this.asioOut.Play();
this.timer1.Enabled = true;
reader.Position = 0;
asioOut.Play();
timer1.Enabled = true;
SetButtonStates();
}

Expand All @@ -110,19 +104,19 @@ private void SetButtonStates()
buttonStop.Enabled = asioOut != null && asioOut.PlaybackState == PlaybackState.Playing;
}

private void buttonStop_Click(object sender, EventArgs e)
private void OnButtonStopClick(object sender, EventArgs e)
{
Stop();
}

private void Stop()
{
this.asioOut.Stop();
this.timer1.Enabled = false;
asioOut.Stop();
timer1.Enabled = false;
SetButtonStates();
}

private void timer1_Tick(object sender, EventArgs e)
private void OnTimerTick(object sender, EventArgs e)
{
if (asioOut != null && asioOut.PlaybackState == PlaybackState.Playing && reader.Position >= reader.Length)
{
Expand All @@ -131,7 +125,6 @@ private void timer1_Tick(object sender, EventArgs e)
}
}

[Export(typeof(INAudioDemoPlugin))]
public class AsioDirectPanelPlugin : INAudioDemoPlugin
{
public string Name
Expand Down
Loading

0 comments on commit 0c37b66

Please sign in to comment.