Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.ComponentModel;
- using System.Drawing;
- using System.Windows.Forms;
- namespace FracksA00
- {
- public partial class SamplerBackground : UserControl
- {
- public SamplerBackground()
- {
- InitializeComponent();
- }
- private NAudio.Wave.WaveFileReader wave = null;
- private NAudio.Wave.DirectSoundOut output = null;
- void SamplerButtonLoadClick(object sender, EventArgs e)
- {
- OpenFileDialog open = new OpenFileDialog();
- open.Filter = "Wave File (*.wav)|*.wav;";
- if (open.ShowDialog() != DialogResult.OK) return;
- DisposeWave();
- wave = new NAudio.Wave.WaveFileReader(open.FileName);
- output = new NAudio.Wave.DirectSoundOut();
- output.Init(new NAudio.Wave.WaveChannel32(wave));
- output.Play();
- SamplerButtonPlay.Enabled = true;
- }
- void SamplerButtonPlayClick(object sender, EventArgs e)
- {
- if (output != null)
- {
- if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) output.Pause();
- else if (output.PlaybackState == NAudio.Wave.PlaybackState.Paused) output.Play();
- }
- }
- private void DisposeWave()
- {
- if (output != null)
- {
- if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) output.Stop();
- output.Dispose();
- output = null;
- }
- if (wave != null)
- {
- wave.Dispose();
- wave = null;
- }
- }
- private void Sampler_FormClosing(object sender, FormClosingEventArgs e)
- {
- DisposeWave();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement