Esempio n. 1
0
        private void OnBeatEvent(BeatEvent beatEvent)
        {
            Queue <AcademicChord> academicChordsQueue = context.academicChordsQueue;
            PlayableSoundQueue    queue = context.playableSoundQueue;

            while (queue.count < MAX_QUEUE_SIZE && academicChordsQueue.Count > 0)
            {
                AcademicChord academicChord     = academicChordsQueue.Dequeue();
                PlayableSound lastSound         = queue.GetLastSound();
                int           timeQuantumNumber = beatEvent.timeQuantumNumber;
                if (lastSound != null)
                {
                    timeQuantumNumber = lastSound.startTimeQuantumNumber + lastSound.durationTimeQuanta;
                }

                float volume = beatEvent.isStrong ? 1f : 0.75f;
                for (int i = 0; i < academicChord.notes.Length; ++i)
                {
                    Note  chordNote = academicChord.notes[i];
                    Pitch pitch     = new Pitch(chordNote, (i == 0 || chordNote > academicChord.notes[0]) ? 4 : 5);
                    queue.AddSound(new PlayableSound(pitch, volume, timeQuantumNumber, context.beatManager.timeQuantaPerBeat));
                }
            }

            if (queue.count < MAX_QUEUE_SIZE && academicChordsQueue.Count == 0)
            {
                Debug.LogWarning("Playable sounds queue is not full, but academic chords queue is empty");
            }
        }
        private void OnBeatEvent(BeatEvent beatEvent)
        {
            Queue <AcademicChord> academicChordsQueue = context.academicChordsQueue;
            PlayableSoundQueue    queue = context.playableSoundQueue;

            while (queue.count < MAX_QUEUE_SIZE && academicChordsQueue.Count > 0)
            {
                AcademicChord academicChord     = academicChordsQueue.Dequeue();
                PlayableSound lastSound         = queue.GetLastSound();
                int           timeQuantumNumber = beatEvent.timeQuantumNumber;
                if (lastSound != null)
                {
                    timeQuantumNumber = lastSound.startTimeQuantumNumber + lastSound.durationTimeQuanta;
                }

                List <Pitch> pitches = new List <Pitch>
                {
                    new Pitch(academicChord.notes[0], 4),
                    new Pitch(academicChord.notes[1], academicChord.notes[1] > academicChord.notes[0] ? 4 : 5),
                    new Pitch(academicChord.notes[2], academicChord.notes[2] > academicChord.notes[0] ? 4 : 5),
                };

                List <int> indices = GetIndices(pitches.Count, context.beatManager.timeQuantaPerBeat / SOUND_DURATION_TIME_QUANTA);
                bool       strong  = true;
                foreach (int index in indices)
                {
                    float volume = strong ? 1f : 0.5f;
                    strong = false;
                    queue.AddSound(new PlayableSound(pitches[index], volume, timeQuantumNumber, SOUND_DURATION_TIME_QUANTA));
                    timeQuantumNumber += SOUND_DURATION_TIME_QUANTA;
                }
            }

            if (queue.count < MAX_QUEUE_SIZE && academicChordsQueue.Count == 0)
            {
                Debug.LogWarning("Playable sounds queue is not full, but academic chords queue is empty");
            }
        }
Esempio n. 3
0
        private void OnBeatEvent(BeatEvent beatEvent)
        {
            Queue <AcademicChord> academicChordsQueue = context.academicChordsQueue;
            PlayableSoundQueue    queue = context.playableSoundQueue;

            while (queue.count < MAX_QUEUE_SIZE && academicChordsQueue.Count > 0)
            {
                AcademicChord academicChord     = academicChordsQueue.Dequeue();
                PlayableSound lastSound         = queue.GetLastSound();
                int           timeQuantumNumber = beatEvent.timeQuantumNumber;
                if (lastSound != null)
                {
                    timeQuantumNumber = lastSound.startTimeQuantumNumber + lastSound.durationTimeQuanta;
                }

                int   beatCounter = timeQuantumNumber / context.beatManager.timeQuantaPerBeat;
                bool  isStrong    = beatCounter % context.beatManager.measure == 0;
                float volume      = isStrong ? 1f : 0.75f;

                if (_useMelody)
                {
                    for (int i = 0; i < academicChord.notes.Length; ++i)
                    {
                        Note  chordNote = academicChord.notes[i];
                        Pitch pitch     = new Pitch(chordNote, (i == 0 || chordNote > academicChord.notes[0]) ? 4 : 5);
                        queue.AddSound(new PlayableSound(pitch, volume, timeQuantumNumber, context.beatManager.timeQuantaPerBeat));
                    }
                }

                if (_useBass)
                {
                    Pitch bass = new Pitch(academicChord.notes[0], 2);
                    queue.AddSound(new PlayableSound(bass, volume, timeQuantumNumber, context.beatManager.timeQuantaPerBeat));
                }

                if (_useCounterMelody)
                {
                    List <Pitch> arpeggioPitches = new List <Pitch>();
                    for (int i = 0; i < academicChord.notes.Length; ++i)
                    {
                        Note chordNote = academicChord.notes[i];
                        arpeggioPitches.Add(new Pitch(chordNote, (i == 0 || chordNote > academicChord.notes[0]) ? 6 : 7));
                    }
                    ;

                    const int  arpeggioNoteDurationTimeQuanta = 8;
                    List <int> indices = GetIndices(arpeggioPitches.Count, context.beatManager.timeQuantaPerBeat / arpeggioNoteDurationTimeQuanta);
                    int        arpeggioTimeQuantumNumber = timeQuantumNumber;
                    foreach (int index in indices)
                    {
                        queue.AddSound(new PlayableSound(arpeggioPitches[index], volume, arpeggioTimeQuantumNumber, arpeggioNoteDurationTimeQuanta));
                        arpeggioTimeQuantumNumber += arpeggioNoteDurationTimeQuanta;
                    }
                }
            }

            if (queue.count < MAX_QUEUE_SIZE && academicChordsQueue.Count == 0)
            {
                Debug.LogWarning("Playable sounds queue is not full, but academic chords queue is empty");
            }
        }