Example #1
0
 public void FillOctave(string NoteInfo)
 {
     if (NoteInfo.IndexOf('l') != -1)
     {
         TheOctave = Octave.low;
     }
     if (NoteInfo.IndexOf('m') != -1)
     {
         TheOctave = Octave.middle;
     }
     if (NoteInfo.IndexOf('h') != -1)
     {
         TheOctave = Octave.high;
     }
     if (NoteInfo.IndexOf('+') != -1)
     {
         TheOctave              = Octave.middle;
         octaveOutOfRange       = true;
         octaveOutOfRangeOffset = NoteInfo.Substring(NoteInfo.IndexOf('+'), 2);
     }
     if (NoteInfo.IndexOf('-') != -1)
     {
         TheOctave              = Octave.middle;
         octaveOutOfRange       = true;
         octaveOutOfRangeOffset = NoteInfo.Substring(NoteInfo.IndexOf('-'), 2);
     }
 }
Example #2
0
        public Pitch Map(NoteEvent noteEvent)
        {
            var octave = Octave.OfNumber(noteEvent.NoteNumber / Const.SemitonesInOctave - 1);

            switch (noteEvent.NoteNumber % Const.SemitonesInOctave)
            {
            case 0: return(MakeNatural(PitchClass.C, octave));

            case 1: return(MakeSharp(PitchClass.C, octave));

            case 2: return(MakeNatural(PitchClass.D, octave));

            case 3: return(MakeSharp(PitchClass.D, octave));

            case 4: return(MakeNatural(PitchClass.E, octave));

            case 5: return(MakeNatural(PitchClass.F, octave));

            case 6: return(MakeSharp(PitchClass.F, octave));

            case 7: return(MakeNatural(PitchClass.G, octave));

            case 8: return(MakeSharp(PitchClass.G, octave));

            case 9: return(MakeNatural(PitchClass.A, octave));

            case 10: return(MakeSharp(PitchClass.A, octave));

            case 11: return(MakeNatural(PitchClass.B, octave));
            }
            throw new InvalidOperationException();
        }
        public void Chord_DefaultOctave()
        {
            var defaultVelocity = (SevenBitNumber)90;
            var defaultOctave   = Octave.Get(2);

            var chordLength = MusicalTimeSpan.Sixteenth.Triplet();
            var chordTime1  = new MetricTimeSpan(0, 1, 12);
            var chordTime2  = chordTime1.Add(chordLength, TimeSpanMode.TimeLength);

            var pattern = new PatternBuilder()
                          .SetVelocity(defaultVelocity)
                          .SetOctave(defaultOctave)

                          .MoveToTime(chordTime1)
                          .Chord(new[]
            {
                NoteName.C,
                NoteName.G
            }, chordLength)
                          .Repeat()

                          .Build();

            PatternTestUtilities.TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.C, defaultOctave.Number, chordTime1, chordLength, defaultVelocity),
                new NoteInfo(NoteName.G, defaultOctave.Number, chordTime1, chordLength, defaultVelocity),
                new NoteInfo(NoteName.C, defaultOctave.Number, chordTime2, chordLength, defaultVelocity),
                new NoteInfo(NoteName.G, defaultOctave.Number, chordTime2, chordLength, defaultVelocity)
            });
        }
Example #4
0
        /// <summary>
        /// Returns the top margin value for the ledger line/the space corresponding to the given note.
        /// </summary>
        /// <param name="note"></param>
        /// <param name="octave"></param>
        /// <param name="clef"></param>
        /// <param name="partIndex"></param>
        /// <returns></returns>
        public static double GetNotePos(Note note, Octave octave, Clef clef, byte partIndex)
        {
            double result = GetScoreLinePos(octave, clef, partIndex);

            result -= (byte)note * stepLedgerLine / 2;
            return(result);
        }
Example #5
0
 public override void RevertChanges()
 {
     Filter.RevertChanges();
     Phaser.RevertChanges();
     Flanger.RevertChanges();
     Synth.RevertChanges();
     LoFi.RevertChanges();
     RingModulator.RevertChanges();
     GuitarToBass.RevertChanges();
     SlowGear.RevertChanges();
     Transpose.RevertChanges();
     PitchBend.RevertChanges();
     Robot.RevertChanges();
     VocalDist.RevertChanges();
     Dynamics.RevertChanges();
     Eq.RevertChanges();
     Isolator.RevertChanges();
     Octave.RevertChanges();
     Pan.RevertChanges();
     Tremolo.RevertChanges();
     Slicer.RevertChanges();
     Delay.RevertChanges();
     PanningDelay.RevertChanges();
     TapeEcho.RevertChanges();
     GranularDelay.RevertChanges();
     Roll.RevertChanges();
     Chorus.RevertChanges();
     Reverb.RevertChanges();
 }
Example #6
0
        public void Parse(string input, int expectedOctaveNumber)
        {
            var parsedOctave   = Octave.Parse(input);
            var expectedOctave = Octave.Get(expectedOctaveNumber);

            Assert.AreEqual(expectedOctave, parsedOctave, "Parsed octave is invalid.");
        }
Example #7
0
        /// <summary>
        /// Returns a standard top value for the ledger line/space used to compute specific top values.
        /// </summary>
        /// <param name="octave"></param>
        /// <param name="clef"></param>
        /// <param name="partIndex"></param>
        /// <returns></returns>
        private static double GetScoreLinePos(Octave octave, Clef clef, byte partIndex)
        {
            double result = scoreOffset;

            if (clef == Clef.treble)
            {
                result = result - stepLedgerLine;

                if (octave == Octave.Octave5)
                {
                }
                else if (octave == Octave.Octave6)
                {
                    result = result - stepLedgerLine * 7 / 2;
                }
                else if (octave == Octave.Octave7)
                {
                    result = result - stepLedgerLine * 14 / 2;
                }
            }
            else if (clef == Clef.bass)
            {
                if (octave == Octave.Octave3)
                {
                }
                else if (octave == Octave.Octave4)
                {
                    result = result - stepLedgerLine * 7 / 2;
                }
            }

            result += lineTopMargin[partIndex];

            return(result);
        }
Example #8
0
    private void UpdateVertices()
    {
        var vertices = mesh.vertices;

        for (int x = 0; x <= dimension; ++x)
        {
            for (int z = 0; z <= dimension; ++z)
            {
                float y = 0f;
                for (int o = 0; o < octaves.Length; ++o)
                {
                    Octave octave = octaves[o];
                    if (octave.alternate)
                    {
                        Vector2 noisePos = new Vector2(x, z) * octave.scale / dimension;
                        float   noise    = Mathf.PerlinNoise(noisePos.x, noisePos.y) * Mathf.PI * 2;
                        y += Mathf.Cos(noise + octave.speed.magnitude * Time.time) * octave.height;
                    }
                    else
                    {
                        Vector2 noisePos = (new Vector2(x, z) * octave.scale + Time.time * octave.speed) / dimension;
                        float   noise    = Mathf.PerlinNoise(noisePos.x, noisePos.y) - 0.5f;
                        y = noise * octave.height;
                    }
                }

                vertices[Index(x, z)] = new Vector3(x, y, z);
            }
        }

        mesh.vertices = vertices;
        mesh.RecalculateNormals();
    }
Example #9
0
 public Key(Note note, Accidental accidental, Octave octave)
 {
     Note        = note;
     Octave      = octave;
     Accidental  = accidental;
     numberOfKey = (int)Octave - (int)Note - (0.5 * (int)Accidental);
 }
Example #10
0
        public void ResolveRootNote()
        {
            var chord    = new Chord(NoteName.A, NoteName.ASharp, NoteName.D);
            var rootNote = chord.ResolveRootNote(Octave.Get(4));

            Assert.AreEqual(Notes.A4, rootNote, "Resolved root note is invalid.");
        }
Example #11
0
        public void GetPitch(int previousMidiKey, int midiKey, out Pitch pitch, out Octave octave, out MoleOrCross moc)
        {
            int key = midiKey % 12;

            //int octave = (midiKey / 12) - 1;
            pitch = pitches[key];
            moc   = moles[key];

            // Check if note has distance more than 6 == Octave higher or lower
            int distance = (previousMidiKey != 0) ? midiKey - previousMidiKey : 0;

            int baseOctave = 0;

            while (distance < -6)
            {
                baseOctave--;
                distance += 8;
            }

            while (distance > 6)
            {
                baseOctave++;
                distance -= 8;
            }

            octave = (Octave)baseOctave;
        }
Example #12
0
        public void Chord_Interval()
        {
            var defaultNoteLength = MusicalTimeSpan.Quarter;
            var defaultVelocity   = (SevenBitNumber)90;

            var pattern = new PatternBuilder()
                          .SetNoteLength(defaultNoteLength)
                          .SetVelocity(defaultVelocity)
                          .SetRootNote(DryWetMidi.MusicTheory.Note.Get(NoteName.CSharp, 5))

                          .Chord(new[] { Interval.Two, Interval.Five }, Octave.Get(2).A)
                          .Chord(new[] { Interval.Two, -Interval.Ten }, Octave.Get(2).B)

                          .Build();

            TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.A, 2, null, defaultNoteLength, defaultVelocity),
                new NoteInfo(NoteName.B, 2, null, defaultNoteLength, defaultVelocity),
                new NoteInfo(NoteName.D, 3, null, defaultNoteLength, defaultVelocity),

                new NoteInfo(NoteName.B, 2, defaultNoteLength, defaultNoteLength, defaultVelocity),
                new NoteInfo(NoteName.CSharp, 3, defaultNoteLength, defaultNoteLength, defaultVelocity),
                new NoteInfo(NoteName.CSharp, 2, defaultNoteLength, defaultNoteLength, defaultVelocity),
            });
        }
Example #13
0
        public override string ToString()
        {
            string accidental = GetAccidentalName(Acc);
            Octave octave     = GetOctaveFromNoteNumber(NoteNumber);
            Note   note       = GetNoteFromNoteNumber(NoteNumber, (sbyte)octave);

            return($"{note}{accidental} ({GetOctaveName(octave)})");
        }
Example #14
0
 public Note(Pitch pitch, Octave octave, MoleOrCross moleOrCross, Duration duration, int points, bool hasTilde)
 {
     this.pitch       = pitch;
     this.octave      = octave;
     this.moleOrCross = moleOrCross;
     this.duration    = duration;
     this.hasTilde    = hasTilde;
     this.points      = points;
 }
Example #15
0
        public void ResolveNotes()
        {
            var chord = new Chord(NoteName.A, NoteName.ASharp, NoteName.D);
            var notes = chord.ResolveNotes(Octave.Get(2));

            CollectionAssert.AreEqual(
                new[] { Notes.A2, Notes.ASharp2, Notes.D3 },
                notes,
                "Resolved notes are invalid.");
        }
Example #16
0
        public void OpenScore(List <Genome> genomes, List <string> scoreParams)
        {
            keySignature = scoreParams[0];
            byte beat;
            int  pmCount = 6;
            // The first element in <see cref="scoreParams"/> is the key signature.
            int index = 1;

            Octave[]       oct = new Octave[2];
            byte[]         barIter = new byte[2];
            string         tempo, duration;
            DurationCFugue cFugueDuration;
            double         realUnit     = ScoreStaffs.unitElementWidth;
            int            genomesCount = genomes.Count;

            try
            {
                for (int i = 0; i < genomesCount; i++, index += pmCount)
                {
                    tempo      = scoreParams[index];
                    oct[0]     = LayoutController.StringToEnum <Octave>("Octave" + scoreParams[index + 1]);
                    oct[1]     = LayoutController.StringToEnum <Octave>("Octave" + scoreParams[index + 2]);
                    barIter[0] = Convert.ToByte(scoreParams[index + 3]);
                    barIter[1] = Convert.ToByte(scoreParams[index + 4]);

                    duration       = scoreParams[index + 5];
                    cFugueDuration = Controller.StringToEnum <DurationCFugue>(duration);
                    if (duration == "s")
                    {
                        beat = 16;
                    }
                    else if (duration == "i")
                    {
                        beat = 8;
                    }
                    else if (duration == "q")
                    {
                        beat = 4;
                    }
                    else
                    {
                        beat = 16;
                    }

                    ScoreStaffs.unitElementWidth = ScoreStaffs.thisWidth / beat;
                    AddBar(genomes[i], keySignature, oct, cFugueDuration, barIter, tempo);
                    ScoreStaffs.unitElementWidth = realUnit;
                }
            }
            catch (Exception)
            {
                throw new Exception("The file you're trying to open is corrupted.");
            }
        }
Example #17
0
        private static double GetFrequency(Note note, Octave octave)
        {
            // We could decrease octave of every note by 1 by dividing it's frequency by 2.
            // We have predefined frequency of every note of eighth octave rounded to 2 decimals.
            // To get note frequency of any other octave we have to divide note frequency of eighth octave by 2 n times,
            // where n is a difference between eight octave and desired octave.
            var eightOctaveNoteFrequency = GetNoteFrequencyOfEightOctave(note);
            var frequencyDivider         = Math.Pow(2, 8 - (int)octave);

            return(Math.Round(eightOctaveNoteFrequency / frequencyDivider, 2));
        }
Example #18
0
 public static double GetTieOffset(Note note, Octave octave, byte partIndex)
 {
     if (octave == Octave.Octave3 && (note == Note.C || note == Note.D))
     {
         return(-stepLedgerLine / (partIndex + 1));
     }
     else
     {
         return(0);
     }
 }
Example #19
0
 /// <summary>
 /// Инициализирует новый экземпляр класса.
 /// </summary>
 /// <param name = "left">
 /// Левая граница (включённый предел).
 /// </param>
 /// <param name = "right">
 /// Правая граница (включённый предел).
 /// </param>
 /// <exception cref = "PianoException"></exception>
 public Piano(Octave left, Octave right)
 {
     if ((Int32)right - (Int32)left < 1)
     {
         throw new PianoException("Правая октава должна быть больше левой.");
     }
     startOctave = (Int32)left;
     endOctave   = (Int32)right;
     octaves     = (right - left) + 1;
     InitNotes(out notes);
 }
Example #20
0
 /// <summary>
 /// Returns the note orientation (stem up/down) used to choose the normal note image or the lower note image.
 /// </summary>
 /// <param name="note"></param>
 /// <param name="octave"></param>
 /// <returns></returns>
 public static char GetNoteOrientation(Note note, Octave octave)
 {
     if (octave == Octave.Octave3 || (octave == Octave.Octave4 && (note == Note.C || note == Note.D)) ||
         octave == Octave.Octave5)
     {
         return('+');
     }
     else
     {
         return('-');
     }
 }
Example #21
0
        /// <summary>
        /// Draws extra ledger line(s) when the specified note falls above/below the staff.
        /// </summary>
        /// <param name="notePos"></param>
        /// <param name="note"></param>
        /// <param name="octave"></param>
        /// <param name="duration"></param>
        /// <param name="noteLeft"></param>
        /// <param name="partIndex"></param>
        private void DrawExtraLedgerLines(double notePos, Note note, Octave octave, DurationCFugue duration,
                                          double noteLeftMargin, int verticalOffset, byte partIndex)
        {
            double x1 = noteLeftMargin - 4;
            double x2 = noteLeftMargin + LayoutController.ElementWidth["N" + duration];
            double y  = notePos + verticalOffset * LayoutController.stepLedgerLine / 2;

            DrawLine(x1, x2, y, partIndex);

            Clef clef = Parameters.Clefs[partIndex];

            // Now add the extra lines.
            if (octave == Octave.Octave3 && note == Note.C)
            {
                y = LayoutController.GetNotePos(Note.E, Octave.Octave3, clef, partIndex);
                DrawLine(x1, x2, y, partIndex);
            }
            else if (octave == Octave.Octave7)
            {
                if (note == Note.C || note == Note.D)
                {
                    y = LayoutController.GetNotePos(Note.A, Octave.Octave6, clef, partIndex);
                    DrawLine(x1, x2, y, partIndex);
                }
                else if (note == Note.E || note == Note.F)
                {
                    y = LayoutController.GetNotePos(Note.A, Octave.Octave6, clef, partIndex);
                    DrawLine(x1, x2, y, partIndex);
                    y = LayoutController.GetNotePos(Note.C, Octave.Octave7, clef, partIndex);
                    DrawLine(x1, x2, y, partIndex);
                }
                else if (note == Note.G || note == Note.A)
                {
                    y = LayoutController.GetNotePos(Note.A, Octave.Octave6, clef, partIndex);
                    DrawLine(x1, x2, y, partIndex);
                    y = LayoutController.GetNotePos(Note.C, Octave.Octave7, clef, partIndex);
                    DrawLine(x1, x2, y, partIndex);
                    y = LayoutController.GetNotePos(Note.E, Octave.Octave7, clef, partIndex);
                    DrawLine(x1, x2, y, partIndex);
                }
                else
                {
                    y = LayoutController.GetNotePos(Note.A, Octave.Octave6, clef, partIndex);
                    DrawLine(x1, x2, y, partIndex);
                    y = LayoutController.GetNotePos(Note.C, Octave.Octave7, clef, partIndex);
                    DrawLine(x1, x2, y, partIndex);
                    y = LayoutController.GetNotePos(Note.E, Octave.Octave7, clef, partIndex);
                    DrawLine(x1, x2, y, partIndex);
                    y = LayoutController.GetNotePos(Note.G, Octave.Octave7, clef, partIndex);
                    DrawLine(x1, x2, y, partIndex);
                }
            }
        }
        public void SetOctave()
        {
            Assert.AreEqual(Octave.Middle, PatternBuilder.DefaultOctave, "Default octave is invalid.");

            var patternBuilder = new PatternBuilder();

            Assert.AreEqual(PatternBuilder.DefaultOctave, patternBuilder.Octave, "Invalid initial octave.");

            var octave = Octave.Get(6);

            patternBuilder.SetOctave(octave);
            Assert.AreEqual(octave, patternBuilder.Octave, "Invalid octave after change.");
        }
        public void SetRootNote()
        {
            Assert.AreEqual(Octave.Middle.C, PatternBuilder.DefaultRootNote, "Default root note is invalid.");

            var patternBuilder = new PatternBuilder();

            Assert.AreEqual(PatternBuilder.DefaultRootNote, patternBuilder.RootNote, "Invalid initial root note.");

            var rootNote = Octave.Get(2).ASharp;

            patternBuilder.SetRootNote(rootNote);
            Assert.AreEqual(rootNote, patternBuilder.RootNote, "Invalid root note after change.");
        }
Example #24
0
        /// <summary>
        /// Returns the appropriate clef, based on octave.
        /// </summary>
        /// <param name="octave"></param>
        /// <returns></returns>
        public static Clef GetClef(Octave octave)
        {
            Clef clef;

            if ((byte)octave <= (byte)Octave.Octave4)
            {
                clef = Clef.bass;
            }
            else
            {
                clef = Clef.treble;
            }
            return(clef);
        }
        public void Chord_Chord_Octave_Length()
        {
            var pattern = new PatternBuilder()
                          .SetNoteLength(MusicalTimeSpan.Whole)
                          .SetOctave(Octave.Get(7))
                          .Chord(new DryWetMidi.MusicTheory.Chord(NoteName.A, NoteName.C), Octave.Get(2), MusicalTimeSpan.Eighth)
                          .Build();

            PatternTestUtilities.TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.A, 2, null, MusicalTimeSpan.Eighth, PatternBuilder.DefaultVelocity),
                new NoteInfo(NoteName.C, 3, null, MusicalTimeSpan.Eighth, PatternBuilder.DefaultVelocity)
            });
        }
        private Octave GetOctaveInstance()
        {
            if (GlobalSettings.Settings.OctavePath == "" && Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                throw new Exception("Octave binaries path not set (go to 'Edit' > 'General Settings' > 'Other' > 'DWSIM/Octave bridge settings').");
            }

            var octave = new Octave(GlobalSettings.Settings.OctavePath);

            octave.ExecuteCommand("addpath('" + Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + Path.DirectorySeparatorChar + "ECE')");
            octave.ExecuteCommand("cd '" + Path.GetTempPath() + Path.DirectorySeparatorChar + "'");

            return(octave);
        }
        public void Chord_Chord_Octave_Velocity()
        {
            var pattern = new PatternBuilder()
                          .SetVelocity((SevenBitNumber)80)
                          .SetOctave(Octave.Get(5))
                          .Chord(new DryWetMidi.MusicTheory.Chord(NoteName.A, NoteName.C), Octave.Get(1), (SevenBitNumber)70)
                          .Build();

            PatternTestUtilities.TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.A, 1, null, PatternBuilder.DefaultNoteLength, (SevenBitNumber)70),
                new NoteInfo(NoteName.C, 2, null, PatternBuilder.DefaultNoteLength, (SevenBitNumber)70)
            });
        }
Example #28
0
        public void MoveToFirstAnchor_Unkeyed_NoAnchors()
        {
            Assert.Throws <InvalidOperationException>(() =>
                                                      new PatternBuilder()
                                                      .MoveToTime(new MetricTimeSpan(0, 0, 10))
                                                      .StepForward(new MetricTimeSpan(0, 0, 11))
                                                      .MoveToTime(new MetricTimeSpan(0, 0, 30))
                                                      .StepBack(new MetricTimeSpan(0, 0, 5))
                                                      .MoveToFirstAnchor()

                                                      .Note(Octave.Get(0).A)

                                                      .Build());
        }
Example #29
0
        public void MoveToFirstAnchor_Keyed_NoKeyedAnchors()
        {
            Assert.Throws <ArgumentException>(() =>
                                              new PatternBuilder()
                                              .MoveToTime(new MetricTimeSpan(0, 0, 10))
                                              .StepForward(new MetricTimeSpan(0, 0, 11))
                                              .MoveToTime(new MetricTimeSpan(0, 0, 30))
                                              .Anchor()
                                              .StepBack(new MetricTimeSpan(0, 0, 5))
                                              .MoveToFirstAnchor("Test")

                                              .Note(Octave.Get(0).A)

                                              .Build());
        }
Example #30
0
 private int StepsToA4( Octave octave, Tone note, Accidental accidental)
 {
     int stepsToOctave4 = (int)octave * 12;
     var stepsToA = (int)note;
     switch (accidental)
     {
         case Accidental.Flat:
             stepsToA--;
             break;
         case Accidental.Sharp:
             stepsToA++;
             break;
     }
     return stepsToOctave4 + stepsToA;
 }
Example #31
0
 // Internal Methods
 protected void Initialize()
 {
     if (!_initialized)
     {
         _octaves = new Octave[octaves];
         float remainder = 1.0F;
         for (int index = octaves - 1; index > 0; index -= 1)
         {
             float significance = (index == 0) ? remainder : octaveRatio * remainder;
             _octaves[index] = new Octave(significance, Random.Range(minFrequency, maxFrequency));
             remainder      -= significance;
         }
         _initialized = true;
     }
 }
Example #32
0
    public Noise(int largestFeature, double persistence, int seed)
    {
        this.persistence = persistence;

        //recieves a number (eg 128) and calculates what power of 2 it is (eg 2^7)
        int numberOfOctaves = (int)Math.Ceiling(Math.Log10(largestFeature) / Math.Log10(2));

        octaves = new Octave[numberOfOctaves];
        frequencys = new double[numberOfOctaves];
        amplitudes = new double[numberOfOctaves];

        System.Random rnd = new System.Random(seed);

        for (int i = 0; i < numberOfOctaves; i++)
        {
            octaves[i] = new Octave(rnd.Next());

            frequencys[i] = Math.Pow(2, i);
            amplitudes[i] = Math.Pow(persistence, octaves.Length - i);
        }
    }
 public SetOctave(Octave octave)
 {
     m_Octave = octave;
 }