예제 #1
0
파일: Motif.cs 프로젝트: amulware/yatl
 public override IEnumerable <SoundEvent> Render(RenderParameters parameters, double start = 0)
 {
     // First generate arpeggios
     // Then render the other notes
     //return voices.Render(parameters);
     foreach (var e in this.GenerateArpeggios(parameters).Concat(voices.Render(parameters, start)))
     {
         yield return(e);
     }
 }
예제 #2
0
 public override IEnumerable <SoundEvent> Render(RenderParameters parameters, double start = 0)
 {
     foreach (var child in this.Content)
     {
         foreach (var soundEvent in child.Render(parameters, start))
         {
             yield return(soundEvent);
         }
         start += child.Duration;
     }
 }
예제 #3
0
        public override IEnumerable <SoundEvent> Render(RenderParameters parameters, double start = 0)
        {
            // Number of voices depends on density
            int number = Math.Max(2, (int)Math.Round(this.Content.Length * parameters.MusicParameters.Tension));

            foreach (var child in this.Content.Take(number))
            {
                foreach (var soundEvent in child.Render(parameters, start))
                {
                    soundEvent.MultiplyOffset(this.durationMultiplier);
                    yield return(soundEvent);
                }
            }
        }
예제 #4
0
        public override IEnumerable <SoundEvent> Render(RenderParameters parameters, double start)
        {
            var on = new NoteOn(start, parameters.Instrument, this.Frequency);

            yield return(on);

            var off = new NoteOff(start + this.Duration, on);

            yield return(off);

            // Extra octave depends on density
            //if (MusicManager.Random.NextDouble() < parameters.Density) {
            //    var startOctave = new NoteOn(0, parameters.Instrument, this.Frequency * 2, parameters.Volume);
            //    yield return startOctave;
            //    var endOctave = new NoteOff(this.Duration, startOctave);
            //    yield return endOctave;
            //}
        }
예제 #5
0
        void scheduleNextMotif()
        {
            if (this.currentMotif == null)
            {
                this.currentMotif = this.composition.Motifs["light1a"];
            }
            else
            {
                if (this.Parameters.GameOverState == GameState.GameOverState.Won)
                {
                    var win = this.currentMotif.Successors.Where(o => o.Name.Contains("win")).ToList();
                    if (win.Count() != 0)
                    {
                        this.currentMotif = win[0];
                        goto Rendering;
                    }
                }
                else if (this.Parameters.GameOverState == GameState.GameOverState.Lost)
                {
                    var lose = this.currentMotif.Successors.Where(o => o.Name.Contains("lose")).ToList();
                    if (lose.Count() != 0)
                    {
                        this.currentMotif = lose[0];
                        goto Rendering;
                    }
                }

                string tag         = this.Parameters.Lightness > .5 ? "light" : "dark";
                var    choiceSpace = this.currentMotif.Successors.Where(o => o.Name.Contains(tag));
                if (choiceSpace.Count() == 0)
                {
                    choiceSpace = this.currentMotif.Successors;
                }
                this.currentMotif = choiceSpace.RandomElement();
            }
Rendering:
            RenderParameters parameters = new RenderParameters(this.Parameters, this.Piano);

            this.Schedule(this.currentMotif.Render(parameters));
        }
예제 #6
0
 public abstract IEnumerable <SoundEvent> Render(RenderParameters parameters, double start = 0);
예제 #7
0
파일: Motif.cs 프로젝트: amulware/yatl
        public IEnumerable <SoundEvent> GenerateArpeggios(RenderParameters parameters)
        {
            double start = 0;

            foreach (var basenote in this.voices.Content[1].Content)
            {
                double end = start + basenote.Duration;
                yield return(new LiftSustain(start));     // Lift sustain before each chord

                yield return(new BiteOpportunity(start)); // Have a bit opportunity for each chord

                yield return(new BiteOpportunityEnd(start + 0.1));

                // Gather arpeggio set
                var arpeggioSpace = new List <Pitch>();
                foreach (var voice in this.voices.Content)
                {
                    foreach (var pitch in voice.GetPosition(start).Select(note => note.Pitch))
                    {
                        if (pitch.Frequency > 0)
                        {
                            arpeggioSpace.Add(pitch);
                            arpeggioSpace.Add(pitch.NextOctave());
                            arpeggioSpace.Add(pitch.PreviousOctave());
                        }
                    }
                }
                arpeggioSpace = arpeggioSpace.OrderBy(o => o.Frequency).ToList();

                int density = (int)Math.Round(2 * parameters.MusicParameters.Tension + 1);

                IEnumerable <int> pattern;
                int tonesPerChord;
                if (density == 1)
                {
                    pattern       = new int[] { 1 };
                    tonesPerChord = 3;
                }
                else if (density == 2)
                {
                    pattern       = new int[] { 1, -1 };
                    tonesPerChord = 6;
                }
                else
                {
                    pattern       = new int[] { 1, -1, 1 };
                    tonesPerChord = 12;
                }
                int    tonesPerStroke = tonesPerChord / pattern.Count();
                double duration       = basenote.Duration / (double)(tonesPerChord);

                //Console.WriteLine("pattern: " + string.Join(", ", pattern.Select(o => o.ToString())));
                //Console.WriteLine("duration: " + duration.ToString());

                // Select tones
                IEnumerable <Note> arpeggio = this.SelectArpeggioSequence(arpeggioSpace, pattern, tonesPerStroke, duration);

                // Render and yield arpeggio
                foreach (var e in (new Serial(arpeggio.ToArray())).Render(parameters, start))
                {
                    yield return(e);
                }

                start = end;
                yield return(new StartRubato(start - 0.1)); // Some articulation just before the next chord
            }
        }