Ejemplo n.º 1
0
        public static D_Note noteFromToken(String token, int current_scope_octave, D_Note previous_note)
        {
            NoteLevel noteLevel            = noteLevelDictionary[token[0]];
            int       length_in_sixteenths = 16 / StringUtil.getNumberFromString(token);

            if (token.Contains('.'))
            {
                length_in_sixteenths = (int)((double)length_in_sixteenths * 1.5);
            }

            if (noteLevel == NoteLevel.rest)
            {
                return(D_NoteFactory.create_rest(length_in_sixteenths));
            }
            else
            {
                NoteAlteration alteration = getNoteNoteAlteration(token);

                int octave = getNoteOctave(token, current_scope_octave);

                D_Note new_note = D_NoteFactory.create_note(noteLevel, alteration, octave, length_in_sixteenths);
                if (previous_note != null)
                {
                    setRelativeOctave(new_note, previous_note);
                }
                return(new_note);
            }
        }
Ejemplo n.º 2
0
        public static D_Note create_note(int keycode, int beats)
        {
            Tuple <NoteLevel, NoteAlteration> note_alt = get_level_and_alteration(keycode);
            int octave = get_octave(keycode);

            return(D_NoteFactory.create_note(note_alt.Item1, note_alt.Item2, octave, beats));
        }
Ejemplo n.º 3
0
        public static Tuple <D_Note, D_Note> splitNote(D_Note note_to_split, int first_note_length)
        {
            int    second_note_length = note_to_split.length - first_note_length;
            D_Note first = D_NoteFactory.create_note(note_to_split, first_note_length);

            first.note_tie = NoteTie.start;
            D_Note second = D_NoteFactory.create_note(note_to_split, second_note_length);

            second.note_tie = NoteTie.stop;

            return(new Tuple <D_Note, D_Note>(first, second));
        }
Ejemplo n.º 4
0
        public void fillBarsWithNotes(List <D_Note> notes)
        {
            // Warning: this does not take notes into account that span multiple bars
            int current_bar_index = 0;

            foreach (D_Note note in notes)
            {
                D_Note to_append = this.bars[current_bar_index].addNote(note);

                if (to_append != null)
                {
                    // overflow!
                    current_bar_index++;
                    D_Note please_dont_return = this.bars[current_bar_index].addNote(to_append);

                    if (please_dont_return != null)
                    {
                        throw new Exception("Somehow there's a note that's longer than an entire bar. wot de fok");
                    }
                }

                if (this.bars[current_bar_index].isFull())
                {
                    current_bar_index++;
                }
            }

            if (!this.bars[this.bars.Count - 2].isFull())
            {
                throw new Exception("Second last bar is not full, something probablt went wrong here.");
            }

            if (!this.bars[this.bars.Count - 1].isFull())
            {
                // fill with rests
                int to_fill = this.bars[current_bar_index].spaceLeft();
                this.bars[current_bar_index].addNote(D_NoteFactory.create_rest(to_fill));
            }
        }
Ejemplo n.º 5
0
 public static D_Note create_rest(int beats)
 {
     return(D_NoteFactory.create_rest(beats));
 }