Advertisement
Guest User

Untitled

a guest
Jan 1st, 2012
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1. [MachineDecl(Name = "Jeskola Gain", ShortName = "Gain", Author = "Oskari Tammelin")]
  2.     public class GainMachine : IBuzzMachine
  3.     {
  4.         IBuzzMachineHost host;
  5.  
  6.         public GainMachine(IBuzzMachineHost host)
  7.         {
  8.             this.host = host;
  9.             Gain = new Interpolator();
  10.             MachineState = new State();
  11.         }
  12.  
  13.         [ParameterDecl(ResponseTime = 5, MaxValue = 127, DefValue = 80, Transformation = Transformations.Cubic, TransformUnityValue = 80, ValueDescriptor = Descriptors.Decibel)]
  14.         public Interpolator Gain { get; private set; }
  15.  
  16.         [ParameterDecl(ValueDescriptions = new[] { "no", "yes" })]
  17.         public bool Bypass { get; set; }
  18.  
  19.         public Sample Work(Sample s)
  20.         {
  21.             return Bypass ? s : s * Gain.Tick();
  22.         }
  23.  
  24.         public class State : INotifyPropertyChanged
  25.         {
  26.             public State() { text = "here is state"; }  // NOTE: parameterless constructor is required by the xml serializer
  27.  
  28.             string text;
  29.             public string Text
  30.             {
  31.                 get { return text; }
  32.                 set
  33.                 {
  34.                     text = value;
  35.                     if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Text"));
  36.                 }
  37.             }
  38.  
  39.             public event PropertyChangedEventHandler PropertyChanged;
  40.         }
  41.  
  42.         public State MachineState { get; set; }     // a property called 'MachineState' gets automatically saved in songs and presets
  43.     }
  44.  
  45.     public class MachineGUIFactory : IMachineGUIFactory { public IMachineGUI CreateGUI(IMachineGUIHost host) { return new GainGUI(); } }
  46.     public class GainGUI : UserControl, IMachineGUI
  47.     {
  48.         IMachine machine;
  49.         GainMachine gainMachine;
  50.         TextBox tb;
  51.  
  52.         public IMachine Machine
  53.         {
  54.             get { return machine; }
  55.             set
  56.             {
  57.                 machine = value;
  58.                 if (machine != null)
  59.                 {
  60.                     gainMachine = (GainMachine)machine.ManagedMachine;
  61.                     tb.SetBinding(TextBox.TextProperty, new Binding("Text") { Source = gainMachine.MachineState, Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged });
  62.                 }
  63.             }
  64.         }
  65.  
  66.         public GainGUI()
  67.         {
  68.             this.Content = tb = new TextBox() { Margin = new Thickness(0, 0, 0, 4) };
  69.         }
  70.  
  71.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement