예제 #1
0
        /* determine if note is an integer multiple of a 64th div3 */
        public static bool IntMultOf64thDiv3(NoteFlags Opcode)
        {
            FractionRec OpcodesDuration;

            NoteNoteObjectRec.ConvertDurationFrac(Opcode, out OpcodesDuration);
            return(FractionIntMultOf64thDiv3(OpcodesDuration));
        }
예제 #2
0
 private void TryWriteNotes(BinaryWriter writer, NoteFlags flags)
 {
     if (panelConfig.HasFlag(flags))
     {
         writer.Write(notes[flags]);
     }
 }
예제 #3
0
        /* quantize the start time */
        private static void QuantizeStartTime(
            int StartTime,
            int QuarterNoteLen,
            NoteFlags QuantizedDuration,
            double QuantizedDurationAdjust,
            out FractionRec StartTimeOut,
            out double StartTimeAdjustOut,
            out double WholeNoteStartTimeAdjust)
        {
            uint        Denominator;
            double      QuantizedStartTime;
            double      OrigDuration;
            FractionRec OrigDurationFractional;

            /* start times must be a multiple of the 64th note.  see rationale */
            /* in comment at top of this file. */
            Denominator = 64;

            NoteNoteObjectRec.ConvertDurationFrac(QuantizedDuration, out OrigDurationFractional);
            OrigDuration = (4 * QuarterNoteLen) * QuantizedDurationAdjust
                           * FractionRec.Fraction2Double(OrigDurationFractional);

            /* compute start time to nearest division they allow */
            FractionRec.Double2Fraction(StartTime / (double)(QuarterNoteLen * 4), Denominator, out StartTimeOut);

            /* set start time adjust (relative to duration) */
            QuantizedStartTime       = FractionRec.Fraction2Double(StartTimeOut) * (4 * QuarterNoteLen);
            StartTimeAdjustOut       = (QuantizedStartTime - StartTime) / OrigDuration;
            WholeNoteStartTimeAdjust = (QuantizedStartTime - StartTime) / (4 * QuarterNoteLen);
        }
예제 #4
0
 private static void TryReadNotes(BinaryReader reader, Layer layer, NoteFlags flags)
 {
     if (layer.panelConfig.HasFlag(flags))
     {
         var notes = reader.ReadList(Note.Deserialize);
         layer.notes.Add(flags, notes);
     }
 }
예제 #5
0
        /* quantize the duration */
        private static void QuantizeDuration(
            int Duration,
            int QuarterNoteLen,
            TimeMatchRec[] MatchingTable,
            int MatchingTableLength,
            out NoteFlags QuantizedDurationOut,
            out double QuantizedDurationAdjustOut,
            out int WholeNoteOverflowOut)
        {
            double Tolerance;
            bool   Matched;
            int    Scan;

            /* initialize */
            QuantizedDurationOut       = 0;
            QuantizedDurationAdjustOut = 1;
            WholeNoteOverflowOut       = 0;

            /* extract whole note overflow */
            while (Duration > 4 * QuarterNoteLen)
            {
                WholeNoteOverflowOut += 1;
                Duration             -= 4 * QuarterNoteLen;
            }

            /* determine closest symbolic duration */
            Tolerance = 0;
            Matched   = false;
            while (!Matched)
            {
                /* scan duration matching table to see if we can find a match */
                for (Scan = 0; (!Matched) && (Scan < MatchingTableLength); Scan += 1)
                {
                    if (Math.Abs(MatchingTable[Scan].Ticks - Duration) <= Tolerance)
                    {
                        /* match found */
                        Matched = true;
                        QuantizedDurationOut       = MatchingTable[Scan].Descriptor;
                        QuantizedDurationAdjustOut = (double)Duration
                                                     / (double)MatchingTable[Scan].Ticks;
                    }
                }

                /* if no match was found then increase tolerance */
                if (!Matched)
                {
                    if (Tolerance == 0)
                    {
                        Tolerance = 1;
                    }
                    else
                    {
                        Tolerance = Tolerance * 1.5;
                    }
                }
            }
        }
예제 #6
0
 public override void SetValue(NoteNoteObjectRec Note, string value)
 {
     if (String.Equals(value, GetDefaultValue()))
     {
         Note.PutNoteMultisampleFalsePitch(-1);
     }
     else
     {
         short     pitch     = Note.GetNoteMultisampleFalsePitch();
         NoteFlags sharpFlat = Note.SharpFlat;
         SymbolicPitch.StringToNumericPitch(value, ref pitch, ref sharpFlat);
         Note.PutNoteMultisampleFalsePitch(pitch);
         Note.PutNoteFlatOrSharpStatus(sharpFlat);
     }
 }
예제 #7
0
        public static int[] GetPanelIndices(NoteFlags noteFlags)
        {
            for (var i = 0; i < panelIndicesToNoteArray.GetLength(0); i++)
            {
                for (var j = 0; j < panelIndicesToNoteArray.GetLength(1); j++)
                {
                    if (panelIndicesToNoteArray[i, j] == noteFlags)
                    {
                        return new int[] { i, j }
                    }
                    ;
                }
            }

            return(null);
        }
    }
예제 #8
0
 /* get note event information.  fields may be NIL if value is not needed */
 public static void GetQuantizedNoteEventInfo(
     QuantEventRec Event,
     out FractionRec StartTimeOut,
     out double StartTimeAdjustOut,
     out NoteFlags DurationOut,
     out double DurationAdjustOut,
     out short MIDIPitchOut,
     out short MIDIAttackVelocityOut,
     out short MIDIReleaseVelocityOut)
 {
     Debug.Assert(Event.Type == QuantEventType.eQuantizedNoteEvent);
     StartTimeOut           = Event.StartTime;
     StartTimeAdjustOut     = Event.StartTimeAdjust;
     DurationOut            = Event.Duration;
     DurationAdjustOut      = Event.DurationAdjust;
     MIDIPitchOut           = Event.MIDIPitch;
     MIDIAttackVelocityOut  = Event.MIDIAttackVelocity;
     MIDIReleaseVelocityOut = Event.MIDIReleaseVelocity;
 }
예제 #9
0
        /* create new interval note */
        public static QuantEventRec NewQuantizedNoteEvent(
            FractionRec StartTime,
            double StartTimeAdjust,
            NoteFlags Duration,
            double DurationAdjust,
            short MIDIPitch,
            short MIDIAttackVelocity,
            short MIDIReleaseVelocity)
        {
            QuantEventRec Event = new QuantEventRec();

            Event.Type                = QuantEventType.eQuantizedNoteEvent;
            Event.StartTime           = StartTime;
            Event.StartTimeAdjust     = StartTimeAdjust;
            Event.Duration            = Duration;
            Event.DurationAdjust      = DurationAdjust;
            Event.MIDIPitch           = MIDIPitch;
            Event.MIDIAttackVelocity  = MIDIAttackVelocity;
            Event.MIDIReleaseVelocity = MIDIReleaseVelocity;
            Event.TieTarget           = null;
            return(Event);
        }
예제 #10
0
 public PanelNote(NoteFlags panel, Note note)
 {
     this.panel = panel;
     this.note  = note;
 }
예제 #11
0
        /* convert the duration flags into a heap allocated string */
        public static string NumericDurationToString(
            NoteFlags Duration,
            bool DotFlag,
            NoteFlags Division)
        {
            string RootString;
            string DotPrefix;
            string DivisionSuffix;

            if (Division == NoteFlags.eDiv1Modifier)
            {
                /* normal notes */
                switch (Duration)
                {
                default:
                    Debug.Assert(false);
                    throw new ArgumentException();

                case NoteFlags.e64thNote:
                    RootString = "64th";
                    break;

                case NoteFlags.e32ndNote:
                    RootString = "32nd";
                    break;

                case NoteFlags.e16thNote:
                    RootString = "16th";
                    break;

                case NoteFlags.e8thNote:
                    RootString = "8th";
                    break;

                case NoteFlags.e4thNote:
                    RootString = "quarter";
                    break;

                case NoteFlags.e2ndNote:
                    RootString = "half";
                    break;

                case NoteFlags.eWholeNote:
                    RootString = "whole";
                    break;

                case NoteFlags.eDoubleNote:
                    RootString = "double";
                    break;

                case NoteFlags.eQuadNote:
                    RootString = "quad";
                    break;
                }
            }
            else
            {
                /* fractional notes */
                switch (Duration)
                {
                default:
                    Debug.Assert(false);
                    throw new ArgumentException();

                case NoteFlags.e64thNote:
                    RootString = "128th";
                    break;

                case NoteFlags.e32ndNote:
                    RootString = "64th";
                    break;

                case NoteFlags.e16thNote:
                    RootString = "32nd";
                    break;

                case NoteFlags.e8thNote:
                    RootString = "16th";
                    break;

                case NoteFlags.e4thNote:
                    RootString = "8th";
                    break;

                case NoteFlags.e2ndNote:
                    RootString = "quarter";
                    break;

                case NoteFlags.eWholeNote:
                    RootString = "half";
                    break;

                case NoteFlags.eDoubleNote:
                    RootString = "whole";
                    break;

                case NoteFlags.eQuadNote:
                    RootString = "double";
                    break;
                }
            }
            if (DotFlag)
            {
                DotPrefix = "dotted ";
            }
            else
            {
                DotPrefix = "";
            }
            switch (Division)
            {
            default:
                Debug.Assert(false);
                throw new ArgumentException();

            case NoteFlags.eDiv1Modifier:
                DivisionSuffix = "";
                break;

            case NoteFlags.eDiv3Modifier:
                DivisionSuffix = " triplet";
                break;

            case NoteFlags.eDiv5Modifier:
                DivisionSuffix = " div 5";
                break;

            case NoteFlags.eDiv7Modifier:
                DivisionSuffix = " div 7";
                break;
            }

            return(String.Concat(DotPrefix, RootString, DivisionSuffix));
        }
예제 #12
0
        /* obtain duration attributes from the string passed in.  if the duration attribute */
        /* can't be determined, then Duration will remain unchanged */
        /* this routine is kinda yucky. */
        public static void StringToNumericDuration(
            string String,
            ref NoteFlags Duration,
            out bool DotFlag,
            out NoteFlags Division)
        {
            /* look for hint of division */
            if (String.Contains("div 3") || String.Contains("div3") || String.Contains("trip"))
            {
                Division = NoteFlags.eDiv3Modifier;
            }
            else if (String.Contains("div 5") || String.Contains("div5") || String.Contains("quint"))
            {
                Division = NoteFlags.eDiv5Modifier;
            }
            else if (String.Contains("div 7") || String.Contains("div7") || String.Contains("sept"))
            {
                Division = NoteFlags.eDiv7Modifier;
            }
            else
            {
                Division = NoteFlags.eDiv1Modifier;
            }

            /* look for hint of duration */
            if (Division == NoteFlags.eDiv1Modifier)
            {
                /* normal notes */
                if (String.Contains("64") || String.Contains("sixty"))
                {
                    Duration = NoteFlags.e64thNote;
                }
                else if (String.Contains("32") || String.Contains("thirty"))
                {
                    Duration = NoteFlags.e32ndNote;
                }
                else if (String.Contains("16") || String.Contains("sixteen"))
                {
                    Duration = NoteFlags.e16thNote;
                }
                else if (String.Contains("8") || String.Contains("eight"))
                {
                    Duration = NoteFlags.e8thNote;
                }
                else if (String.Contains("4") || String.Contains("quarter"))
                {
                    Duration = NoteFlags.e4thNote;
                }
                else if (String.Contains("half"))
                {
                    Duration = NoteFlags.e2ndNote;
                }
                else if (String.Contains("whole"))
                {
                    Duration = NoteFlags.eWholeNote;
                }
                else if (String.Contains("double"))
                {
                    Duration = NoteFlags.eDoubleNote;
                }
                else if (String.Contains("quad"))
                {
                    Duration = NoteFlags.eQuadNote;
                }
                else
                {
                    /* didn't find anything */
                }
            }
            else
            {
                /* handle fractional ones */
                if (String.Contains("128") || String.Contains("twenty"))
                {
                    Duration = NoteFlags.e64thNote;
                }
                else if (String.Contains("64") || String.Contains("sixty"))
                {
                    Duration = NoteFlags.e32ndNote;
                }
                else if (String.Contains("32") || String.Contains("thirty"))
                {
                    Duration = NoteFlags.e16thNote;
                }
                else if (String.Contains("16") || String.Contains("sixteen"))
                {
                    Duration = NoteFlags.e8thNote;
                }
                else if (String.Contains("8") || String.Contains("eight"))
                {
                    Duration = NoteFlags.e4thNote;
                }
                else if (String.Contains("4") || String.Contains("quarter"))
                {
                    Duration = NoteFlags.e2ndNote;
                }
                else if (String.Contains("half"))
                {
                    Duration = NoteFlags.eWholeNote;
                }
                else if (String.Contains("whole"))
                {
                    Duration = NoteFlags.eDoubleNote;
                }
                else if (String.Contains("double"))
                {
                    Duration = NoteFlags.eQuadNote;
                }
                else
                {
                    /* didn't find anything */
                }
            }

            /* look for dot hint */
            if (String.Contains("dot"))
            {
                DotFlag = true;
            }
            else
            {
                DotFlag = false;
            }
        }
예제 #13
0
        public static string NumericPitchToString(
            short pitch,
            NoteFlags sharpFlat)
        {
            int octave = (pitch / 12);
            int index  = pitch % 12;

            string name;

            switch (index)
            {
            default:
                Debug.Assert(false);
                throw new ArgumentException();

            case 0:     /* B#/C */
                if ((sharpFlat & NoteFlags.eSharpModifier) != 0)
                {
                    name = "B sharp ";
                }
                else
                {
                    name = "C ";
                }
                break;

            case 1:     /* C#/Db */
                if ((sharpFlat & NoteFlags.eSharpModifier) != 0)
                {
                    name = "C sharp ";
                }
                else
                {
                    name = "D flat ";
                }
                break;

            case 2:     /* D */
                name = "D ";
                break;

            case 3:     /* D#/Eb */
                if ((sharpFlat & NoteFlags.eSharpModifier) != 0)
                {
                    name = "D sharp ";
                }
                else
                {
                    name = "E flat ";
                }
                break;

            case 4:     /* E/Fb */
                if ((sharpFlat & NoteFlags.eFlatModifier) != 0)
                {
                    name = "F flat ";
                }
                else
                {
                    name = "E ";
                }
                break;

            case 5:     /* E#/F */
                if ((sharpFlat & NoteFlags.eSharpModifier) != 0)
                {
                    name = "E sharp ";
                }
                else
                {
                    name = "F ";
                }
                break;

            case 6:     /* F#/Gb */
                if ((sharpFlat & NoteFlags.eSharpModifier) != 0)
                {
                    name = "F sharp ";
                }
                else
                {
                    name = "G flat ";
                }
                break;

            case 7:     /* G */
                name = "G ";
                break;

            case 8:     /* G#/Ab */
                if ((sharpFlat & NoteFlags.eSharpModifier) != 0)
                {
                    name = "G sharp ";
                }
                else
                {
                    name = "A flat ";
                }
                break;

            case 9:     /* A */
                name = "A ";
                break;

            case 10:     /* A#/Bb */
                if ((sharpFlat & NoteFlags.eSharpModifier) != 0)
                {
                    name = "A sharp ";
                }
                else
                {
                    name = "B flat ";
                }
                break;

            case 11:     /* B/Cb */
                if ((sharpFlat & NoteFlags.eFlatModifier) != 0)
                {
                    name = "C flat ";
                }
                else
                {
                    name = "B ";
                }
                break;
            }

            return(String.Concat(name, (octave - (Constants.CENTERNOTE / 12)).ToString()));
        }
예제 #14
0
        /* convert the string into a pitch and sharp/flat word. */
        public static void StringToNumericPitch(
            string composite,
            ref short pitch,
            ref NoteFlags sharpFlat)
        {
            int localPitch = pitch % 12;                               /* get the default */
            int octave     = pitch / 12 - (Constants.CENTERNOTE / 12); /* defaults */

            if (String.IsNullOrEmpty(composite))
            {
                /* return without changing anything */
                return;
            }

            /* check the pitch specifier */
            switch (composite[0])
            {
            default:
                break;

            case 'a':
            case 'A':
                if (composite.Contains("sharp") || composite.Contains("#"))
                {
                    /* A# */
                    localPitch = 9 + 1;
                    sharpFlat  = NoteFlags.eSharpModifier;
                }
                else if (composite.Contains("flat"))
                {
                    /* Ab */
                    localPitch = 9 - 1;
                    sharpFlat  = NoteFlags.eFlatModifier;
                }
                else
                {
                    /* A */
                    localPitch = 9;
                    sharpFlat  = 0;
                }
                break;

            case 'B':
            case 'b':
                if (composite.Contains("sharp") || composite.Contains("#"))
                {
                    /* B# */
                    localPitch = 11 + 1;
                    sharpFlat  = NoteFlags.eSharpModifier;
                }
                else if (composite.Contains("flat"))
                {
                    /* Bb */
                    localPitch = 11 - 1;
                    sharpFlat  = NoteFlags.eFlatModifier;
                }
                else
                {
                    /* B */
                    localPitch = 11;
                    sharpFlat  = 0;
                }
                break;

            case 'C':
            case 'c':
                if (composite.Contains("sharp") || composite.Contains("#"))
                {
                    /* C# */
                    localPitch = 0 + 1;
                    sharpFlat  = NoteFlags.eSharpModifier;
                }
                else if (composite.Contains("flat"))
                {
                    /* Cb */
                    localPitch = 0 - 1 + 12;
                    sharpFlat  = NoteFlags.eFlatModifier;
                }
                else
                {
                    /* C */
                    localPitch = 0;
                    sharpFlat  = 0;
                }
                break;

            case 'D':
            case 'd':
                if (composite.Contains("sharp") || composite.Contains("#"))
                {
                    /* D# */
                    localPitch = 2 + 1;
                    sharpFlat  = NoteFlags.eSharpModifier;
                }
                else if (composite.Contains("flat"))
                {
                    /* Db */
                    localPitch = 2 - 1;
                    sharpFlat  = NoteFlags.eFlatModifier;
                }
                else
                {
                    /* D */
                    localPitch = 2;
                    sharpFlat  = 0;
                }
                break;

            case 'E':
            case 'e':
                if (composite.Contains("sharp") || composite.Contains("#"))
                {
                    /* E# */
                    localPitch = 4 + 1;
                    sharpFlat  = NoteFlags.eSharpModifier;
                }
                else if (composite.Contains("flat"))
                {
                    /* Eb */
                    localPitch = 4 - 1;
                    sharpFlat  = NoteFlags.eFlatModifier;
                }
                else
                {
                    /* E */
                    localPitch = 4;
                    sharpFlat  = 0;
                }
                break;

            case 'F':
            case 'f':
                if (composite.Contains("sharp") || composite.Contains("#"))
                {
                    /* F# */
                    localPitch = 5 + 1;
                    sharpFlat  = NoteFlags.eSharpModifier;
                }
                else if (composite.Contains("flat"))
                {
                    /* Fb */
                    localPitch = 5 - 1;
                    sharpFlat  = NoteFlags.eFlatModifier;
                }
                else
                {
                    /* F */
                    localPitch = 5;
                    sharpFlat  = 0;
                }
                break;

            case 'G':
            case 'g':
                if (composite.Contains("sharp") || composite.Contains("#"))
                {
                    /* G# */
                    localPitch = 7 + 1;
                    sharpFlat  = NoteFlags.eSharpModifier;
                }
                else if (composite.Contains("flat"))
                {
                    /* Gb */
                    localPitch = 7 - 1;
                    sharpFlat  = NoteFlags.eFlatModifier;
                }
                else
                {
                    /* G */
                    localPitch = 7;
                    sharpFlat  = 0;
                }
                break;
            }

            /* try to figure out what octave they want */
            int i = 0;

            while ((i < composite.Length) && (composite[i] != '-') && ((composite[i] < '0') || (composite[i] > '9')))
            {
                i += 1;
            }
            if (i < composite.Length)
            {
                Int32.TryParse(composite.Substring(i), out octave);
            }
            if ((octave * 12) + Constants.CENTERNOTE < 0)
            {
                octave = -Constants.CENTERNOTE / 12;
            }
            if ((octave * 12) + Constants.CENTERNOTE > Constants.NUMNOTES - 1)
            {
                octave = Constants.CENTERNOTE / 12 - 1;
            }

            localPitch = ((octave + (Constants.CENTERNOTE / 12)) * 12) + localPitch;
            if (localPitch < 0)
            {
                localPitch = 0;
            }
            else if (localPitch > Constants.NUMNOTES - 1)
            {
                localPitch = Constants.NUMNOTES - 1;
            }
            pitch = (short)localPitch;
        }