Beispiel #1
0
        /// <summary>
        /// There is still one system per bar.
        /// Each VoiceDef begins with an MNXCommon.Clef (taking small clefs into account).
        /// An Exception will be thrown if a SmallClefDef is found on the lower voiceDef in a staff in the systems input.
        /// Small clefs (if there are any) are copied from the top to the bottom voice (if there is one) on each staff.
        /// Small clefs on lower voices on a staff have IsVisible set to false.
        /// </summary>
        /// <param name="systems"></param>
        public void ConvertVoiceDefsToNoteObjects(List <SvgSystem> systems)
        {
            byte[] currentChannelVelocities = new byte[systems[0].Staves.Count];
            var    topVoiceSmallClefs       = new List <SmallClef>();

            int systemAbsMsPos = 0;

            for (int systemIndex = 0; systemIndex < systems.Count; ++systemIndex)
            {
                SvgSystem system = systems[systemIndex];
                system.AbsStartMsPosition = systemAbsMsPos;
                int msPositionReVoiceDef = 0;
                for (int staffIndex = 0; staffIndex < system.Staves.Count; ++staffIndex)
                {
                    Staff staff = system.Staves[staffIndex];
                    msPositionReVoiceDef = 0;
                    topVoiceSmallClefs.Clear();
                    for (int voiceIndex = 0; voiceIndex < staff.Voices.Count; ++voiceIndex)
                    {
                        Voice voice = staff.Voices[voiceIndex];
                        voice.VoiceDef.AgglomerateRests();

                        msPositionReVoiceDef = 0;
                        List <IUniqueDef> iuds = voice.VoiceDef.UniqueDefs;
                        M.Assert(iuds[0] is ClefDef || iuds[0] is MNX.Common.Clef); /** <-------------- **/

                        for (int iudIndex = 0; iudIndex < iuds.Count; ++iudIndex)
                        {
                            IUniqueDef iud           = voice.VoiceDef.UniqueDefs[iudIndex];
                            int        absMsPosition = systemAbsMsPos + msPositionReVoiceDef;

                            NoteObject noteObject =
                                SymbolSet.GetNoteObject(voice, absMsPosition, iud, iudIndex, ref currentChannelVelocities[staffIndex]);

                            if (noteObject is SmallClef smallClef)
                            {
                                if (voiceIndex == 0)
                                {
                                    if (staff.Voices.Count > 1)
                                    {
                                        topVoiceSmallClefs.Add(smallClef);
                                    }
                                }
                                else
                                {
                                    throw new Exception("SmallClefs may not be defined for a lower voice. They will be copied from the top voice");
                                }
                            }

                            if (iud is IUniqueSplittableChordDef iscd && iscd.MsDurationToNextBarline != null)
                            {
                                msPositionReVoiceDef += (int)iscd.MsDurationToNextBarline;
                            }
Beispiel #2
0
        /// <summary>
        /// There is still one system per bar.
        /// </summary>
        /// <param name="systems"></param>
        public void ConvertVoiceDefsToNoteObjects(List <SvgSystem> systems)
        {
            byte[] currentChannelVelocities = new byte[systems[0].Staves.Count];

            List <ClefChangeDef> voice0ClefChangeDefs = new List <ClefChangeDef>();
            List <ClefChangeDef> voice1ClefChangeDefs = new List <ClefChangeDef>();

            for (int systemIndex = 0; systemIndex < systems.Count; ++systemIndex)
            {
                SvgSystem system            = systems[systemIndex];
                int       visibleStaffIndex = -1;
                for (int staffIndex = 0; staffIndex < system.Staves.Count; ++staffIndex)
                {
                    Staff staff = system.Staves[staffIndex];
                    if (!(staff is InvisibleOutputStaff))
                    {
                        visibleStaffIndex++;
                    }
                    voice0ClefChangeDefs.Clear();
                    voice1ClefChangeDefs.Clear();
                    for (int voiceIndex = 0; voiceIndex < staff.Voices.Count; ++voiceIndex)
                    {
                        Voice voice           = staff.Voices[voiceIndex];
                        float musicFontHeight = (voice is OutputVoice) ? _pageFormat.MusicFontHeight : _pageFormat.MusicFontHeight * _pageFormat.InputStavesSizeFactor;
                        if (!(staff is InvisibleOutputStaff))
                        {
                            Debug.Assert(_pageFormat.ClefsList[visibleStaffIndex] != null);
                            voice.NoteObjects.Add(new ClefSymbol(voice, _pageFormat.ClefsList[visibleStaffIndex], musicFontHeight));
                        }
                        bool firstLmdd = true;

                        if (staff is InputStaff)
                        {
                            InputVoice inputVoice = staff.Voices[voiceIndex] as InputVoice;
                            if (systemIndex == 0)
                            {
                                InputVoiceDef inputVoiceDef = inputVoice.VoiceDef as InputVoiceDef;
                                inputVoice.SetMidiChannel(inputVoiceDef.MidiChannel, systemIndex);
                            }
                        }
                        foreach (IUniqueDef iud in voice.VoiceDef.UniqueDefs)
                        {
                            NoteObject noteObject =
                                SymbolSet.GetNoteObject(voice, iud, firstLmdd, ref currentChannelVelocities[staffIndex], musicFontHeight);

                            ClefChangeSymbol clefChangeSymbol = noteObject as ClefChangeSymbol;
                            if (clefChangeSymbol != null)
                            {
                                if (voiceIndex == 0)
                                {
                                    voice0ClefChangeDefs.Add(iud as ClefChangeDef);
                                }
                                else
                                {
                                    voice1ClefChangeDefs.Add(iud as ClefChangeDef);
                                }
                            }

                            voice.NoteObjects.Add(noteObject);

                            firstLmdd = false;
                        }
                    }

                    if (voice0ClefChangeDefs.Count > 0 || voice1ClefChangeDefs.Count > 0)
                    {
                        // the main clef on this staff in the next system
                        SetNextSystemClefType(staffIndex, voice0ClefChangeDefs, voice1ClefChangeDefs);
                    }

                    if (staff.Voices.Count == 2)
                    {
                        InsertInvisibleClefChangeSymbols(staff.Voices, voice0ClefChangeDefs, voice1ClefChangeDefs);

                        CheckClefTypes(staff.Voices);

                        StandardSymbolSet standardSymbolSet = SymbolSet as StandardSymbolSet;
                        if (standardSymbolSet != null)
                        {
                            standardSymbolSet.ForceNaturalsInSynchronousChords(staff);
                        }
                    }
                }
            }
        }