using System;
using System.Collections.Generic;
using System.Text;
namespace NAudio.Wave
{
///
/// Wave Callback Info
///
public class WaveCallbackInfo
{
///
/// Callback Strategy
///
public WaveCallbackStrategy Strategy { get; private set; }
///
/// Window Handle (if applicable)
///
public IntPtr Handle { get; private set; }
///
/// Sets up a new WaveCallbackInfo for function callbacks
///
public static WaveCallbackInfo FunctionCallback()
{
return new WaveCallbackInfo(WaveCallbackStrategy.FunctionCallback, IntPtr.Zero);
}
///
/// Sets up a new WaveCallbackInfo to use a New Window
/// IMPORTANT: only use this on the GUI thread
///
public static WaveCallbackInfo NewWindow()
{
return new WaveCallbackInfo(WaveCallbackStrategy.NewWindow, IntPtr.Zero);
}
///
/// Sets up a new WaveCallbackInfo to use an existing window
/// IMPORTANT: only use this on the GUI thread
///
public static WaveCallbackInfo ExistingWindow(IntPtr handle)
{
if (handle == IntPtr.Zero)
{
throw new ArgumentException("Handle cannot be zero");
}
return new WaveCallbackInfo(WaveCallbackStrategy.ExistingWindow, handle);
}
private WaveCallbackInfo(WaveCallbackStrategy strategy, IntPtr handle)
{
this.Strategy = strategy;
this.Handle = handle;
}
internal void Connect(WaveInterop.WaveCallback callback)
{
}
internal MmResult WaveOutOpen(out IntPtr waveOutHandle, int deviceNumber, WaveFormat waveFormat, WaveInterop.WaveCallback callback)
{
MmResult result;
if (Strategy == WaveCallbackStrategy.FunctionCallback)
{
result = WaveInterop.waveOutOpen(out waveOutHandle, (IntPtr)deviceNumber, waveFormat, callback, IntPtr.Zero, WaveInterop.WaveInOutOpenFlags.CallbackFunction);
}
else
{
result = WaveInterop.waveOutOpenWindow(out waveOutHandle, (IntPtr)deviceNumber, waveFormat, this.Handle, IntPtr.Zero, WaveInterop.WaveInOutOpenFlags.CallbackWindow);
}
return result;
}
internal MmResult WaveInOpen(out IntPtr waveInHandle, int deviceNumber, WaveFormat waveFormat, WaveInterop.WaveCallback callback)
{
MmResult result;
if (Strategy == WaveCallbackStrategy.FunctionCallback)
{
result = WaveInterop.waveInOpen(out waveInHandle, (IntPtr)deviceNumber, waveFormat, callback, IntPtr.Zero, WaveInterop.WaveInOutOpenFlags.CallbackFunction);
}
else
{
result = WaveInterop.waveInOpenWindow(out waveInHandle, (IntPtr)deviceNumber, waveFormat, this.Handle, IntPtr.Zero, WaveInterop.WaveInOutOpenFlags.CallbackWindow);
}
return result;
}
internal void Disconnect()
{
}
}
}