Example #1
0
        public void AddTieStop()
        {
            this.Items = ArrayExtensions.ArrayAppend(this.Items, new tie {
                type = startstop.stop
            });
            this.ItemsElementName = ArrayExtensions.ArrayAppend(this.ItemsElementName, ItemsChoiceType1.tie);
            var theNotation = new notations();

            this.notations = ArrayExtensions.ArrayAppend(this.notations, theNotation);
            theNotation.AddTiedStop();
        }
Example #2
0
            private void Init(TimesigVector timesig_table, TempoVector tempo_table, int clock_start, int length, int note_number, bool create_rest)
            {
                clock_  = clock_start;
                length_ = length;

                // 着目している範囲内のテンポのみを取り出す
                var small_tempo_table = new TempoVector();

                small_tempo_table.AddRange(
                    tempo_table
                    .Where((tempo) => clock_start <= tempo.Clock && tempo.Clock < clock_start + length)
                    .Select((tempo) => (TempoTableEntry)tempo.Clone()));

                // <pitch> エレメントのテンプレートを作成
                MusicXML.pitch pitch = null;
                if (!create_rest)
                {
                    pitch = new pitch();
                    int  octave = VsqNote.getNoteOctave(note_number) + 1;
                    step step;
                    if (Enum.TryParse <step>(VsqNote.getNoteStringBase(note_number), out step))
                    {
                        pitch.step = step;
                    }
                    pitch.octave = octave.ToString();
                    int alter = VsqNote.getNoteAlter(note_number);
                    if (alter != 0)
                    {
                        pitch.alter          = alter;
                        pitch.alterSpecified = true;
                    }
                }

                int clock_end     = clock_start + length;
                int current_clock = clock_start;

                while (current_clock < clock_start + length)
                {
                    int next_bar_clock    = timesig_table.getClockFromBarCount(timesig_table.getBarCountFromClock(current_clock) + 1);
                    int next_tempo_change = clock_end;
                    if (small_tempo_table.Count > 0)
                    {
                        try {
                            next_tempo_change =
                                small_tempo_table
                                .First((tempo) => {
                                return(current_clock < tempo.Clock && tempo.Clock < clock_end);
                            })
                                .Clock;
                        } catch (InvalidOperationException) { }
                    }

                    int next_separation_point = Math.Min(Math.Min(clock_end, next_bar_clock), next_tempo_change);

                    int remain   = next_separation_point - current_clock;
                    var template =
                        templates_
                        .OrderByDescending((note) => note.duration.First)
                        .FirstOrDefault((note) => note.duration.First <= remain);
                    if (template == null)
                    {
                        break;
                    }
                    else
                    {
                        var note = template.Clone();
                        if (create_rest)
                        {
                            note.rest.Add(new rest());
                        }
                        else
                        {
                            note.pitch.Add(pitch.Clone());
                            note.stem       = new stem();
                            note.stem.Value = stemvalue.up;
                        }
                        notes_.Add(note);
                        current_clock += (int)note.duration.First;
                    }
                }

                // connect note with tie
                if (!create_rest && notes_.Count >= 2)
                {
                    for (int i = 0; i < notes_.Count; ++i)
                    {
                        var note      = notes_[i];
                        var tied_list = new List <tied>();
                        if (i < notes_.Count - 1)
                        {
                            var start_tie = new tie();
                            start_tie.type = startstop.start;
                            note.tie.Add(start_tie);

                            var tied = new tied();
                            tied.type = startstopcontinue.start;
                            tied_list.Add(tied);
                        }
                        if (0 < i)
                        {
                            var stop_tie = new tie();
                            stop_tie.type = startstop.stop;
                            note.tie.Add(stop_tie);

                            var tied = new tied();
                            tied.type = startstopcontinue.stop;
                            tied_list.Add(tied);
                        }
                        var notations = new notations();
                        notations.Items = tied_list.ToArray();
                        note.notations  = new MusicXML.notations[] { notations };
                    }
                }
            }