Esempio n. 1
0
        private void CreateBar(waveform form, BarType barType)
        {
            List <NoteType> notesInBar = new List <NoteType>();

            int[] pitchIndexes;
            if (currentBar == 1)
            {
                notesInBar   = barMaker.BarNotes(barType);
                pitchIndexes = pitcher.GenerateNotes(barType, rootInScale + (scale.Length / 3), previousNote, notesInBar.Count, scale.Length);
            }
            else if (currentBar == totalBars)
            {
                notesInBar   = barMaker.BarNotes(barType);
                pitchIndexes = pitcher.GenerateNotes(barType, rootInScale + (scale.Length / 3), previousNote, notesInBar.Count, scale.Length);
            }
            else
            {
                notesInBar   = barMaker.BarNotes(barType);
                pitchIndexes = pitcher.GenerateNotes(barType, rootInScale + (scale.Length / 3), previousNote, notesInBar.Count, scale.Length);
            }
            previousNote = pitchIndexes.Last <int>();
            for (int i = 0; i < notesInBar.Count; ++i)
            {
                float noteDuration = noteDurations[(int)notesInBar[i]];
                buffer.AddRange(noteOutput.NoteFromA3(scale[pitchIndexes[i]], noteDuration, form));
            }
            currentBar++;
        }
Esempio n. 2
0
 public List <float> CreateTrack(int phrases, waveform form, int seed)
 {
     givenSeed     = seed;
     barMaker.Seed = seed;
     pitcher.Seed  = seed;
     previousNote  = rootInScale;
     totalBars     = phrases * 4;
     CreateStructure(phrases);
     for (int i = 0; i < phrases; ++i)
     {
         CreateFour(form, i, phrases);
     }
     return(buffer);
 }
Esempio n. 3
0
        public List <float> NoteFromA3(int interval, float duration, waveform form)
        {
            List <float> buff = new List <float>();

            for (int i = 0; i < 44100 * duration; i++)
            {
                // Time value for the oscilator might need tweaking
                switch (form)
                {
                case waveform.sine:
                    buff.Add(Oscillator.Sine(notes[interval], i / 44100.0f));
                    break;

                case waveform.sawtooth:
                    buff.Add(Oscillator.SawTooth(notes[interval], i / 44100.0f));
                    break;

                case waveform.square:
                    buff.Add(Oscillator.Square(notes[interval], i / 44100.0f));
                    break;

                case waveform.triangle:
                    buff.Add(Oscillator.Triangle(notes[interval], i / 44100.0f));
                    break;

                default:
                    break;
                }

                // fade in fade out
                if (i < fadeTime)
                {
                    buff[i] *= (i / (float)fadeTime);
                }
                if (44100.0f * duration - i < fadeTime)
                {
                    buff[i] *= ((44100.0f * duration - i) / (float)fadeTime);
                }
            }

            // test
            //   buff = MixerClass.AddAttack(buff);

            return(buff);
        }
Esempio n. 4
0
        private void CreateFour(waveform form, int phraseNumber, int phrases)
        {
            List <BarType> currentPhrase = phraseStructure[structure[phraseNumber]];

            for (int i = 0; i < 4; ++i)
            {
                if (phraseNumber == 0 && i == 0)
                {
                    CreateBar(form, BarType.Start);
                }
                else if (phraseNumber == phrases - 1 && i == 3)
                {
                    CreateBar(form, BarType.End);
                }
                else
                {
                    CreateBar(form, currentPhrase[i]);
                }
            }
        }
Esempio n. 5
0
        public List <float> makeTrack(int[] scale, int keyIndex, float tempo, int nOf4Bars, waveform form, float timeSignature, float seed)
        {
            int[] wrapped;
            wrapped = getIndexes(keyIndex, scale, scale.Length / 3);
            List <float>  buffer   = new List <float>();
            List <float>  fourBars = new List <float>();
            NoteGenerator ng       = new NoteGenerator();
            Random        r        = new Random((int)(seed * 10000.0f));

            for (int i = 0; i < 4; i++)
            {
                fourBars.AddRange(ng.NoteFromA3(wrapped[r.Next(5)], (60 / tempo) * timeSignature * 4.0f, form));
            }
            for (int i = 0; i < nOf4Bars; i++)
            {
                buffer.AddRange(fourBars);
            }
            return(buffer);
        }