Skip to content

Commit

Permalink
Use Types
Browse files Browse the repository at this point in the history
  • Loading branch information
Kermalis committed Aug 15, 2018
1 parent 8160e9e commit ca52edb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 24 deletions.
4 changes: 3 additions & 1 deletion GBAMusicStudio/Core/MusicStructs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ internal class M4AVoice : IVoice
internal byte Sweep; // Square1

[FieldOffset(4)]
internal byte Pattern; // Square1, Square2, Noise
internal SquarePattern SquarePattern; // Square1, Square2
[FieldOffset(4)]
internal NoisePattern NoisePattern; // Noise
[FieldOffset(4)]
internal uint Address; // Direct, Wave
[FieldOffset(4)]
Expand Down
4 changes: 2 additions & 2 deletions GBAMusicStudio/Core/SongEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ internal class ModTypeCommand : ICommand
{
public string Name => "MOD Type";

MODT type;
public byte Type { get => (byte)type; set => type = (MODT)value.Clamp((byte)MODT.Vibrate, (byte)MODT.Panpot); }
MODType type;
public byte Type { get => (byte)type; set => type = (MODType)value.Clamp((byte)MODType.Vibrate, (byte)MODType.Panpot); }

public string Arguments => type.ToString();
}
Expand Down
8 changes: 4 additions & 4 deletions GBAMusicStudio/Core/SongPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ internal static void PlayNote(Track track, sbyte note, byte velocity, int durati
case 0x9:
SoundMixer.NewGBNote(owner, m4avoice.ADSR, aNote,
track.GetVolume(), track.GetPan(), track.GetPitch(),
GBType.Square1, m4avoice.Pattern);
GBType.Square1, m4avoice.SquarePattern);
break;
case 0x2:
case 0xA:
SoundMixer.NewGBNote(owner, m4avoice.ADSR, aNote,
track.GetVolume(), track.GetPan(), track.GetPitch(),
GBType.Square2, m4avoice.Pattern);
GBType.Square2, m4avoice.SquarePattern);
break;
case 0x3:
case 0xB:
Expand All @@ -203,7 +203,7 @@ internal static void PlayNote(Track track, sbyte note, byte velocity, int durati
case 0xC:
SoundMixer.NewGBNote(owner, m4avoice.ADSR, aNote,
track.GetVolume(), track.GetPan(), track.GetPitch(),
GBType.Noise, m4avoice.Pattern);
GBType.Noise, m4avoice.NoisePattern);
break;
}
}
Expand Down Expand Up @@ -273,7 +273,7 @@ static bool ExecuteNext(int i)
else if (e.Command is LFOSpeedCommand lfos) { track.LFOSpeed = lfos.Speed; track.LFOPhase = track.LFODelayCount = 0; update = true; }
else if (e.Command is LFODelayCommand lfodl) { track.LFODelay = lfodl.Delay; track.LFOPhase = track.LFODelayCount = 0; update = true; }
else if (e.Command is ModDepthCommand mod) { track.MODDepth = mod.Depth; update = true; }
else if (e.Command is ModTypeCommand modt) { track.MODType = (MODT)modt.Type; update = true; }
else if (e.Command is ModTypeCommand modt) { track.MODType = (MODType)modt.Type; update = true; }
else if (e.Command is TuneCommand tune) { track.Tune = tune.Tune; update = true; }
else if (e.Command is LibraryCommand xcmd)
{
Expand Down
12 changes: 3 additions & 9 deletions GBAMusicStudio/Core/SoundMixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,20 @@ internal static void NewDSNote(byte owner, ADSR env, Note note, byte vol, sbyte
}
internal static void NewGBNote(byte owner, ADSR env, Note note, byte vol, sbyte pan, int pitch, GBType type, object arg)
{
T ObjToEnum<T>(object o)
{
T enumVal = (T)Enum.Parse(typeof(T), o.ToString());
return enumVal;
}

GBChannel nChn;
switch (type)
{
default:
nChn = sq1;
if (nChn.State < ADSRState.Releasing && nChn.OwnerIdx < owner)
return;
sq1.Init(owner, note, env, ObjToEnum<SquarePattern>(arg));
sq1.Init(owner, note, env, (SquarePattern)arg);
break;
case GBType.Square2:
nChn = sq2;
if (nChn.State < ADSRState.Releasing && nChn.OwnerIdx < owner)
return;
sq2.Init(owner, note, env, ObjToEnum<SquarePattern>(arg));
sq2.Init(owner, note, env, (SquarePattern)arg);
break;
case GBType.Wave:
nChn = wave;
Expand All @@ -144,7 +138,7 @@ T ObjToEnum<T>(object o)
nChn = noise;
if (nChn.State < ADSRState.Releasing && nChn.OwnerIdx < owner)
return;
noise.Init(owner, note, env, ObjToEnum<NoisePattern>(arg));
noise.Init(owner, note, env, (NoisePattern)arg);
break;
}
nChn.SetVolume(vol, pan);
Expand Down
10 changes: 5 additions & 5 deletions GBAMusicStudio/Core/Track.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal class Track
LFOPhase, LFODelayCount, BendRange,
LFOSpeed, LFODelay, MODDepth,
EchoVolume, EchoLength; // Unused for now
internal MODT MODType;
internal MODType MODType;
internal sbyte Bend, Tune, Pan, KeyShift, PrevNote;
internal int CommandIndex, EndOfPattern;
internal bool Ready, Stopped;
Expand All @@ -23,17 +23,17 @@ int Tri(int index)

internal int GetPitch()
{
int mod = MODType == MODT.Vibrate ? (Tri(LFOPhase) * MODDepth) >> 8 : 0;
int mod = MODType == MODType.Vibrate ? (Tri(LFOPhase) * MODDepth) >> 8 : 0;
return Bend * BendRange + Tune + mod;
}
internal byte GetVolume()
{
int mod = MODType == MODT.Volume ? (Tri(LFOPhase) * MODDepth * 3 * Volume) >> 19 : 0;
int mod = MODType == MODType.Volume ? (Tri(LFOPhase) * MODDepth * 3 * Volume) >> 19 : 0;
return (byte)(Volume + mod).Clamp(0, Engine.GetMaxVolume());
}
internal sbyte GetPan()
{
int mod = MODType == MODT.Panpot ? (Tri(LFOPhase) * MODDepth * 3) >> 12 : 0;
int mod = MODType == MODType.Panpot ? (Tri(LFOPhase) * MODDepth * 3) >> 12 : 0;
byte range = Engine.GetPanpotRange();
return (sbyte)(Pan + mod).Clamp(-range, range - 1);
}
Expand All @@ -44,7 +44,7 @@ internal virtual void Init()
Voice = Priority = Delay = LFODelay = LFODelayCount = LFOPhase = MODDepth = EchoVolume = EchoLength = 0;
Bend = Tune = Pan = KeyShift = 0;
CommandIndex = EndOfPattern = 0;
MODType = MODT.Vibrate;
MODType = MODType.Vibrate;
Ready = true;
Stopped = false;
BendRange = 2;
Expand Down
6 changes: 3 additions & 3 deletions GBAMusicStudio/Core/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ internal enum EngineType { M4A, MLSS }
internal enum ADSRState { Initializing, Rising, Decaying, Playing, Releasing, Dying, Dead }
internal enum PlayerState { Stopped, Playing, Paused, ShutDown }

internal enum MODT : byte { Vibrate, Volume, Panpot }
internal enum SquarePattern : byte { D12, D25, D50, D75 }
internal enum NoisePattern : byte { Fine, Rough }
internal enum MODType : byte { Vibrate, Volume, Panpot }
internal enum GBType { Square1, Square2, Wave, Noise }
internal enum ReverbType { None, Normal }
internal enum SquarePattern : byte { D12, D25, D50, D75 }
internal enum NoisePattern : byte { Fine, Rough }


internal struct ChannelVolume
Expand Down

0 comments on commit ca52edb

Please sign in to comment.