コード例 #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);
        }
コード例 #2
0
ファイル: ChordSymbol.cs プロジェクト: yugsh/PianoGame
        /** 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;
        }
コード例 #3
0
ファイル: ChordSymbol.cs プロジェクト: yugsh/PianoGame
 /** Return whether any of the notes in notedata (between start and
  * end indexes) overlap.  This is needed by the Stem class to
  * determine the position of the stem (left or right of notes).
  */
 private static bool NotesOverlap(NoteData[] notedata, int start, int end)
 {
     for (int i = start; i < end; i++) {
     if (!notedata[i].leftside) {
         return true;
     }
     }
     return false;
 }
コード例 #4
0
ファイル: ChordSymbol.cs プロジェクト: yugsh/PianoGame
 /** Given the note data (the white keys and accidentals), create
  * the Accidental Symbols and return them.
  */
 private static AccidSymbol[] CreateAccidSymbols(NoteData[] notedata, Clef clef)
 {
     int count = 0;
     foreach (NoteData n in notedata) {
     if (n.accid != Accid.None) {
         count++;
     }
     }
     AccidSymbol[] symbols = new AccidSymbol[count];
     int i = 0;
     foreach (NoteData n in notedata) {
     if (n.accid != Accid.None) {
         symbols[i] = new AccidSymbol(n.accid, n.whitenote, clef);
         i++;
     }
     }
     return symbols;
 }