Skip to content

Commit

Permalink
misc unity cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
anokta committed Nov 17, 2024
1 parent 8b490f1 commit 4ebbce2
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 90 deletions.
18 changes: 10 additions & 8 deletions platforms/unity/Assets/BarelyMusician/Scripts/Instrument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,6 @@ public static void OnNoteOnEvent(Instrument instrument, double pitch, double int

private void Awake() {
Source = GetComponent<AudioSource>();
Source.clip = AudioClip.Create("[DO NOT EDIT]", 64, 1, AudioSettings.outputSampleRate, false);
float[] ones = new float[64];
for (int i = 0; i < ones.Length; ++i) {
ones[i] = 1.0f;
}
Source.clip.SetData(ones, 0);
Source.loop = true;
}

Expand All @@ -272,13 +266,21 @@ private void OnDestroy() {
private void OnEnable() {
Musician.Internal.Instrument_Create(this, ref _handle);
OnInstrumentCreate?.Invoke();
Source?.Play();
Source.clip = AudioClip.Create("[DO NOT EDIT]", 64, 1, AudioSettings.outputSampleRate, false);
float[] ones = new float[64];
for (int i = 0; i < ones.Length; ++i) {
ones[i] = 1.0f;
}
Source.clip.SetData(ones, 0);
Source.Play();
}

private void OnDisable() {
Source?.Stop();
Source.Stop();
Source.clip = null;
OnInstrumentDestroy?.Invoke();
Musician.Internal.Instrument_Destroy(ref _handle);
_sliceCount = 0;
}

private void Update() {
Expand Down
Loading

0 comments on commit 4ebbce2

Please sign in to comment.