Skip to content

Commit

Permalink
merge from master
Browse files Browse the repository at this point in the history
  • Loading branch information
markheath committed Mar 11, 2016
2 parents 2d8deb6 + ae02165 commit c342e11
Show file tree
Hide file tree
Showing 37 changed files with 558 additions and 397 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# runs on mono, so we can't build the Win 8 or Universal projects
# docs here: https://docs.travis-ci.com/user/languages/csharp/
language: csharp
solution: NAudio.sln
script:
- xbuild /p:Configuration=Release NAudio.sln
- mono ./packages/NUnit.*/tools/nunit-console.exe /exclude=IntegrationTest ./NAudioTests/bin/Release/NAudioTests.dll
4 changes: 2 additions & 2 deletions MidiFileConverter/AboutForm.Designer.cs

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

28 changes: 15 additions & 13 deletions MidiFileConverter/MidiConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using NAudio.Utils;
using NAudio.Midi;
Expand Down Expand Up @@ -191,7 +192,7 @@ private void ConvertMidi(MidiFile midiFile, string target, string[] context)
if (midiFile.FileFormat == 0)
outputTrackCount = 2;
else
outputTrackCount = midiFile.Tracks;
outputTrackCount = Math.Max(midiFile.Tracks,2); // at least two tracks because we'll move notes onto track 1 always
}


Expand Down Expand Up @@ -327,11 +328,8 @@ private void ConvertMidi(MidiFile midiFile, string target, string[] context)
{
if (outputFileType == 1)
{
// if we are converting type 0 to type 1 and recreating end markers,
if (midiFile.FileFormat == 0)
{
AppendEndMarker(events[1]);
}
// make sure track 1 has an end track marker
AppendEndMarker(events[1]);
}
// make sure that track zero has an end track marker
AppendEndMarker(events[0]);
Expand Down Expand Up @@ -397,20 +395,24 @@ private void ConvertMidi(MidiFile midiFile, string target, string[] context)

private bool HasNotes(IList<MidiEvent> midiEvents)
{
foreach (MidiEvent midiEvent in midiEvents)
{
if (midiEvent.CommandCode == MidiCommandCode.NoteOn)
return true;
}
return false;
return midiEvents.Any(midiEvent => midiEvent.CommandCode == MidiCommandCode.NoteOn);
}

private bool IsEndTrack(MidiEvent midiEvent)
{
var meta = midiEvent as MetaEvent;
return meta?.MetaEventType == MetaEventType.EndTrack;
}

private void AppendEndMarker(IList<MidiEvent> eventList)
{
long absoluteTime = 0;

if (eventList.Count > 0)
absoluteTime = eventList[eventList.Count - 1].AbsoluteTime;
eventList.Add(new MetaEvent(MetaEventType.EndTrack, 0, absoluteTime));

if (!IsEndTrack(eventList.LastOrDefault()))
eventList.Add(new MetaEvent(MetaEventType.EndTrack, 0, absoluteTime));
}

private string CreateEzdName(string[] context)
Expand Down
8 changes: 5 additions & 3 deletions MidiFileConverter/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Mark Heath")]
[assembly: AssemblyProduct("MIDI File Converter")]
[assembly: AssemblyCopyright("Copyright © Mark Heath 2007")]
[assembly: AssemblyCopyright("Copyright © Mark Heath 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -29,8 +29,8 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("0.3.10.0")]
[assembly: AssemblyFileVersion("0.3.10.0")]
[assembly: AssemblyVersion("0.3.11.0")]
[assembly: AssemblyFileVersion("0.3.11.0")]

// build 1 29 Oct 2006
// build 1 is experimental
Expand Down Expand Up @@ -73,6 +73,8 @@
// and converting from type 0 to type 1
// build 10 5 Apr 2007
// updated to use new MidiEventCollection
// build 11 12 Feb 2016
// ensuring end track markers persent converting type 1 to 1

// revamp help for advanced options

Expand Down
16 changes: 16 additions & 0 deletions NAudio.Universal/CoreAudioApi/PropVariantNative.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Runtime.InteropServices;

namespace NAudio.CoreAudioApi.Interfaces
{
class PropVariantNative
{
// Windows 10 requires api-ms-win-core-com-l1-1-1.dll
[DllImport("api-ms-win-core-com-l1-1-1.dll")]
internal static extern int PropVariantClear(ref PropVariant pvar);

[DllImport("api-ms-win-core-com-l1-1-1.dll")]
internal static extern int PropVariantClear(IntPtr pvar);

}
}
2 changes: 2 additions & 0 deletions NAudio.Universal/NAudio.Universal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,9 @@
<Compile Include="..\NAudio\Wave\WaveStreams\WaveStream.cs">
<Link>Wave\WaveStreams\WaveStream.cs</Link>
</Compile>
<Compile Include="CoreAudioApi\PropVariantNative.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utils\MarshalHelpers.cs" />
<Compile Include="Wave\WaveOutputs\IWavePlayer.cs" />
</ItemGroup>
<ItemGroup />
Expand Down
6 changes: 6 additions & 0 deletions NAudio.Win8/NAudio.Win8.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@
<Compile Include="..\NAudio\CoreAudioApi\PropVariant.cs">
<Link>CoreAudioApi\PropVariant.cs</Link>
</Compile>
<Compile Include="..\NAudio\CoreAudioApi\PropVariantNative.cs">
<Link>CoreAudioApi\PropVariantNative.cs</Link>
</Compile>
<Compile Include="..\NAudio\CoreAudioApi\Role.cs">
<Link>CoreAudioApi\Role.cs</Link>
</Compile>
Expand Down Expand Up @@ -586,6 +589,9 @@
<Compile Include="..\NAudio\Utils\IgnoreDisposeStream.cs">
<Link>Utils\IgnoreDisposeStream.cs</Link>
</Compile>
<Compile Include="..\NAudio\Utils\MarshalHelpers.cs">
<Link>Utils\MarshalHelpers.cs</Link>
</Compile>
<Compile Include="..\NAudio\Utils\MergeSort.cs">
<Link>Utils\MergeSort.cs</Link>
</Compile>
Expand Down
3 changes: 2 additions & 1 deletion NAudio.Win8/Wave/WaveOutputs/WasapiOutRT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using NAudio.Dsp;
using NAudio.Wave;
using Windows.Media.Devices;
using NAudio.Utils;
using NAudio.Wave.SampleProviders;

namespace NAudio.Win8.Wave.WaveOutputs
Expand Down Expand Up @@ -95,7 +96,7 @@ public void SetClientProperties(bool useHardwareOffload, AudioStreamCategory cat
{
audioClientProperties = new AudioClientProperties()
{
cbSize = (uint) Marshal.SizeOf<AudioClientProperties>(),
cbSize = (uint) MarshalHelpers.SizeOf<AudioClientProperties>(),
bIsOffload = Convert.ToInt32(useHardwareOffload),
eCategory = category,
Options = options
Expand Down
4 changes: 2 additions & 2 deletions NAudio.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NAudio", "NAudio\NAudio.csproj", "{DA4F02E3-0B5E-42CD-B8D9-5583FA51D66E}"
EndProject
Expand Down
26 changes: 21 additions & 5 deletions NAudio/CoreAudioApi/AudioEndpointVolume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ public class AudioEndpointVolume : IDisposable
private readonly EEndpointHardwareSupport hardwareSupport;
private AudioEndpointVolumeCallback callBack;

private Guid notificationGuid = Guid.Empty;

/// <summary>
/// GUID to pass to AudioEndpointVolumeCallback
/// </summary>
public Guid NotificationGuid {
get
{
return notificationGuid;
}
set
{
notificationGuid = value;
}
}

/// <summary>
/// On Volume Notification
/// </summary>
Expand Down Expand Up @@ -100,7 +116,7 @@ public float MasterVolumeLevel
}
set
{
Marshal.ThrowExceptionForHR(audioEndPointVolume.SetMasterVolumeLevel(value, Guid.Empty));
Marshal.ThrowExceptionForHR(audioEndPointVolume.SetMasterVolumeLevel(value, ref notificationGuid));
}
}

Expand All @@ -117,7 +133,7 @@ public float MasterVolumeLevelScalar
}
set
{
Marshal.ThrowExceptionForHR(audioEndPointVolume.SetMasterVolumeLevelScalar(value, Guid.Empty));
Marshal.ThrowExceptionForHR(audioEndPointVolume.SetMasterVolumeLevelScalar(value, ref notificationGuid));
}
}

Expand All @@ -134,7 +150,7 @@ public bool Mute
}
set
{
Marshal.ThrowExceptionForHR(audioEndPointVolume.SetMute(value, Guid.Empty));
Marshal.ThrowExceptionForHR(audioEndPointVolume.SetMute(value, ref notificationGuid));
}
}

Expand All @@ -143,15 +159,15 @@ public bool Mute
/// </summary>
public void VolumeStepUp()
{
Marshal.ThrowExceptionForHR(audioEndPointVolume.VolumeStepUp(Guid.Empty));
Marshal.ThrowExceptionForHR(audioEndPointVolume.VolumeStepUp(ref notificationGuid));
}

/// <summary>
/// Volume Step Down
/// </summary>
public void VolumeStepDown()
{
Marshal.ThrowExceptionForHR(audioEndPointVolume.VolumeStepDown(Guid.Empty));
Marshal.ThrowExceptionForHR(audioEndPointVolume.VolumeStepDown(ref notificationGuid));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion NAudio/CoreAudioApi/AudioEndpointVolumeCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void OnNotify(IntPtr notifyData)
}

//Create combined structure and Fire Event in parent class.
var notificationData = new AudioVolumeNotificationData(data.guidEventContext, data.bMuted, data.fMasterVolume, voldata);
var notificationData = new AudioVolumeNotificationData(data.guidEventContext, data.bMuted, data.fMasterVolume, voldata, data.guidEventContext);
parent.FireNotification(notificationData);
}
}
Expand Down
21 changes: 19 additions & 2 deletions NAudio/CoreAudioApi/AudioEndpointVolumeChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ public class AudioEndpointVolumeChannel
private readonly uint channel;
private readonly IAudioEndpointVolume audioEndpointVolume;

private Guid notificationGuid = Guid.Empty;

/// <summary>
/// GUID to pass to AudioEndpointVolumeCallback
/// </summary>
public Guid NotificationGuid
{
get
{
return notificationGuid;
}
set
{
notificationGuid = value;
}
}

internal AudioEndpointVolumeChannel(IAudioEndpointVolume parent, int channel)
{
this.channel = (uint)channel;
Expand All @@ -53,7 +70,7 @@ public float VolumeLevel
}
set
{
Marshal.ThrowExceptionForHR(audioEndpointVolume.SetChannelVolumeLevel(channel, value,Guid.Empty));
Marshal.ThrowExceptionForHR(audioEndpointVolume.SetChannelVolumeLevel(channel, value, ref this.notificationGuid));
}
}

Expand All @@ -70,7 +87,7 @@ public float VolumeLevelScalar
}
set
{
Marshal.ThrowExceptionForHR(audioEndpointVolume.SetChannelVolumeLevelScalar(channel, value, Guid.Empty));
Marshal.ThrowExceptionForHR(audioEndpointVolume.SetChannelVolumeLevelScalar(channel, value, ref this.notificationGuid));
}
}

Expand Down
2 changes: 2 additions & 0 deletions NAudio/CoreAudioApi/AudioSessionControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void Dispose()
if (audioSessionEventCallback != null)
{
Marshal.ThrowExceptionForHR(audioSessionControlInterface.UnregisterAudioSessionNotification(audioSessionEventCallback));
audioSessionEventCallback = null;
}
GC.SuppressFinalize(this);
}
Expand Down Expand Up @@ -241,6 +242,7 @@ public void UnRegisterEventClient(IAudioSessionEventsHandler eventClient)
if (audioSessionEventCallback != null)
{
Marshal.ThrowExceptionForHR(audioSessionControlInterface.UnregisterAudioSessionNotification(audioSessionEventCallback));
audioSessionEventCallback = null;
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion NAudio/CoreAudioApi/AudioVolumeNotificationData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class AudioVolumeNotificationData
private readonly float masterVolume;
private readonly int channels;
private readonly float[] channelVolume;
private readonly Guid guid;

/// <summary>
/// Event Context
Expand All @@ -50,6 +51,14 @@ public bool Muted
get { return muted; }
}

/// <summary>
/// Guid that raised the event
/// </summary>
public Guid Guid
{
get { return guid; }
}

/// <summary>
/// Master Volume
/// </summary>
Expand Down Expand Up @@ -81,13 +90,15 @@ public float[] ChannelVolume
/// <param name="muted"></param>
/// <param name="masterVolume"></param>
/// <param name="channelVolume"></param>
public AudioVolumeNotificationData(Guid eventContext, bool muted, float masterVolume, float[] channelVolume)
/// <param name="guid"></param>
public AudioVolumeNotificationData(Guid eventContext, bool muted, float masterVolume, float[] channelVolume, Guid guid)
{
this.eventContext = eventContext;
this.muted = muted;
this.masterVolume = masterVolume;
channels = channelVolume.Length;
this.channelVolume = channelVolume;
this.guid = guid;
}
}
}
14 changes: 7 additions & 7 deletions NAudio/CoreAudioApi/Interfaces/IAudioEndpointVolume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ internal interface IAudioEndpointVolume
int RegisterControlChangeNotify(IAudioEndpointVolumeCallback pNotify);
int UnregisterControlChangeNotify(IAudioEndpointVolumeCallback pNotify);
int GetChannelCount(out int pnChannelCount);
int SetMasterVolumeLevel(float fLevelDB, Guid pguidEventContext);
int SetMasterVolumeLevelScalar(float fLevel, Guid pguidEventContext);
int SetMasterVolumeLevel(float fLevelDB, ref Guid pguidEventContext);
int SetMasterVolumeLevelScalar(float fLevel, ref Guid pguidEventContext);
int GetMasterVolumeLevel(out float pfLevelDB);
int GetMasterVolumeLevelScalar(out float pfLevel);
int SetChannelVolumeLevel(uint nChannel, float fLevelDB, Guid pguidEventContext);
int SetChannelVolumeLevelScalar(uint nChannel, float fLevel, Guid pguidEventContext);
int SetChannelVolumeLevel(uint nChannel, float fLevelDB, ref Guid pguidEventContext);
int SetChannelVolumeLevelScalar(uint nChannel, float fLevel, ref Guid pguidEventContext);
int GetChannelVolumeLevel(uint nChannel, out float pfLevelDB);
int GetChannelVolumeLevelScalar(uint nChannel, out float pfLevel);
int SetMute([MarshalAs(UnmanagedType.Bool)] Boolean bMute, Guid pguidEventContext);
int SetMute([MarshalAs(UnmanagedType.Bool)] Boolean bMute, ref Guid pguidEventContext);
int GetMute(out bool pbMute);
int GetVolumeStepInfo(out uint pnStep, out uint pnStepCount);
int VolumeStepUp(Guid pguidEventContext);
int VolumeStepDown(Guid pguidEventContext);
int VolumeStepUp(ref Guid pguidEventContext);
int VolumeStepDown(ref Guid pguidEventContext);
int QueryHardwareSupport(out uint pdwHardwareSupportMask);
int GetVolumeRange(out float pflVolumeMindB, out float pflVolumeMaxdB, out float pflVolumeIncrementdB);
}
Expand Down
Loading

0 comments on commit c342e11

Please sign in to comment.