示例#1
0
    void OnEnable()
    {
        SongStructure.Initialize();
        HarmonicProgression.Initialize(sequencer.numBars);

        sequencer.Play(AudioSettings.dspTime + 3.0f);
    }
示例#2
0
 public static int GetHarmonic(int section, int barIndex)
 {
     int[] progression = null;
     if (progressions.TryGetValue(SongStructure.GetSection(section), out progression))
     {
         return(progression[barIndex]);
     }
     return(0);
 }
示例#3
0
    protected override void OnNextBeat(int section, int bar, int beat, double dspTime, double beatTime)
    {
        if (bar == 0 && beat == 0)
        {
            sectionType = SongStructure.GetSection(section);
        }
        if (sectionType == SectionType.OUTRO && drumType != DrumType.CLAP)
        {
            return;
        }
        int augmentedBeat = 2 * (bar * 4 + beat);

        for (int i = 0; i < 2; ++i)
        {
            float volume = 1.0f;
            float p      = RandomNumber.NextFloat(0.0f, 1.0f);
            bool  play   = false;
            switch (drumType)
            {
            case DrumType.KICK:
                play = p < 0.0025f || (p < 0.97f && augmentedBeat % 8 == 0);
                break;

            case DrumType.SNARE:
                play = p < 0.0025f || augmentedBeat % 8 == 4;
                if (augmentedBeat % 8 != 4)
                {
                    volume = RandomNumber.NextFloat(0.75f, 1.0f);
                }
                break;

            case DrumType.CLAP:
                play = p < 0.0025f || augmentedBeat % 8 == 4;
                break;

            case DrumType.HH_CLOSED:
                play = p < 0.001f || augmentedBeat % 4 == 2 || (sectionType == SectionType.CHORUS && augmentedBeat % 2 == 0 && p < 0.9f);
                if (augmentedBeat % 4 != 2)
                {
                    volume = RandomNumber.NextFloat(0.75f, 1.0f);
                }
                break;

            case DrumType.HH_OPEN:
                play = augmentedBeat % 32 == 0;
                break;
            }
            if (play)
            {
                double playTime = dspTime + i * 0.5 * beatTime;
                instrument.PlayNote(playTime, 0, volume);
            }
            ++augmentedBeat;
        }
    }
示例#4
0
 private void OnNextBeat(int section, int bar, int beat, double dspTime, double beatTime)
 {
     if (bar == 0 && beat == 0)
     {
         sectionType = SongStructure.GetSection(section);
         if (sectionType == SectionType.CHORUS && PerformerSelector.numPerformers > 5)
         {
             //source.clip = crash[index];
             source.PlayScheduled(dspTime);
             //index = (index + 1) % crash.Length;
         }
     }
 }
示例#5
0
 protected override void Awake()
 {
     base.Awake();
     lines = new Dictionary <SectionType, Dictionary <int, int> >();
     for (int i = 0; i < SongStructure.Length(); ++i)
     {
         var section = SongStructure.GetSection(i);
         if (!lines.ContainsKey(section))
         {
             lines.Add(section, new Dictionary <int, int>());
         }
     }
 }
示例#6
0
    protected override void OnNextBeat(int section, int bar, int beat, double dspTime, double beatTime)
    {
        SectionType sectionType = SongStructure.GetSection(section);

        if (beat == beatOffset || (sectionType == SectionType.CHORUS && beat == ((beatOffset + 2) % 4)))
        {
            lastNote += RandomNumber.NextInt(-Scale.scaleLength / 4, Scale.scaleLength / 2);
            lastNote  = System.Math.Max(-Scale.scaleLength / 4, System.Math.Min(Scale.scaleLength, lastNote));

            Dictionary <int, int> sectionLines = null;
            if (lines.TryGetValue(sectionType, out sectionLines))
            {
                int key       = bar * numBeats + beat;
                int noteIndex = 0;
                if (!sectionLines.TryGetValue(key, out noteIndex))
                {
                    noteIndex = HarmonicProgression.GetHarmonic(section, bar) + lastNote;
                    sectionLines.Add(key, noteIndex);
                }
                instrument.PlayNote(dspTime, noteIndex, RandomNumber.NextFloat(0.9f, 1.0f));
            }
        }
    }
示例#7
0
    public static void Initialize(int numBars)
    {
        markov       = new MarkovChain(8, 1);
        progressions = new Dictionary <SectionType, int[]>();

        for (int i = 0; i < SongStructure.Length(); ++i)
        {
            var section = SongStructure.GetSection(i);
            if (!progressions.ContainsKey(section))
            {
                if (section != SectionType.BRIDGE)
                {
                    markov.Reset();
                }
                int[] progression = new int[numBars];
                for (int bar = 0; bar < numBars; ++bar)
                {
                    progression[bar] = markov.CurrentState;
                    markov.GenerateNextState();
                }
                progressions.Add(section, progression);
            }
        }
    }