Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. using System;
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5.  
  6. namespace FracksA00
  7. {
  8.     public partial class SamplerBackground : UserControl
  9.     {
  10.         public SamplerBackground()
  11.         {
  12.             InitializeComponent();
  13.  
  14.         }
  15.        
  16.         private NAudio.Wave.WaveFileReader wave = null;
  17.         private NAudio.Wave.DirectSoundOut output = null;
  18.        
  19.         void SamplerButtonLoadClick(object sender, EventArgs e)
  20.         {
  21.             OpenFileDialog open = new OpenFileDialog();
  22.             open.Filter = "Wave File (*.wav)|*.wav;";
  23.             if (open.ShowDialog() != DialogResult.OK) return;
  24.            
  25.             DisposeWave();
  26.            
  27.             wave = new NAudio.Wave.WaveFileReader(open.FileName);
  28.             output = new NAudio.Wave.DirectSoundOut();
  29.             output.Init(new NAudio.Wave.WaveChannel32(wave));
  30.             output.Play();
  31.            
  32.             SamplerButtonPlay.Enabled = true;
  33.            
  34.         }
  35.         void SamplerButtonPlayClick(object sender, EventArgs e)
  36.         {
  37.             if (output != null)
  38.             {
  39.                 if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) output.Pause();
  40.                 else if (output.PlaybackState == NAudio.Wave.PlaybackState.Paused) output.Play();
  41.                
  42.             }
  43.         }
  44.        
  45.         private void DisposeWave()
  46.         {
  47.             if (output != null)
  48.             {
  49.                 if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) output.Stop();
  50.                 output.Dispose();
  51.                 output = null;
  52.             }
  53.             if (wave != null)
  54.             {
  55.                 wave.Dispose();
  56.                 wave = null;
  57.             }
  58.         }
  59.         private void Sampler_FormClosing(object sender, FormClosingEventArgs e)
  60.         {
  61.             DisposeWave();         
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement