GetNoteDuration() public method

public GetNoteDuration ( int duration ) : NoteDuration
duration int
return NoteDuration
コード例 #1
0
        RestSymbol[] GetRests(TimeSignature time, int start, int end)
        {
            RestSymbol[] result;
            RestSymbol   r1, r2;

            if (end - start < 0)
            {
                return(null);
            }

            NoteDuration dur = time.GetNoteDuration(end - start);

            switch (dur)
            {
            case NoteDuration.Whole:
            case NoteDuration.Half:
            case NoteDuration.Quarter:
            case NoteDuration.Eighth:
                r1     = new RestSymbol(start, dur);
                result = new RestSymbol[] { r1 };
                return(result);

            case NoteDuration.DottedHalf:
                r1 = new RestSymbol(start, NoteDuration.Half);
                r2 = new RestSymbol(start + time.Quarter * 2,
                                    NoteDuration.Quarter);
                result = new RestSymbol[] { r1, r2 };
                return(result);

            case NoteDuration.DottedQuarter:
                r1 = new RestSymbol(start, NoteDuration.Quarter);
                r2 = new RestSymbol(start + time.Quarter,
                                    NoteDuration.Eighth);
                result = new RestSymbol[] { r1, r2 };
                return(result);

            case NoteDuration.DottedEighth:
                r1 = new RestSymbol(start, NoteDuration.Eighth);
                r2 = new RestSymbol(start + time.Quarter / 2,
                                    NoteDuration.Sixteenth);
                result = new RestSymbol[] { r1, r2 };
                return(result);

            default:
                return(null);
            }
        }
コード例 #2
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);
        }
コード例 #3
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;
        }
コード例 #4
0
        /** Return the rest symbols needed to fill the time interval between
         * start and end.  If no rests are needed, return nil.
         */
        private RestSymbol[] GetRests(TimeSignature time, int start, int end)
        {
            RestSymbol[] result;
            RestSymbol r1, r2;

            if (end - start < 0)
            return null;

            NoteDuration dur = time.GetNoteDuration(end - start);
            switch (dur) {
            case NoteDuration.Whole:
            case NoteDuration.Half:
            case NoteDuration.Quarter:
            case NoteDuration.Eighth:
                r1 = new RestSymbol(start, dur);
                result = new RestSymbol[]{ r1 };
                return result;

            case NoteDuration.DottedHalf:
                r1 = new RestSymbol(start, NoteDuration.Half);
                r2 = new RestSymbol(start + time.Quarter*2,
                                    NoteDuration.Quarter);
                result = new RestSymbol[]{ r1, r2 };
                return result;

            case NoteDuration.DottedQuarter:
                r1 = new RestSymbol(start, NoteDuration.Quarter);
                r2 = new RestSymbol(start + time.Quarter,
                                    NoteDuration.Eighth);
                result = new RestSymbol[]{ r1, r2 };
                return result;

            case NoteDuration.DottedEighth:
                r1 = new RestSymbol(start, NoteDuration.Eighth);
                r2 = new RestSymbol(start + time.Quarter/2,
                                    NoteDuration.Sixteenth);
                result = new RestSymbol[]{ r1, r2 };
                return result;

            default:
                return null;
            }
        }