예제 #1
0
        private void WriteChordTrack()
        {
            //* contains labels and/or midinotes
            //* last track in midi file
            if (P.F?.CF?.Evs == null || P.F.CF.Evs.Count == 0)
            {
                return;
            }
            int prevticks = 0;

            using (stTrk = new MemoryStream()) {
                BinaryWriter br = new BinaryWriter(stTrk);
                MWriterTrk = new clsMWriter(br);
                string strtitle = (P.frmSaveMidiFileAs.txtChordTrackTitle.Text == "") ?
                                  "Chords" : P.frmSaveMidiFileAs.txtChordTrackTitle.Text;
                byte[] bytestitle = Encoding.ASCII.GetBytes(strtitle);
                clsFileStream.clsEvTitle evtitle = new clsFileStream.clsEvTitle(0, 0, -1, bytestitle); //trk param not used
                evtitle.WriteTitle(this, 0);
                foreach (clsCF.clsEv evcf in P.F.CF.Evs)
                {
                    if (P.frmSaveMidiFileAs.chkSaveChordLabels.Checked)
                    {
                        byte[] bytestext = Encoding.ASCII.GetBytes(evcf.ChordName(eKBTrans.None, kbtranskey: false));
                        clsFileStream.clsEvStrm evstrm = new clsFileStream.clsEvMeta(0, evcf.OnTime, -1, 0x01, bytestext);
                        WriteStrmMsg(ref prevticks, evstrm);
                    }
                    if (P.frmSaveMidiFileAs.chkSaveChordTrack.Checked)
                    {
                        int status = 0x90 | (int)(P.frmSaveMidiFileAs.nudChordChan.Value - 1);
                        WriteChord(ref prevticks, evcf, status, evcf.OnTime, 80); //ON evs of chord
                        WriteChord(ref prevticks, evcf, status, evcf.OffTime, 0); //OFF evs of chord
                    }
                }
                WriteToFileStream(prevticks);
            }
        }
예제 #2
0
        private void WriteTrack(clsTrks.T trk)
        {
            int prevticks = 0;

            using (stTrk = new MemoryStream()) {
                BinaryWriter br = new BinaryWriter(stTrk);
                MWriterTrk = new clsMWriter(br);
                string strtitle = (P.F.frmTrackMap == null || P.F.frmTrackMap.txtTitles[trk] == null) ?
                                  FS.Title[trk] : P.F.frmTrackMap.txtTitles[trk].Text;
                byte[] bytestitle = Encoding.ASCII.GetBytes(strtitle);
                clsFileStream.clsEvTitle evtitle = new clsFileStream.clsEvTitle(0, 0, -1, bytestitle); //trk param not used
                evtitle.WriteTitle(this, 0);

                //* write overriding controllers (vol, pan, patch)
                clsFileStream.clsEvShort evshort;
                bool indvol = false, indpan = false, indpatch = false;
                if (P.F.Chan[trk] >= 0)
                {
                    int  chan = P.F.Chan[trk];
                    byte vol  = (byte)P.F.Vol[chan];
                    if (vol <= 127)
                    {
                        indvol  = true;
                        evshort = new clsFileStream.clsEvShort(0, trk.TrkNum, (byte)(0xb0 | chan), 7, vol);
                        WriteStrmMsg(ref prevticks, evshort);
                    }
                    byte pan = (byte)P.F.Pan[chan];
                    if (pan <= 127)
                    {
                        indpan  = true;
                        evshort = new clsFileStream.clsEvShort(0, trk.TrkNum, (byte)(0xb0 | chan), 10, pan);
                        WriteStrmMsg(ref prevticks, evshort);
                    }
                    byte patch = (byte)P.F.Patch[chan];
                    if (patch <= 127)
                    {
                        indpatch = true;
                        evshort  = new clsFileStream.clsEvShort(0, 0, trk.TrkNum, (byte)(0xc0 | chan), patch);
                        WriteStrmMsg(ref prevticks, evshort);
                    }
                }

                foreach (clsFileStream.clsEvStrm ev in FS.Strm)
                {
                    if (ev.Trk != trk)
                    {
                        continue;
                    }
                    if (ev is clsFileStream.clsEvBeat)
                    {
                        continue;
                    }
                    if (ev is clsFileStream.clsEvShort)
                    {
                        clsFileStream.clsEvShort evsh = (clsFileStream.clsEvShort)ev;
                        int status = evsh.Status & 0xf0;
                        if (indvol && status == 0xb0 && evsh.Msg == 7)
                        {
                            continue;                                 //vol overriden
                        }
                        if (indpan && status == 0xb0 && evsh.Msg == 10)
                        {
                            continue;                                  //pan overriden
                        }
                        if (indpatch && status == 0xc0)
                        {
                            continue;                  //patch overriden
                        }
                    }
                    WriteStrmMsg(ref prevticks, ev);
                }
                WriteToFileStream(prevticks);
            }
        }