Пример #1
0
        internal int GetMainValue(eCtlr ectlr, int portchan, out bool multiple)
        {
            //* return single value for a controller, allowing for overrides
            //* used by frmMultiMap to display a value for Pan, Vol, Patch
            //* multiple = true if ctlr not overridden, and more than one ctlr in portchan
            //* return -1 if patch and chan == 9 (percussion)
            multiple = false;
            int ctlr = (int)ectlr;

            if (portchan < 0)
            {
                return(Dflt[ctlr]);
            }
            if (Override[ctlr] == null)
            {
                LogicError.Throw(eLogicError.X015);
                return(Dflt[ctlr]);
            }
            if (Override[ctlr][portchan] >= 0)
            {
                return(Override[ctlr][portchan]);
            }
            clsMap <int> map = DataLast[ctlr, portchan];

            if (map == null)
            {
                return(Dflt[ctlr]);
            }
            if (map.Count > 1)
            {
                multiple = true;
            }
            if (ctlr == PatchCtlrNum && portchan % 16 == 9)
            {
                return(-1);                                       //channel 10 percussion
            }
            //return map.ValByIndex(0);
            return(map.GetFirstValue());
        }
Пример #2
0
        internal string[] GetPatchList(int portchan)
        {
            //* used by frmSummary
            clsMap <int> map = DataLast[PatchCtlrNum, portchan];

            if (map == null)
            {
                return new String[] { "" }
            }
            ;
            List <string> list = new List <string>();

            //for (int i = 0; i < map.Count; i++) list.Add(GeneralMidiList.Desc[map.ValByIndex(i)]);
            foreach (KeyValuePair <int, int> pair in map)
            {
                list.Add(GeneralMidiList.Desc[pair.Value]);
            }
            if (list.Count == 0)
            {
                list.Add("");
            }
            return(list.ToArray());
        }
    }
Пример #3
0
 private void CreateDataLast(clsFileStream.clsEvStrm[] stream)
 {
     if (stream == null)
     {
         return;
     }
     foreach (clsFileStream.clsEvShort ev in stream.OfType <clsFileStream.clsEvShort>())
     {
         //if (ev.Port == 1) Debugger.Break();
         int status = ev.Status & 0xf0;
         if ((status != 0xb0) && (status != 0xc0))
         {
             continue;                                //not ctlr or patch
         }
         if (status == 0xb0 && !IsDataLast(ev.Msg))
         {
             continue;                                 //ctlr but dataall
         }
         int chan = ev.Status & 0x0f;
         int ctlr = ev.Msg;
         if (status == 0xc0)
         {
             ctlr = PatchCtlrNum;          //patch: last ctlr
         }
         if (DataLast[ctlr, chan] == null)
         {
             DataLast[ctlr, chan] = new clsMap <int>(Dflt[ctlr]);
         }
         int data = ev.Data;
         if (status == 0xc0)
         {
             data = ev.Msg;
         }
         DataLast[ctlr, chan].Add(ev.Ticks, data);
     }
 }
Пример #4
0
        private void WriteCondTrk()
        {
            List <clsFileStream.clsEvStrm> listev = new List <clsFileStream.clsEvStrm>();

            using (stTrk = new MemoryStream()) {
                BinaryWriter br = new BinaryWriter(stTrk);
                MWriterTrk = new clsMWriter(br);

                //* get current conductor track
                //* should not incl. keys or tsigs
                //* should not incl. tempos
                foreach (clsFileStream.clsEvStrm ev in FS.Strm)
                {
                    if (ev.Trk == null && ev.indWrite)
                    {
                        listev.Add(ev);
                    }
                }

                //* save keys
                foreach (clsKeyTicks key in P.F.Keys.Keys)
                {
                    //sbyte midikey = (sbyte)key.MidiKey;
                    byte[] data = new byte[] { (byte)key.MidiKey, (byte)key.MajMin };
                    clsFileStream.clsEvStrm ev = new clsFileStream.clsEvMeta(0, key.Ticks, -1, 0x59, data);
                    int index = listev.BinarySearch(ev);
                    if (index < 0)
                    {
                        index = ~index;
                    }
                    listev.Insert(index, ev);
                }

                //* save time signatures
                foreach (clsMTime.clsTSigBB tsig in P.F.MTime.TSigs)
                {
                    byte[] data = new byte[] { (byte)tsig.NN, (byte)tsig.DDMidi, (byte)tsig.MidiClocksPerMetClick, (byte)8 };
                    clsFileStream.clsEvStrm ev = new clsFileStream.clsEvMeta(0, tsig.Tick, -1, 0x58, data);
                    int index = listev.BinarySearch(ev);
                    if (index < 0)
                    {
                        index = ~index;
                    }
                    listev.Insert(index, ev);
                }

                //* save tempos
                //clsFileStream.clsMap<int> tempomap = null;
                clsMap <int> tempomap = null;
                if (P.F?.FSTrackMap?.TempoMap != null)
                {
                    tempomap = P.F.FSTrackMap.TempoMap;
                }
                else if (P.F?.FileStreamConv?.TempoMap != null)
                {
                    tempomap = P.F.FileStreamConv.TempoMap;
                }
                if (tempomap != null)
                {
                    //for (int i = 0; i < tempomap.Count; i++) {
                    //  int ticks = tempomap.KeyByIndex(i);
                    //  int tempo = tempomap.ValByIndex(i);
                    foreach (KeyValuePair <int, int> pair in tempomap)
                    {
                        int    ticks = pair.Key;
                        int    tempo = pair.Value;
                        byte[] data  = clsFileStream.ConvUIntF((uint)tempo, 3);
                        clsFileStream.clsEvStrm ev = new clsFileStream.clsEvMeta(0, ticks, -1, 0x51, data);
                        int index = listev.BinarySearch(ev);
                        if (index < 0)
                        {
                            index = ~index;
                        }
                        listev.Insert(index, ev);
                    }
                }

                //* write to trk stream
                int prevticks = 0;
                foreach (clsFileStream.clsEvStrm ev in listev)
                {
                    if (ev is clsFileStream.clsEvBeat)
                    {
                        continue;
                    }
                    WriteStrmMsg(ref prevticks, ev);
                }
                WriteToFileStream(prevticks);
            }
        }
Пример #5
0
        private void SendCtlrs(int ticks, int chanlo, int chanhi)
        {
            //* send current midi ctlr values (or sequence of values) for ticks
            //* for all channels
            //* used by streamplay locate and frmTrackMap record
            //* ticks= -1: send ticks0 DataAll and first DataLast controller

            //xplay.ResetAllCtlrs();
            clsFileStream.clsPlay.ResetAllCtlrsStatic(MidiPlay.OutMStream);

#if DebugSend
            XStreamDebug = new FileStream(Cfg.CfgPath + @"\MidiCtlrsSend.debug." + FileNum++ + ".txt", FileMode.Create, FileAccess.Write); //overwrite
            using (XSWDebug = new StreamWriter(XStreamDebug)) {
                //XSWDebug = new StreamWriter(XStreamDebug);
                DebugFmt = "{0,-4} {1:X2} {2:X2} {3:X2}";
                XSWDebug.WriteLine(DebugFmt, "src", "B0", "B1", "B2");
#endif

            //* send all
            for (int chan = chanlo; chan <= chanhi; chan++)
            {
                foreach (sMsgDataTicks ev in DataAll[chan])
                {
                    if (ev.Ticks > Math.Max(0, ticks))
                    {
                        break;
                    }
                    //if (port != play.Port) continue;
                    int status = 0xb0 | chan;
                    int msg    = ev.Msg;
                    int data   = ev.Data;
#if DebugSend
                    XSWDebug.WriteLine(DebugFmt, "all", status, msg, data);
#endif
                    //xplay.SendDirect(status, msg, data);
                    MidiPlay.OutMStream.SendShortMsg(status, msg, data);
                }
            }

            //* send last
            for (int ctlr = 0; ctlr < 129; ctlr++)
            {
                //if (ctlr == PatchCtlrNum) Debugger.Break();
                if (!IsDataLast(ctlr))
                {
                    continue;
                }
                for (int chan = chanlo; chan <= chanhi; chan++)
                {
                    //if (port != play.Port) continue;
                    int?val = null;
                    if (Override[ctlr] != null && Override[ctlr][chan] >= 0) //overridden
                    {
                        val = Override[ctlr][chan];
                    }
                    else
                    {
                        clsMap <int> map = DataLast[ctlr, chan];
                        if (map != null)
                        {
                            //if (ticks < 0 && map.Count > 0) val = map.ValByIndex(0);  //first value
                            if (ticks < 0 && map.Count > 0)
                            {
                                val = map.GetFirstValue();
                            }
                            else
                            {
                                val = map[ticks]; //map[ticks] may be null
                            }
                        }
                    }
                    if (val == null)
                    {
                        continue;
                    }
                    int status, msg, data;
                    if (ctlr == PatchCtlrNum)
                    {
                        status = 0xc0 | chan;
                        msg    = val.Value;
                        data   = 0;
                    }
                    else //not patch
                    {
                        status = 0xb0 | chan;
                        msg    = ctlr;
                        data   = (byte)val;
                        if (msg == 0 && P.frmStart.chkFilterMidiBank.Checked)
                        {
                            continue;
                        }
                    }
#if DebugSend
                    XSWDebug.WriteLine(DebugFmt, "last", status, msg, data);
                    //if (status == 0xb8 && msg == 0) Debugger.Break();
#endif
                    //xplay.SendDirect(status, msg, data);
                    MidiPlay.OutMStream.SendShortMsg(status, msg, data);
                }
            }
#if DebugSend
        }

        //XSWDebug.Close();
#endif
        }