public void PlaySyllable(int Index) { //Debug.Log("playing syllable index " + Index); syllables[Index].SetNewDefaults(); AudioClip clip = baseClip; if ((instrumentMode == InstrumentMode.Random || (instrumentMode == InstrumentMode.Custom && syllables[Index].useRandomClip)) && randomClips.Length > 0) { clip = randomClips[Random.Range(0, randomClips.Length - 1)]; } else if (instrumentMode == InstrumentMode.Custom && syllables[Index].clip != null) { clip = syllables[Index].clip; } else if (instrumentMode == InstrumentMode.Ordered && orderedClips.Count() > 0) { clip = orderedClips[(int)Mathf.Repeat(Index, orderedClips.Count())]; } float syllableVolume = volume; if (instrumentMode == InstrumentMode.Custom) { syllableVolume *= syllables[Index].localVolume; } AudioSource baseAudioSource = audioEffects_enabled ? audioEffects_source : null; if (clip != null) { MusicalDialogMidiEvent e = midiEvents[(int)Mathf.PingPong(Index, midiEvents.Count - 1)]; if (useMidi && midiEvents.Count > 0) { foreach (int note in e.notes) { AudioSource ass = SoundManager.instance.PlayClipOnPlayer(clip, syllableVolume, baseAudioSource); int transposedNote = note - (int)baseNote; transposedNote += pitchSemitones; ass.name = "_TempAudio " + clip.name + " note " + (AudioSynthesis.Midi.NotePitch)transposedNote; ass.pitch = Mathf.Pow(2, (transposedNote) / 12.0f); } } else { SoundManager.instance.PlayClipOnPlayer(clip, syllableVolume, baseAudioSource); } //Debug.Log("Playing note# " + Index + ": value " + note + /*" pitch " + Tables.SemitoneTable[note] +*/ " (source pitch: " + testAudio.pitch + ")"); } }
public void ParseMidiFile() { midiEvents.Clear(); if (midiFile == null) { return; } if (string.IsNullOrEmpty(_editor_midiFile_path)) { Debug.LogError("Midi path is empty"); return; } MidiFile mf = new MidiFile(new MidiSimpleFile(_editor_midiFile_path)); mf.CombineTracks(); foreach (MidiTrack t in mf.Tracks) { foreach (MidiEvent e in t.MidiEvents) { if ((MidiEventTypeEnum)e.Command == MidiEventTypeEnum.NoteOn) { //Debug.Log("Note dt " + e.DeltaTime + " at " + e.AbsoluteTime + ": " + e.Data1 + " (" + System.Enum.GetName(typeof(ControllerTypeEnum), e.Data1) + ") " + e.ToString()); // check if last note uses the same time (NOTE: This assumes the notes come in order, TODO: make sure this is true) if (midiEvents.Count > 0 && midiEvents.Last().time == e.AbsoluteTime) { midiEvents.Last().notes.Add(e.Data1); } else { MusicalDialogMidiEvent musicalEvent = new MusicalDialogMidiEvent(); musicalEvent.time = e.AbsoluteTime; musicalEvent.notes.Add(e.Data1); midiEvents.Add(musicalEvent); } } } } }