Example #1
0
        /// <summary>
        /// Creates a new InputVoiceDef containing just the argument inputChordDef,
        /// then calls the other InsertInRest() function with the voiceDef as argument.
        /// </summary>
        public void InsertInRest(InputChordDef inputChordDef)
        {
            List <IUniqueDef> iuds = new List <IUniqueDef>()
            {
                inputChordDef
            };
            InputVoiceDef iVoiceDef = new InputVoiceDef(iuds);

            InsertInRest(iVoiceDef);
        }
Example #2
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);
            }
        }
Example #3
0
        /// <summary>
        /// Returns two bars. The first is the beginning of the argument bar up to absoluteSplitPos,
        /// The second is the end of the argument bar beginning at absoluteSplitPos.
        /// The final UniqueMidiDurationDef in each voice.UniqueMidiDurationDefs list is converted
        /// to a FinalLMDDInVoice object containing an MsDurationToBarline property.
        /// If a chord or rest overlaps a barline, a LocalizedCautionaryChordDef object is created at the
        /// start of the voice.UniqueMidiDurationDefs in the second bar. A LocalizedCautionaryChordDef
        /// object is a kind of chord which is used while justifying systems, but is not displayed and
        /// does not affect performance.
        /// ClefChangeDefs are placed at the end of the first bar, not at the start of the second bar.
        /// </summary>
        protected List<List<VoiceDef>> SplitBar(List<VoiceDef> originalBar, int absoluteSplitPos)
        {
            List<List<VoiceDef>> twoBars = new List<List<VoiceDef>>();
            List<VoiceDef> firstBar = new List<VoiceDef>();
            List<VoiceDef> secondBar = new List<VoiceDef>();
            twoBars.Add(firstBar);
            twoBars.Add(secondBar);
            int originalBarStartPos = originalBar[0].UniqueDefs[0].MsPosition;
            int originalBarEndPos =
                originalBar[0].UniqueDefs[originalBar[0].UniqueDefs.Count - 1].MsPosition +
                originalBar[0].UniqueDefs[originalBar[0].UniqueDefs.Count - 1].MsDuration;

            VoiceDef firstBarVoice;
            VoiceDef secondBarVoice;
            foreach(VoiceDef voice in originalBar)
            {
                TrkDef outputVoice = voice as TrkDef;
                if(outputVoice != null)
                {
                    firstBarVoice = new TrkDef(outputVoice.MidiChannel,new List<IUniqueDef>());
                    firstBar.Add(firstBarVoice);
                    secondBarVoice = new TrkDef(outputVoice.MidiChannel, new List<IUniqueDef>());
                    secondBar.Add(secondBarVoice);
                }
                else
                {
                    firstBarVoice = new InputVoiceDef();
                    firstBar.Add(firstBarVoice);
                    secondBarVoice = new InputVoiceDef();
                    secondBar.Add(secondBarVoice);
                }
                foreach(IUniqueDef iUnique in voice.UniqueDefs)
                {
                    int udMsDuration = iUnique.MsDuration;
                    IUniqueSplittableChordDef uniqueChordDef = iUnique as IUniqueSplittableChordDef;
                    if(uniqueChordDef != null)
                    {
                        udMsDuration = (uniqueChordDef.MsDurationToNextBarline == null) ? iUnique.MsDuration : (int)uniqueChordDef.MsDurationToNextBarline;
                    }

                    int udEndPos = iUnique.MsPosition + udMsDuration;

                    if(iUnique.MsPosition >= absoluteSplitPos)
                    {
                        if(iUnique.MsPosition == absoluteSplitPos && iUnique is ClefChangeDef)
                        {
                            firstBarVoice.UniqueDefs.Add(iUnique);
                        }
                        else
                        {
                            Debug.Assert(udEndPos <= originalBarEndPos);
                            secondBarVoice.UniqueDefs.Add(iUnique);
                        }
                    }
                    else if(udEndPos > absoluteSplitPos)
                    {
                        int durationAfterBarline = udEndPos - absoluteSplitPos;
                        if(iUnique is RestDef)
                        {
                            // This is a rest. Split it.
                            RestDef firstRestHalf = new RestDef(iUnique.MsPosition, absoluteSplitPos - iUnique.MsPosition);
                            firstBarVoice.UniqueDefs.Add(firstRestHalf);

                            RestDef secondRestHalf = new RestDef(absoluteSplitPos, durationAfterBarline);
                            secondBarVoice.UniqueDefs.Add(secondRestHalf);
                        }
                        else if(iUnique is CautionaryChordDef)
                        {
                            // This is a cautionary chord. Set the position of the following barline, and
                            // Add an LocalizedCautionaryChordDef at the beginning of the following bar.
                            iUnique.MsDuration = absoluteSplitPos - iUnique.MsPosition;
                            firstBarVoice.UniqueDefs.Add(iUnique);

                            CautionaryChordDef secondLmdd = new CautionaryChordDef((IUniqueChordDef)iUnique, absoluteSplitPos, durationAfterBarline);
                            secondBarVoice.UniqueDefs.Add(secondLmdd);
                        }
                        else
                        {
                            // This is a MidiChordDef or a InputChordDef.
                            // Set the position of the following barline, and add a CautionaryChordDef at the beginning
                            // of the following bar.
                            if(uniqueChordDef != null)
                            {
                                uniqueChordDef.MsDurationToNextBarline = absoluteSplitPos - iUnique.MsPosition;
                            }

                            firstBarVoice.UniqueDefs.Add((IUniqueDef)uniqueChordDef);

                            CautionaryChordDef secondLmdd = new CautionaryChordDef((IUniqueChordDef)uniqueChordDef,
                                absoluteSplitPos, durationAfterBarline);
                            secondBarVoice.UniqueDefs.Add(secondLmdd);
                        }
                    }
                    else
                    {
                        Debug.Assert(udEndPos <= absoluteSplitPos && iUnique.MsPosition >= originalBarStartPos);
                        firstBarVoice.UniqueDefs.Add(iUnique);
                    }
                }
            }
            return twoBars;
        }
Example #4
0
 /// <summary>
 /// Adds the argument to the end of this VoiceDef.
 /// Sets the MsPositions of the appended UniqueDefs.
 /// </summary>
 public void Concat(InputVoiceDef inputVoiceDef)
 {
     int thisEndMsPositionReSeq = this.EndMsPositionReFirstIUD + this.MsPositionReContainer;
     if(inputVoiceDef.MsPositionReContainer > thisEndMsPositionReSeq)
     {
         RestDef rest = new RestDef(this.EndMsPositionReFirstIUD, inputVoiceDef.MsPositionReContainer - thisEndMsPositionReSeq);
         this.Add(rest);
     }
     _AddRange(inputVoiceDef);
 }
        /// <summary>
        /// This function creates only one bar, but with VoiceDef objects. 
        /// </summary>
        List<VoiceDef> CreateBar2(int bar2StartMsPos)
        {
            List<VoiceDef> bar = new List<VoiceDef>();

            byte channel = 0;
            List<TrkDef> trkDefs = new List<TrkDef>();
            foreach(Palette palette in _palettes)
            {
                bar.Add(new TrkDef(channel, new List<IUniqueDef>()));
                TrkDef trkDef = palette.NewTrkDef(channel);
                trkDef.SetMsDuration(6000);
                trkDefs.Add(trkDef);
                ++channel;
            }

            int msPosition = bar2StartMsPos;
            int maxBarMsPos = 0;
            int startMsDifference = 1500;
            for(int i = 0; i < trkDefs.Count; ++i)
            {
                int maxMsPos = WriteVoiceMidiDurationDefsInBar2(bar[i], trkDefs[i], msPosition, bar2StartMsPos);
                maxBarMsPos = maxBarMsPos > maxMsPos ? maxBarMsPos : maxMsPos;
                msPosition += startMsDifference;
            }

            // now add the final rest in the bar
            for(int i = 0; i < trkDefs.Count; ++i)
            {
                int mdsdEndPos = trkDefs[i].EndMsPosition;
                if(maxBarMsPos > mdsdEndPos)
                {
                    RestDef rest2Def = new RestDef(mdsdEndPos, maxBarMsPos - mdsdEndPos);
                    bar[i].UniqueDefs.Add(rest2Def);
                }
            }

            InputVoiceDef inputVoiceDef = new InputVoiceDef(maxBarMsPos - bar2StartMsPos);
            inputVoiceDef.StartMsPosition = bar2StartMsPos;
            int msPos = bar2StartMsPos;
            for(int i = 0; i < bar.Count; ++i)
            {
                TrkOn trkRef = new TrkOn((byte)i, msPos, 12, null);
                List<TrkOn> trkRefs = new List<TrkOn>() { trkRef };
                TrkOns seqDef = new TrkOns(trkRefs, null);

                InputNoteDef inputNoteDef = new InputNoteDef(64, seqDef, null, null);

                List<InputNoteDef> inputNoteDefs = new List<InputNoteDef>(){inputNoteDef};
                InputChordDef inputChordDef = new InputChordDef(msPos, startMsDifference, inputNoteDefs);
                inputVoiceDef.InsertInRest(inputChordDef);
                msPos += startMsDifference;
            }

            bar.Add(inputVoiceDef);
            return bar;
        }
        List<VoiceDef> CreateBar1()
        {
            List<VoiceDef> bar = new List<VoiceDef>();

            byte channel = 0;
            foreach(Palette palette in _palettes)
            {
                TrkDef trkDef = new TrkDef(channel, new List<IUniqueDef>());
                bar.Add(trkDef);
                WriteVoiceMidiDurationDefs1(trkDef, palette);
                ++channel;
            }

            InputVoiceDef inputVoiceDef = new InputVoiceDef();
            VoiceDef bottomOutputVoice = bar[0];

            foreach(IUniqueDef iud in bottomOutputVoice.UniqueDefs)
            {
                MidiChordDef mcd = iud as MidiChordDef;
                RestDef rd = iud as RestDef;
                if(mcd != null)
                {
                    List<IUniqueDef> iuds = new List<IUniqueDef>() { (IUniqueDef)mcd };

                    // Note that the msPosition of the trkDef is trkDef.StartMsPosition (= iuds[0].msPosition),
                    // which may be greater than the InputChordDef's msPosition
                    TrkDef trkDef = new TrkDef(bottomOutputVoice.MidiChannel, iuds);

                    // If non-null, arg2 overrides the inputControls attached to the InputNote or InputChord.
                    TrkOn trkRef = new TrkOn(trkDef, null);
                    List<TrkOn> trkRefs = new List<TrkOn>() { trkRef };
                    TrkOns trkOns = new TrkOns(trkRefs, null);

                    byte displayPitch = (byte)(mcd.NotatedMidiPitches[0] + 36);
                    Pressure pressure = new Pressure(0, null);
                    Pressures pressures = new Pressures(new List<Pressure>() {pressure}, null);
                    TrkOff trkOff = new TrkOff(trkRef.TrkMidiChannel, mcd.MsPosition, null);
                    List<TrkOff> noteOffTrkOffs = new List<TrkOff>() { trkOff };
                    TrkOffs trkOffs = new TrkOffs(noteOffTrkOffs, null);

                    InputNoteDef inputNoteDef = new InputNoteDef(displayPitch,
                                                                    trkOns, null,
                                                                    pressures,
                                                                    null, trkOffs,
                                                                    null);

                    List<InputNoteDef> inputNoteDefs = new List<InputNoteDef>() { inputNoteDef };

                    // The InputChordDef's msPosition must be <= the msPosition of any of the contained trkRefs
                    InputChordDef icd = new InputChordDef(mcd.MsPosition, mcd.MsDuration, inputNoteDefs);

                    inputVoiceDef.UniqueDefs.Add(icd);
                }
                else if(rd != null)
                {
                    RestDef newRest = new RestDef(rd.MsPosition, rd.MsDuration);
                    inputVoiceDef.UniqueDefs.Add(newRest);
                }
            }

            #region set cascading inputControls on the first InputChordDef  (for testing)
            InputChordDef inputChordDef1 = inputVoiceDef.UniqueDefs[0] as InputChordDef; // no need to check for null here.

            InputControls chordInputControls = new InputControls();

            chordInputControls.VelocityOption = VelocityOption.overridden;
            chordInputControls.MinimumVelocity = 19;
            inputChordDef1.InputControls = chordInputControls;

            InputControls noteInputControls = new InputControls();
            noteInputControls.VelocityOption = VelocityOption.scaled;
            noteInputControls.MinimumVelocity = 20;
            inputChordDef1.InputNoteDefs[0].InputControls = noteInputControls;

            #endregion

            bar.Add(inputVoiceDef);

            return bar;
        }
Example #7
0
        private static void SetBar2NoteOnNoteOffControls(InputVoiceDef inputVoiceDef)
        {
            //InputChordDef inputChordDef0 = (InputChordDef)inputVoiceDef[0]; // no need to check for null here.
            //InputChordDef inputChordDef1 = (InputChordDef)inputVoiceDef[1]; // no need to check for null here.

            //inputChordDef0.TrkOptions = new TrkOptions(new TrkOffControl(TrkOffOption.stopChord));
            //inputChordDef1.TrkOptions = new TrkOptions(new TrkOffControl(TrkOffOption.fade));
        }
Example #8
0
 /// <summary>
 /// An attempt is made to insert the argument iVoiceDef in a rest in the VoiceDef.
 /// The rest is found using the iVoiceDef's MsPositon and MsDuration.
 /// The first and last objects in the argument must be chords, not rests.
 /// The argument may contain just one chord.
 /// The inserted iVoiceDef may end up at the beginning, middle or end of the spanning rest (which will
 /// be split as necessary).
 /// If no rest is found spanning the iVoiceDef, the attempt fails and an exception is thrown.
 /// This function does not change the msPositions of any other chords or rests in the containing VoiceDef,
 /// It does, of course, change the indices of the inserted lmdds and the later chords and rests.
 /// </summary>
 public void InsertInRest(InputVoiceDef inputVoiceDef)
 {
     Debug.Assert(inputVoiceDef[0] is InputChordDef && inputVoiceDef[inputVoiceDef.Count - 1] is InputChordDef);
     _InsertInRest((VoiceDef)inputVoiceDef);
 }
Example #9
0
 /// <summary>
 /// Inserts the voiceDef in the list at the given index, and then
 /// resets the positions of all the uniqueDefs in the list.
 /// </summary>
 public void InsertRange(int index, InputVoiceDef voiceDef)
 {
     _InsertRange(index, (VoiceDef) voiceDef);
 }
Example #10
0
 /// <summary>
 /// Returns a deep clone of this InputVoiceDef.
 /// </summary>
 public InputVoiceDef Clone()
 {
     List<IUniqueDef> clonedLmdds = new List<IUniqueDef>();
     foreach(IUniqueDef iu in this._uniqueDefs)
     {
         IUniqueDef clone = (IUniqueDef) iu.Clone();
         clonedLmdds.Add(clone);
     }
     var ivd = new InputVoiceDef(this.MidiChannel, this.MsPositionReContainer, clonedLmdds);
     ivd.Container = this.Container;
     return ivd;
 }
Example #11
0
        /// <summary>
        /// Creates a "bar" which is a list of voiceDefs containing IUniqueDefs that begin before barlineEndMsPosition,
        /// and removes these IUniqueDefs from the current block.
        /// </summary>
        /// <param name="endBarlineAbsMsPosition"></param>
        /// <returns>The popped bar</returns>
        private List<VoiceDef> PopBar(int endBarlineAbsMsPosition)
        {
            Debug.Assert(AbsMsPosition < endBarlineAbsMsPosition);
            AssertNonEmptyBlockConsistency();

            List<VoiceDef> poppedBar = new List<VoiceDef>();
            List<VoiceDef> remainingBar = new List<VoiceDef>();
            int currentBlockAbsEndPos = this.AbsMsPosition + this.MsDuration;

            bool isLastBar = (currentBlockAbsEndPos == endBarlineAbsMsPosition);

            VoiceDef poppedBarVoice;
            VoiceDef remainingBarVoice;
            foreach(VoiceDef voiceDef in _voiceDefs)
            {
                Trk outputVoice = voiceDef as Trk;
                InputVoiceDef inputVoice = voiceDef as InputVoiceDef;
                if(outputVoice != null)
                {
                    poppedBarVoice = new Trk(outputVoice.MidiChannel);
                    poppedBar.Add(poppedBarVoice);
                    remainingBarVoice = new Trk(outputVoice.MidiChannel);
                    remainingBar.Add(remainingBarVoice);
                }
                else
                {
                    poppedBarVoice = new InputVoiceDef(inputVoice.MidiChannel);
                    poppedBar.Add(poppedBarVoice);
                    remainingBarVoice = new InputVoiceDef(inputVoice.MidiChannel);
                    remainingBar.Add(remainingBarVoice);
                }
                foreach(IUniqueDef iud in voiceDef.UniqueDefs)
                {
                    int iudMsDuration = iud.MsDuration;
                    int iudAbsStartPos = this.AbsMsPosition + iud.MsPositionReFirstUD;
                    int iudAbsEndPos = iudAbsStartPos + iudMsDuration;

                    if(iudAbsStartPos >= endBarlineAbsMsPosition)
                    {
                        Debug.Assert(iudAbsEndPos <= currentBlockAbsEndPos);
                        if(iud is ClefChangeDef && iudAbsStartPos == endBarlineAbsMsPosition)
                        {
                            poppedBarVoice.UniqueDefs.Add(iud);
                        }
                        else
                        {
                            remainingBarVoice.UniqueDefs.Add(iud);
                        }
                    }
                    else if(iudAbsEndPos > endBarlineAbsMsPosition)
                    {
                        int durationBeforeBarline = endBarlineAbsMsPosition - iudAbsStartPos;
                        int durationAfterBarline = iudAbsEndPos - endBarlineAbsMsPosition;
                        if(iud is RestDef)
                        {
                            // This is a rest. Split it.
                            RestDef firstRestHalf = new RestDef(iudAbsStartPos, durationBeforeBarline);
                            poppedBarVoice.UniqueDefs.Add(firstRestHalf);

                            RestDef secondRestHalf = new RestDef(endBarlineAbsMsPosition, durationAfterBarline);
                            remainingBarVoice.UniqueDefs.Add(secondRestHalf);
                        }
                        else if(iud is CautionaryChordDef)
                        {
                            // This is a cautionary chord. Set the position of the following barline, and
                            // Add a CautionaryChordDef at the beginning of the following bar.
                            iud.MsDuration = endBarlineAbsMsPosition - iudAbsStartPos;
                            poppedBarVoice.UniqueDefs.Add(iud);

                            Debug.Assert(remainingBarVoice.UniqueDefs.Count == 0);
                            CautionaryChordDef secondLmdd = new CautionaryChordDef((IUniqueChordDef)iud, 0, durationAfterBarline);
                            remainingBarVoice.UniqueDefs.Add(secondLmdd);
                        }
                        else if(iud is MidiChordDef || iud is InputChordDef)
                        {
                            IUniqueSplittableChordDef uniqueChordDef = iud as IUniqueSplittableChordDef;
                            uniqueChordDef.MsDurationToNextBarline = durationBeforeBarline;
                            poppedBarVoice.UniqueDefs.Add(uniqueChordDef);

                            Debug.Assert(remainingBarVoice.UniqueDefs.Count == 0);
                            CautionaryChordDef ccd = new CautionaryChordDef(uniqueChordDef, 0, durationAfterBarline);
                            remainingBarVoice.UniqueDefs.Add(ccd);
                        }
                    }
                    else
                    {
                        Debug.Assert(iudAbsEndPos <= endBarlineAbsMsPosition && iudAbsStartPos >= AbsMsPosition);
                        poppedBarVoice.UniqueDefs.Add(iud);
                    }
                }
            }

            this.AbsMsPosition = endBarlineAbsMsPosition;

            this._voiceDefs = remainingBar;
            SetMsPositions();

            if(!isLastBar)
            {
                // _voiceDefs is not empty
                AssertNonEmptyBlockConsistency();
            }

            return poppedBar;
        }
Example #12
0
 /// <summary>
 /// Creates a new InputVoiceDef containing just the argument inputChordDef,
 /// then calls the other InsertInRest() function with the voiceDef as argument. 
 /// </summary>
 public void InsertInRest(InputChordDef inputChordDef)
 {
     List<IUniqueDef> iuds = new List<IUniqueDef>() { inputChordDef };
     InputVoiceDef iVoiceDef = new InputVoiceDef(this.MidiChannel, 0, iuds);
     InsertInRest(iVoiceDef);
 }
Example #13
0
 /// <summary>
 /// Adds the argument to the end of this VoiceDef.
 /// Sets the MsPositions of the appended UniqueDefs.
 /// </summary>
 public void AddRange(InputVoiceDef voiceDef)
 {
     _AddRange((VoiceDef)voiceDef);
 }
Example #14
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;
        }
Example #15
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;
        }
Example #16
0
 private static void SetTrackCCSettings(InputVoiceDef inputVoiceDef)
 {
     InputChordDef inputChordDef1 = (InputChordDef)inputVoiceDef[0]; // no need to check for null here.
     #region set ccSettings
     TrackCCSettings defaultCCSettings = new TrackCCSettings(null, new List<CCSetting>()
     {
         new PitchWheelPitchControl(5),
         new PressureControl(CControllerType.channelPressure),
         new ModWheelVolumeControl(20,127)
     });
     inputChordDef1.CCSettings = new CCSettings(defaultCCSettings, null);
     #endregion
 }
Example #17
0
 private static void SetBar345PerformanceOptions(InputVoiceDef inputVoiceDef)
 {
     //// actually only bar 3
     //foreach(InputChordDef inputChordDef in inputVoiceDef.InputChordDefs)
     //{
     //    inputChordDef.InputNoteDefs[0].TrkOptions = new TrkOptions(new List<TrkOption>()
     //        {
     //            new TrkOffControl(TrkOffOption.fade),
     //        });
     //}
     //// actually only bar 4
     //foreach(InputChordDef inputChordDef in inputVoiceDef.InputChordDefs)
     //{
     //    inputChordDef.InputNoteDefs[0].TrkOptions = new TrkOptions(new List<TrkOption>()
     //        {
     //            new TrkOffControl(TrkOffOption.stopChord),
     //        });
     //}
     //// actually only bar 5
     //foreach(InputChordDef inputChordDef in inputVoiceDef.InputChordDefs)
     //{
     //    inputChordDef.InputNoteDefs[0].TrkOptions = new TrkOptions(new SpeedControl(2.2F));
     //}
 }
Example #18
0
 /// <summary>
 /// An attempt is made to insert the argument iVoiceDef in a rest in the VoiceDef.
 /// The rest is found using the iVoiceDef's MsPositon and MsDuration.
 /// The first and last objects in the argument must be chords, not rests.
 /// The argument may contain just one chord.
 /// The inserted iVoiceDef may end up at the beginning, middle or end of the spanning rest (which will
 /// be split as necessary).
 /// If no rest is found spanning the iVoiceDef, the attempt fails and an exception is thrown.
 /// This function does not change the msPositions of any other chords or rests in the containing VoiceDef,
 /// It does, of course, change the indices of the inserted lmdds and the later chords and rests.
 /// </summary>
 public void InsertInRest(InputVoiceDef inputVoiceDef)
 {
     Debug.Assert(inputVoiceDef[0] is InputChordDef && inputVoiceDef[inputVoiceDef.Count - 1] is InputChordDef);
     _InsertInRest(inputVoiceDef);
 }
Example #19
0
 /// <summary>
 /// Adds the argument to the end of this VoiceDef.
 /// Sets the MsPositions of the appended UniqueDefs.
 /// </summary>
 public void AddRange(InputVoiceDef voiceDef)
 {
     _AddRange((VoiceDef)voiceDef);
 }
Example #20
0
        /// <summary>
        /// This function has been moved here from the VoiceDef class since it is no longer used by Trks.
        /// It needs re-testing... Should it take account of this.MsPositionReContainer? See Trk.Superimpose(...).
        /// </summary>
        private void _InsertInRest(InputVoiceDef iVoiceDef)
        {
            Debug.Assert(!(Container is Block), "Cannot Insert a Trk in a RestDef inside a Block.");

            int iLmddsStartMsPosReFirstIUD = iVoiceDef[0].MsPositionReFirstUD;
            int iLmddsEndMsPosReFirstIUD = iVoiceDef[iVoiceDef.Count - 1].MsPositionReFirstUD + iVoiceDef[iVoiceDef.Count - 1].MsDuration;

            int restIndex = FindIndexOfSpanningRest(iLmddsStartMsPosReFirstIUD, iLmddsEndMsPosReFirstIUD);

            // if index >= 0, it is the index of a rest into which the chord will fit.
            if(restIndex >= 0)
            {
                InsertVoiceDefInRest(restIndex, iVoiceDef);
                SetMsPositionsReFirstUD(); // just to be sure!
            }
            else
            {
                Debug.Assert(false, "Can't find a rest spanning the chord!");
            }

            AssertVoiceDefConsistency();
        }
Example #21
0
 /// <summary>
 /// Inserts the voiceDef in the list at the given index, and then
 /// resets the positions of all the uniqueDefs in the list.
 /// </summary>
 public void InsertRange(int index, InputVoiceDef voiceDef)
 {
     _InsertRange(index, (VoiceDef)voiceDef);
 }
Example #22
0
        public void AddInputVoice(InputVoiceDef ivd)
        {
            Debug.Assert((ivd.MsPositionReContainer + ivd.MsDuration) <= MsDuration);
            Debug.Assert(ivd.MidiChannel >= 0 && ivd.MidiChannel <= 3);
            #region check for an existing InputVoiceDef having the same MidiChannel
            foreach(VoiceDef voiceDef in _voiceDefs)
            {
                InputVoiceDef existingInputVoiceDef = voiceDef as InputVoiceDef;
                if(existingInputVoiceDef != null)
                {
                    Debug.Assert(existingInputVoiceDef.MidiChannel != ivd.MidiChannel, "Error: An InputVoiceDef with the same MidiChannel already exists.");
                }
            }
            #endregion

            int startPos = ivd.MsPositionReContainer;
            ivd.MsPositionReContainer = 0;
            foreach(IUniqueDef iud in ivd.UniqueDefs)
            {
                iud.MsPositionReFirstUD += startPos;
            }

            _voiceDefs.Add(ivd);

            Blockify();

            AssertNonEmptyBlockConsistency();
        }
Example #23
0
        private static void SetBar1PerformanceOptions(InputVoiceDef inputVoiceDef)
        {
            InputChordDef inputChordDef1 = (InputChordDef)inputVoiceDef[0]; // no need to check for null here.

            #region set voiceDef level trkOptions
            //foreach(InputChordDef inputChordDef in inputVoiceDef.InputChordDefs)
            //{
            //    inputChordDef.TrkOptions = new TrkOptions(new List<TrkOption>()
            //        {
            //            new TrkOffControl(TrkOffOption.fade),
            //        });
            //}
            #endregion

            #region set chord level TrkOptions
            //inputChordDef1.TrkOptions = new TrkOptions(new List<TrkOption>()
            //{
            //    new VelocityScaledControl(3),
            //    new PedalControl(PedalOption.holdAll),
            //    new TrkOffControl(TrkOffOption.fade),
            //    new SpeedControl(1.5F)
            //});
            #endregion chordTrkOptions

            #region set note level TrkOptions
            //inputChordDef1.InputNoteDefs[0].TrkOptions = new TrkOptions(new VelocityScaledControl(2));
            #endregion

            #region set noteOn TrkOptions
            //NoteOn nOn = inputChordDef1.InputNoteDefs[0].NoteOn;
            //nOn.TrkOptions = new TrkOptions(new List<TrkOption>()
            //{
            //    new VelocityScaledControl(3),
            //    new PedalControl(PedalOption.holdAll),
            //    new TrkOffControl(TrkOffOption.undefined),
            //    new SpeedControl(2.1F)
            //});
            #endregion set noteOn TrkOptions

            #region set noteOff TrkOptions
            //List<int> newTrkOffs = new List<int>() { 0, 4, 2, 3, 5 };
            //inputChordDef1.InputNoteDefs[0].NoteOff.TrkOffs = newTrkOffs;
            //inputChordDef1.InputNoteDefs[0].NoteOn.TrkOffs = newTrkOffs;
            #endregion set noteOff TrkOptions
        }