示例#1
0
        /// <summary>
        /// A Block contains a list of VoiceDefs consisting of a group of Trks followed by InputVoiceDefs.
        /// This constructor creates a MainBlock consisting of the concatenation of the Blocks in the argument blockList.
        /// The initialClefs are set to the clefs in initialClefsPerChannel.
        /// initialClefsPerChannel contains the clefs for the Trks followed by the clefs for the clefs for the InputVoiceDefs.
        /// Note that initialClefsPerChannel contains a clef for each channel, regardless of whether it is going to be printed or not. 
        /// The channels for both Trks and InputVoiceDefs are in ascending order. Their order from top to bottom in the score is determined later.
        /// </summary>
        /// <param name="initialClefPerChannel">The clefs to set at the start of each Trk followed by the clefs for each InputVoiceDef</param>
        /// <param name="blockList">A list of Blocks that will be concatenated to become this MainBlock.</param>
        public MainBlock(List<string> initialClefPerChannel, List<Block> blockList)
            : base()
        {
            Debug.Assert(blockList != null && blockList.Count > 0);

            Block block1 = blockList[0];
            int nTrks = block1.Trks.Count;
            int nInputVoiceDefs = block1.InputVoiceDefs.Count;

            #region conditions
            Debug.Assert(initialClefPerChannel.Count == (nTrks + nInputVoiceDefs));
            foreach(Block block in blockList)
            {
                Debug.Assert(block.Trks.Count == nTrks);
                Debug.Assert(block.InputVoiceDefs.Count == nInputVoiceDefs);
                for(int trkIndex = 0; trkIndex < nTrks; ++trkIndex)
                {
                    // Achtung: Trk midiChannels are those defined in the algorithm's MidiChannelIndexPerOutputVoice.
                    // The output channels must be in ascending oder, **_but_do_not_need_to_be_contiguous_**.
                    // See comment at CompositionAlgorithm.MidiChannelIndexPerOutputVoice.
                    Debug.Assert(block.Trks[trkIndex].MidiChannel == block1.Trks[trkIndex].MidiChannel);
                }
                for(int ivdIndex = 0; ivdIndex < nInputVoiceDefs; ++ivdIndex)
                {
                    // Input channels are in ascending order, starting at 0, and are contiguous.
                    Debug.Assert(block.Trks[ivdIndex].MidiChannel == ivdIndex);
                }
            }
            #endregion conditions

            for(int i = 0; i < nTrks; ++i)
            {
                int channel = block1.Trks[i].MidiChannel;
                VoiceDef trk = new Trk(channel);
                trk.Add(new ClefChangeDef(initialClefPerChannel[channel], 0));
                _voiceDefs.Add(trk);
            }

            int inputVoiceIndex = Trks.Count;
            for(int i = 0; i < nInputVoiceDefs; ++i)
            {
                VoiceDef inputVoiceDef = new InputVoiceDef(i);
                inputVoiceDef.Add(new ClefChangeDef(initialClefPerChannel[inputVoiceIndex++], 0));
                _voiceDefs.Add(inputVoiceDef);
            }

            foreach(Block block in blockList)
            {
                this.Concat(block);
            }
        }
示例#2
0
        private InputVoiceDef GetBar2InputVoiceDef(Seq bar2Seq)
        {
            InputVoiceDef ivd = new InputVoiceDef(0, 0, new List<IUniqueDef>());
            ivd.MsPositionReContainer = bar2Seq.AbsMsPosition;

            foreach(Trk trk in bar2Seq.Trks)
            {
                MidiChordDef firstMidiChordDef = null;
                foreach(IUniqueDef iud in trk.UniqueDefs)
                {
                    firstMidiChordDef = iud as MidiChordDef;
                    if(firstMidiChordDef != null)
                    {
                        List<TrkRef> trkRefs = new List<TrkRef>();
                        trkRefs.Add(new TrkRef((byte)trk.MidiChannel, bar2Seq.AbsMsPosition + firstMidiChordDef.MsPositionReFirstUD, 12, null));
                        SeqRef seqRef = new SeqRef(trkRefs, null);
                        NoteOn noteOn = new NoteOn(seqRef);
                        List<InputNoteDef> inputNoteDefs = new List<InputNoteDef>();
                        inputNoteDefs.Add(new InputNoteDef((byte)65, noteOn, null));
                        InputChordDef icd = new InputChordDef(firstMidiChordDef.MsPositionReFirstUD, 1500, inputNoteDefs, M.Dynamic.none, null);
                        ivd.Add(icd);
                        break;
                    }
                }
            }

            return ivd;
        }
示例#3
0
        private InputVoiceDef GetBar1InputVoiceDef(Seq bar1Seq)
        {
            InputVoiceDef ivd = new InputVoiceDef(0, 0, new List<IUniqueDef>());
            ivd.MsPositionReContainer = bar1Seq.AbsMsPosition;

            Trk leadTrk = null;
            foreach(Trk trk in bar1Seq.Trks)
            {
                if(trk.MidiChannel == 0)
                {
                    leadTrk = trk;
                    break;
                }

            }
            Debug.Assert(leadTrk != null);
            foreach(IUniqueDef tIud in leadTrk)
            {
                RestDef tRestDef = tIud as RestDef;
                MidiChordDef tmcd = tIud as MidiChordDef;
                if(tRestDef != null)
                {
                    RestDef iRestDef = new RestDef(tRestDef.MsPositionReFirstUD, tRestDef.MsDuration);
                    ivd.Add(iRestDef);
                }
                else if(tmcd != null)
                {
                    List<TrkRef> trkRefs = new List<TrkRef>();

                    foreach(Trk trk in bar1Seq.Trks)
                    {
                        trkRefs.Add(new TrkRef((byte)trk.MidiChannel, bar1Seq.AbsMsPosition + tmcd.MsPositionReFirstUD, 1, null));
                    }
                    SeqRef seqRef = new SeqRef(trkRefs, null);
                    NoteOn noteOn = new NoteOn(seqRef);
                    List<InputNoteDef> inputNoteDefs = new List<InputNoteDef>();
                    foreach(byte notatedMidiPitch in tmcd.NotatedMidiPitches)
                    {
                        inputNoteDefs.Add(new InputNoteDef((byte)(notatedMidiPitch + 36), noteOn, null));
                    }
                    InputChordDef icd = new InputChordDef(tIud.MsPositionReFirstUD, tIud.MsDuration, inputNoteDefs, M.Dynamic.none, null);
                    ivd.Add(icd);
                }
            }

            return ivd;
        }