Beispiel #1
0
        private static void set_measures(Sequence sequence, D_Staff staff)
        {
            // This function requires staff.num_of_beats to be set!

            // TimeSignature messages are in channel 0
            List <Tuple <MidiEvent, MetaMessage> > meta_messages = getMetaMessages(sequence[0]);

            foreach (Tuple <MidiEvent, MetaMessage> metaPair in meta_messages)
            {
                MidiEvent   midiEvent   = metaPair.Item1;
                MetaMessage metaMessage = metaPair.Item2;

                byte[] meta_bytes = metaMessage.GetBytes();

                // Time signature
                if (metaMessage.MetaType == MetaType.TimeSignature)
                {
                    int top_number    = meta_bytes[0];
                    int bottom_number = (int)(Math.Pow(2, meta_bytes[1]));
                    int start_beat    = midiEvent.AbsoluteTicks / sequence.Division;

                    staff.addMeasure(top_number, bottom_number, start_beat);
                }
            }

            staff.setMeasureEndTimes();
        }
        private void set_measures(D_Staff staff, List <string> tokens)
        {
            // This function requires staff.num_of_beats to be set
            int    current_token_index = 0;
            int    token_end_index     = tokens.Count - 1;
            double current_beat        = 0;

            while (current_token_index <= token_end_index)
            {
                string current_token = tokens[current_token_index];

                // Special case, when we encounter \relative, skip a token
                if (current_token == "\\relative")
                {
                    current_token_index++;
                }
                else if (isNote(current_token))
                {
                    // We don't care about octaves here so we pass 0 and no previous note
                    // All we care about is note length so that we may increase current_beat
                    D_Note note = LilypondNoteParser.noteFromToken(current_token, 0, null);
                    current_beat += ((double)note.length / (double)4);
                }
                else if (current_token == "\\time")
                {
                    string           time_signature       = tokens[current_token_index + 1];
                    Tuple <int, int> time_signature_tuple = StringUtil.getMeasureFromString(time_signature);
                    staff.addMeasure(time_signature_tuple.Item1, time_signature_tuple.Item2, (int)current_beat);
                }

                current_token_index++;
            }

            staff.setMeasureEndTimes();
        }