Advertisement
Guest User

Untitled

a guest
May 26th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.98 KB | None | 0 0
  1. using GBAMusic.Util;
  2.  
  3. namespace GBAMusic.Core.M4A
  4. {
  5.     internal class Track : ROMReader
  6.     {
  7.         internal readonly FMOD.ChannelGroup Group;
  8.         internal readonly ThreadSafeList<Instrument> Instruments; // Instruments being played by this track
  9.         readonly FMOD.DSP Mod2;
  10.  
  11.         internal byte Voice, Volume, Priority,
  12.             Delay,
  13.             RunCmd, PrevNote, PrevVelocity,
  14.             BendRange, MODDepth, MODType;
  15.         internal sbyte Bend, Pan;
  16.         internal bool Stopped;
  17.         internal uint EndOfPattern;
  18.  
  19.         internal Track(FMOD.System system, FMOD.ChannelGroup parentGroup) : base()
  20.         {
  21.             Instruments = new ThreadSafeList<Instrument>();
  22.             system.createChannelGroup(null, out Group);
  23.             parentGroup.addGroup(Group, false, out FMOD.DSPConnection c);
  24.  
  25.             system.createDSPByType(FMOD.DSP_TYPE.TREMOLO, out Mod2);
  26.             Group.addDSP(2, Mod2);
  27.         }
  28.  
  29.         internal void Init(uint offset)
  30.         {
  31.             InitReader();
  32.             SetOffset(offset);
  33.             Voice = Volume = Priority
  34.                 = Delay
  35.                 = RunCmd = PrevNote = PrevVelocity
  36.                 = MODDepth = MODType = 0;
  37.             Bend = Pan = 0;
  38.             BendRange = 2;
  39.             Stopped = false;
  40.             EndOfPattern = 0;
  41.         }
  42.         internal void Tick()
  43.         {
  44.             foreach (Instrument i in Instruments)
  45.                 i.Tick();
  46.             if (Delay != 0)
  47.                 Delay--;
  48.         }
  49.  
  50.         void UpdateFrequencies()
  51.         {
  52.             foreach (Instrument i in Instruments)
  53.                 i.UpdateFrequency();
  54.         }
  55.         void UpdatePanpots()
  56.         {
  57.             foreach (Instrument i in Instruments)
  58.                 i.UpdatePanpot();
  59.         }
  60.         void UpdateModulation()
  61.         {
  62.             float depth = MODDepth / 127f;
  63.             switch (MODType)
  64.             {
  65.                 case 2: Mod2.setParameterFloat((int)FMOD.DSP_TREMOLO.DEPTH, depth); break;
  66.             }
  67.         }
  68.  
  69.         internal void SetVolume(byte b)
  70.         {
  71.             Volume = b;
  72.             Group.setVolume(b / 127f);
  73.         }
  74.         internal void SetPan(byte b)
  75.         {
  76.             Pan = (sbyte)(b - 64);
  77.             UpdatePanpots();
  78.         }
  79.         internal void SetBend(byte b)
  80.         {
  81.             Bend = (sbyte)(b - 64);
  82.             UpdateFrequencies();
  83.         }
  84.         internal void SetBendRange(byte b)
  85.         {
  86.             BendRange = b;
  87.             UpdateFrequencies();
  88.         }
  89.         internal void SetMODDepth(byte b)
  90.         {
  91.             MODDepth = b;
  92.             UpdateModulation();
  93.         }
  94.         internal void SetMODType(byte b)
  95.         {
  96.             MODType = b;
  97.             UpdateModulation();
  98.         }
  99.         internal void SetPriority(byte b)
  100.         {
  101.             Priority = b;
  102.             foreach (Instrument i in Instruments)
  103.                 i.Channel.setPriority(b);
  104.         }
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement