GetWhiteNote() public method

public GetWhiteNote ( int notenumber ) : WhiteNote
notenumber int
return WhiteNote
Beispiel #1
0
        CreateNoteData(List <MidiNote> midinotes, KeySignature key,
                       TimeSignature time)
        {
            int len = midinotes.Count;

            NoteData[] notedata = new NoteData[len];

            for (int i = 0; i < len; i++)
            {
                MidiNote midi = midinotes[i];
                notedata[i]           = new NoteData();
                notedata[i].number    = midi.Number;
                notedata[i].leftside  = true;
                notedata[i].whitenote = key.GetWhiteNote(midi.Number);
                notedata[i].duration  = time.GetNoteDuration(midi.EndTime - midi.StartTime);
                notedata[i].accid     = key.GetAccidental(midi.Number, midi.StartTime / time.Measure);

                if (i > 0 && (notedata[i].whitenote.Dist(notedata[i - 1].whitenote) == 1))
                {
                    /* This note (notedata[i]) overlaps with the previous note.
                     * Change the side of this note.
                     */

                    if (notedata[i - 1].leftside)
                    {
                        notedata[i].leftside = false;
                    }
                    else
                    {
                        notedata[i].leftside = true;
                    }
                }
                else
                {
                    notedata[i].leftside = true;
                }
            }
            return(notedata);
        }
Beispiel #2
0
        /** Given the raw midi notes (the note number and duration in pulses),
         * calculate the following note data:
         * - The white key
         * - The accidental (if any)
         * - The note duration (half, quarter, eighth, etc)
         * - The side it should be drawn (left or side)
         * By default, notes are drawn on the left side.  However, if two notes
         * overlap (like A and B) you cannot draw the next note directly above it.
         * Instead you must shift one of the notes to the right.
         *
         * The KeySignature is used to determine the white key and accidental.
         * The TimeSignature is used to determine the duration.
         */
        private static NoteData[] CreateNoteData(List<MidiNote> midinotes, KeySignature key,
            TimeSignature time)
        {
            int len = midinotes.Count;
            NoteData[] notedata = new NoteData[len];

            for (int i = 0; i < len; i++) {
            MidiNote midi = midinotes[i];
            notedata[i] = new NoteData();
            notedata[i].number = midi.Number;
            notedata[i].leftside = true;
            notedata[i].whitenote = key.GetWhiteNote(midi.Number);
            notedata[i].duration = time.GetNoteDuration(midi.EndTime - midi.StartTime);
            notedata[i].accid = key.GetAccidental(midi.Number, midi.StartTime / time.Measure);

            if (i > 0 && (notedata[i].whitenote.Dist(notedata[i-1].whitenote) == 1)) {
                /* This note (notedata[i]) overlaps with the previous note.
                 * Change the side of this note.
                 */

                if (notedata[i-1].leftside) {
                    notedata[i].leftside = false;
                } else {
                    notedata[i].leftside = true;
                }
            } else {
                notedata[i].leftside = true;
            }
            }
            return notedata;
        }
Beispiel #3
0
    public void TestGetAccidentalSameMeasure()
    {
        KeySignature k;

        /* G Major, F# */
        k = new KeySignature(1, 0);

        int note = NoteScale.ToNumber(NoteScale.C, 1);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.C);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.None);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.C);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.None);

        note = NoteScale.ToNumber(NoteScale.Fsharp, 1);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.F);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.None);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.F);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.None);

        note = NoteScale.ToNumber(NoteScale.F, 1);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.F);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.Natural);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.F);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.None);

        note = NoteScale.ToNumber(NoteScale.Fsharp, 1);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.F);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.Sharp);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.F);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.None);

        note = NoteScale.ToNumber(NoteScale.Bflat, 1);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.B);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.Flat);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.B);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.None);

        note = NoteScale.ToNumber(NoteScale.A, 1);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.A);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.None);

        note = NoteScale.ToNumber(NoteScale.B, 1);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.B);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.Natural);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.B);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.None);

        note = NoteScale.ToNumber(NoteScale.Bflat, 1);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.B);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.Flat);

        /* F Major, Bflat */
        k = new KeySignature(0, 1);

        note = NoteScale.ToNumber(NoteScale.G, 1);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.G);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.None);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.G);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.None);

        note = NoteScale.ToNumber(NoteScale.Bflat, 1);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.B);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.None);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.B);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.None);

        note = NoteScale.ToNumber(NoteScale.B, 1);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.B);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.Natural);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.B);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.None);

        note = NoteScale.ToNumber(NoteScale.Bflat, 1);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.B);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.Flat);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.B);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.None);

        note = NoteScale.ToNumber(NoteScale.Fsharp, 1);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.F);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.Sharp);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.F);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.None);

        note = NoteScale.ToNumber(NoteScale.G, 1);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.G);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.None);

        note = NoteScale.ToNumber(NoteScale.F, 1);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.F);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.Natural);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.F);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.None);

        note = NoteScale.ToNumber(NoteScale.Fsharp, 1);
        Assert.AreEqual(k.GetWhiteNote(note).Letter, WhiteNote.F);
        Assert.AreEqual(k.GetAccidental(note, 1), Accid.Sharp);
    }