internal static int Find(clsFileStream fs, clsFileStream.clsEvStrm[] strm, int ticks)
            {
                //* return index of ev on or after ticks
                if (ticks == 0)
                {
                    return(0);
                }
                //int index = Array.BinarySearch<clsEvStrm>(strm, new clsEvShort(ticks, 0, 0, 0, 0));
                int index = Array.BinarySearch <clsEvStrm>(strm, new clsEvBeat(new clsMTime.clsBBT(ticks)));

                if (index < 0)
                {
                    index = ~index;     //if not found, get index after ticks
                }
                else //if found, locate first ev with ticks
                {
                    while (strm[index].Ticks == ticks)
                    {
                        if (--index < 0)
                        {
                            break;
                        }
                    }
                    index++;
                }
                return(index);
            }
        internal clsLoadMidiFile(clsFileStream filestream,
                                 string filename, clsTrks.Array <bool> trkselect, bool excl10, bool firsttime)
        {
            bool condtrkempty = P.F.CondTrkEmpty;

            //P.F.Project.MidiPath = filename;
            P.frmSC.cmdMultiMap.Enabled = true;
            if (P.F.frmChordMap != null)
            {
                P.F.frmChordMap.cmdMultiMap.Enabled = true;
            }
            FileStream = filestream;
            //FileStream.Summary = summary;
            //FileStream.Transpose = transpose;
            if (trkselect != null)
            {
                FileStream.TrkSelect = trkselect;
            }
            Excl10 = excl10;
            if (!ReadFile(firsttime))
            {
                if (condtrkempty && !P.F.CondTrkEmpty) //non-empty conductor track found
                {
                    condtrkempty = false;
                    if (!ReadFile(firsttime))
                    {
                        ReadError();
                    }
                }
                else
                {
                    ReadError();
                }
            }
        }
Exemple #3
0
            internal clsWChord(clsMTime.clsBBT bbt, bool[] chord)
            {
                clsFileStream csvfileconv = P.F.frmChordMap.CSVFileConv;

                BBT   = bbt;
                Chord = chord;
            }
Exemple #4
0
        internal clsFileStream LoadMidiFileHeaderFromCF()
        {
            //* filename = ???.chp (from load chord file)
            //P.F.ProjectPath = GetProjectPath(chpfilename);
            //if (midifilename == "") {
            //  try {
            //    string dir = Path.GetDirectoryName(chpfilename);
            //    midifilename = GetFileName("MidiFiles|*.mid", "Midi File", dir);
            //    if (midifilename == "") return null;
            //  }
            //  catch (MidiChordFileException) {
            //    return null;
            //  }
            //}
            P.F.Project.MidiExists = File.Exists(P.F.Project.MidiPath);
            if (!P.F.Project.MidiExists)
            {
                return(null);
            }
            //P.frmStart.lblMidLoad.Text = "loaded";

            clsFileStream fs;

            fs = new clsFileStream(P.F.Project.MidiPath); //readheader only

            //EnablePlayCtls();
            return(fs);
        }
Exemple #5
0
            internal clsWChord(int qi, bool[] chord)
            {
                clsFileStream csvfileconv = P.F.frmChordMap.CSVFileConv;

                BBT   = new clsMTime.clsBBT(qi * P.F.TicksPerQI);
                Chord = chord;
            }
 internal clsChordSegs(clsFileStream filestream, Forms.frmChordMap frmnotemap, eAlign align, bool setatts)
 {
     if (align == eAlign.None)
     {
         return;
     }
     FS         = filestream;
     frmNoteMap = frmnotemap;
     Align      = align;
     ApplyChords(setatts);
 }
            //internal int SetVolume(byte vol) {
            //  //* set output volume MSB of both channels to vol
            //  int msg = (vol << 28) | (vol << 12);
            //  int rtn = midiOutSetVolume(hmi, msg);
            //  return rtn;
            //}

            internal static int FactorMidiTempo(clsFileStream filestream, int miditempo)
            {
                if (P.frmStart.TempoFactor == 0)
                {
                    P.frmStart.TempoFactor = 1;
                }
                if (P.frmStart.TempoFactor != 1)
                {
                    miditempo = (int)(miditempo / P.frmStart.TempoFactor);
                    miditempo = Math.Min(Math.Max(miditempo, filestream.MidiTempoMin), filestream.MidiTempoMax);
                }
                return(miditempo);
            }
Exemple #8
0
        //internal void StartRecord(Form playform, clsFileStream filestream, clsMute mute) {
        //  if (P.F.FileStreamMM != null) P.F.FileStreamMM.InitRec();
        //  StartPlayRecord(playform, filestream, mute);
        //}

        //internal void StartPlay(Form playform, clsFileStream filestream, clsMute mute) {
        //  StartPlayRecord(playform, filestream, mute);
        //}

        internal void StartPlay(Form playform, clsFileStream filestream, clsMute mute)
        {
            //* called from form thread
            //if (PlayCmdOn) DebugPlay();  //already playing?
            PlayableForms.CmdState_Stopped(); //before play starts - in case it fails
            RefreshBBTTimer.Stop();
            BBTQueue.Clear();

            //if (P.F.AutoSync != null && (!P.F.MidiFileLoaded || !P.frmStart.chkPlayMidiPriority.Checked)) {
            if (MidiPlay.OutMStream == null)
            {
                return;
            }
            P.F.Mute.StartPlay();
            //if (P.F.CurrentBBT.Bar >= new clsMTime.clsBBT(P.F.MaxTicks).Bar - 2) return;  //don't start too near the end
            if (P.F.CurrentBBT.Bar >= P.F.MaxBBT.Bar - 2)
            {
                return;                                      //don't start too near the end
            }
            if (/*clsPlay.PlayExists() &&*/ Forms.frmSC.MenuMonitor)
            {
                clsPlay.InitStopwatch();
            }
            Forms.frmSC.ShowfrmPCKBIn();
            if (P.frmSC.Play != null)
            {
                P.frmSC.Play.BBTSwitch = null;
                P.frmSC.Play.NewReset();
            }
            ShowGCCollectionCounts("Start Play");
            P.F.WaitPlay  = new clsWaitPlay(filestream, MidiPlay.OutMStream, mute);
            StreamStartBB = P.F.CurrentBBT.Copy();
            BeatCount     = StreamStartBB.Bar;
            try {
                //lock (TimerLock) {
                P.F.WaitPlay.Start();
                //}
            }
            catch {
                DebugPlay();
                return;
            }

            //if (P.frmStart.chkPlaySustain.Checked) clsPlay.clsSustain.PlayPedalStatic(true);
            //clsPlayKeyboard.PlayNearestChordNote = P.frmStart.chkPlayKBChord.Checked;
            P.frmStart.StreamPlayOnAll();      //enable/disable StartPlay/StopPlay etc.
            P.frmStart.FormsStreamOnOff(true); //enable/disable controls (not StartPlay/StopPlay etc.)
        }
 internal clsLoadMidiFile(clsFileStream filestream) //readheader only
 //P.F.MidiFilePath = filename;
 {
     P.frmSC.cmdMultiMap.Enabled = true;
     if (P.F.frmChordMap != null)
     {
         P.F.frmChordMap.cmdMultiMap.Enabled = true;
     }
     FileStream = filestream;
     clsTrks.Array <List <clsFileStream.clsOO> > oo;
     if (!OpenFile() || !ReadHeader(true, out oo))
     {
         MessageBox.Show("MidiFile Read Error");
         throw new MidiFileException();
     }
 }
Exemple #10
0
 internal clsWaitPlay(clsFileStream filestream, iBassMidiOut bassout, clsMute mute)
 {
     Resolution          = (int)P.frmStart.nudPlayResolution.Value;
     HalfResolution      = Resolution / 2;
     dStartPlay          = new delStartPlay(StartPlay);
     PlayThread          = new Thread(new ThreadStart(StartPlay));
     PlayThread.Priority = ThreadPriority.AboveNormal;
     PlayThread.Name     = "Play Thread";
     //Debug.WriteLine("clsWaitPlay: ThreadId = " + PlayThread.ManagedThreadId);
     FileStream   = filestream;
     BASSOut      = bassout;
     Mute         = mute;
     dUpdateTempo = new delegUpdateTempo(P.frmStart.UpdateLblTempo);
     ResetAllCtlrsTimer.AutoReset = false;
     ResetAllCtlrsTimer.Elapsed  += ResetAllCtlrsTimer_Elapsed;
 }
            //internal void Stop() {
            //  if (MidiStream == null) return;
            //  indStop = true;
            //}

            internal static bool BypassEv(clsFileStream filestream, clsMute mute, clsEvStrm ev)
            {
                //* return true to bypass
                if (ev is clsFileStream.clsEvBeat)
                {
                    return(false);                        //retain beats
                }
                if (ev.Trk == null)
                {
                    return(false);         //retain conductor trk
                }
                if (ev is clsEvTempo)
                {
                    return(false);           //retain meta msgs (tempo)
                }
                if (ev is clsEvSystem)
                {
                    return(true);            //bypass system/meta
                }
                if (ev is clsEvMeta)
                {
                    return(true);          //bypass system/meta
                }
                clsEvShort evshort      = (clsEvShort)ev;
                byte       status       = evshort.Status;
                int        statusprefix = status & 0xf0;

                if (statusprefix >= 0xf0)
                {
                    return(false);
                }
                bool on   = (statusprefix == 0x90 && evshort.Data > 0); //all others evs = OFF
                int  chan = status & 0x0f;

                if (mute.MutedEv(ev.Trk, chan, on))
                {
                    return(true);
                }
                if (statusprefix != 0x90 && statusprefix != 0x80)
                {
                    return(filestream.MidiCtlrs.Bypass(evshort));
                }
                return(false);
            }
Exemple #12
0
 internal void CreateEvsFromMidi(clsFileStream filestream)
 {
     //* create evs from notemapmidi
     NoChords = true;
     Evs      = new List <clsEv>();
     for (int q = 0; q < P.F.MaxBBT.QI; q++)
     {
         clsNoteMapMidi notemapmidi = filestream.NoteMap;
         //if (q > 0 && notemapmidi[q] == notemapmidi[q - 1]) continue;
         if (q > 0 && notemapmidi.FullMapEquals(q, q - 1))
         {
             continue;
         }
         clsMTime.clsBBT bbt = new clsMTime.clsBBT(q * P.F.TicksPerQI);
         //clsEv ev = new clsEv(this, bbt, notemapmidi[q], null);
         clsEvPitch ev = new clsEvPitch(this, bbt, notemapmidi[q, false, true]); //unmodded
         ev.ChordQualifier = "";
         if (ev.Notes.Length == 0 && P.frmStart.chkIgnoreNullChords.Checked)
         {
             continue;                                              //null chord
         }
         if (Evs.Count > 0 && Evs[Evs.Count - 1].Notes.Length == 0) //previous ev was null
         {
             if (bbt.Ticks - Evs[Evs.Count - 1].OnTime <= Forms.frmSC.SyncopationDefault.Ticks)
             {
                 Evs.RemoveAt(Evs.Count - 1);
             }
         }
         if (Evs.Count > 0)
         {
             Evs[Evs.Count - 1].OffBBT = bbt;         //set offtime for previous line
         }
         Evs.Add(ev);
     }
     if (Evs.Count > 0)
     {
         SetLastEv();
     }
     SyncEvsToKeys();
     CalcRange();
 }
Exemple #13
0
        internal void PropagatePW(clsFileStream filestream, int len, clsTrks.T trk)
        {
            //* null trk = all trks
            //* initialize PB
            if (trk == null)
            {
                PB = new clsTrks.Array <short[]>(delegate() {
                    short[] pw = new short[len];
                    for (int i = 0; i < len; i++)
                    {
                        pw[i] = -1;
                    }
                    return(pw);
                });
            }
            else
            {
                PB[trk] = new short[len];
                for (int i = 0; i < len; i++)
                {
                    PB[trk][i] = -1;
                }
            }

            //* read stream
            clsFileStream.clsEvStrm[] strm = filestream.Strm;
            for (int i = 0; i < strm.Length; i++)
            {
                if (strm[i] is clsFileStream.clsEvShort)
                {
                    clsFileStream.clsEvShort ev = ((clsFileStream.clsEvShort)strm[i]);
                    if (trk != null && trk != ev.Trk)
                    {
                        continue;
                    }
                    if ((ev.Status & 0xe0) != 0xe0)
                    {
                        continue;                    //not pitchbend
                    }
                    int val = ev.Msg + (ev.Data << 7);
                    PB[ev.Trk][ev.QTime] = (short)val; //channel not used - only track
                }
            }

            //* propagate PB
            foreach (clsTrks.T t in PB.Next)
            {
                if (trk != null && trk != t)
                {
                    continue;
                }
                short pw = 8192; //centre (default)
                for (int qi = 0; qi < len; qi++)
                {
                    if (PB[t][qi] >= 0)
                    {
                        pw = PB[t][qi];        //set current value
                    }
                    PB[t][qi] = pw;
                }
            }
        }
Exemple #14
0
        internal void CallBack(eMidiMsgType mtype, int?val, clsFileStream filestream, clsMTime.clsBBT BASSbbt)
        {
            //Debug.Write("*");
            //MTime = P.frmStart.GetMTime();
            //if (MTime == null) return;
            switch (mtype)
            {
            /* may want use in future???
             * case eMidiMsgType.Beat:  //from sustain pedal - beats only (no bars)
             * LocateBeat(BeatCount++);
             * break;
             */
            case eMidiMsgType.SPP:
                //* sent by Sonar
                //* not sent by BIAB
                //if (indPlayActive != ePlay.None) return;
                //if (indPlayActive == ePlay.SyncEnabled) indPlayActive = ePlay.SyncActive;
                MidiClockCount = val.Value * 6;
                Debug.WriteLine("Callback: SPP: MidiClockCount = " + MidiClockCount);
                StartMidiClockCount = MidiClockCount;
                int ticksspp = (MidiClockCount * P.F.MTime.TicksPerQNote) / P.F.MTime.MidiClocksPerQNote;
                RefreshBBT(new clsMTime.clsBBT(ticksspp));
                //LocateBeat(MidiClockCount / MTime.MidiClocksPerBeat);
                break;

            //case clsMidiIn.eMidiMsgType.BarBeat:  //midistream
            //  LocateBeat(BeatCount++);
            //  break;
            case eMidiMsgType.StreamBASS: //waitplay
                if (BASSbbt.TicksRemBeat == 0)
                {
                    RefreshBBT(BASSbbt);
                    //Debug.WriteLine("global refreshbbt = " + BASSbbt.ToStringBBT());
                    //P.F.frmTrackMap.FileStream.RecordBeatNM();
                    P.F.FSTrackMap.RecordBeatNM();
                }
                return;

            case eMidiMsgType.MidiClock: //external sequencer with start/stop/continue/clock
                if (indPlayActive != ePlay.SyncActive && indPlayActive != ePlay.SyncEnabled)
                {
                    return;
                }
                if (P.frmStart.chkMidiStartStop.Checked && indPlayActive != ePlay.SyncActive)
                {
                    return;
                }
                //if (filestream == null) {  //sync
                //  if (!P.frmStart.chkMidiStartStop.Checked) return;
                //  if (indPlayActive == ePlay.Stream) return;
                //}

                //{
                //  int ticks = (MidiClockCount * P.F.MTime.TicksPerQNote) / P.F.MTime.MidiClocksPerQNote;
                //  Debug.WriteLine("MidiClockCount = " + MidiClockCount
                //    + " Ticks = " + ticks
                //    + " QNotes*100 = " + (ticks * 100) / P.F.MTime.TicksPerQNote);
                //}

                int ticks = (MidiClockCount * P.F.MTime.TicksPerQNote) / P.F.MTime.MidiClocksPerQNote;
                if (ticks <= P.F.MaxBBT.Ticks)
                {
                    if (ticks >= 0)
                    {
                        clsMTime.clsBBT bbt = new clsMTime.clsBBT(ticks);
                        //if (bbt.TicksRemBeat == 0 && MidiClockCount > (StartMidiClockCount + LeadInClocks)) {
                        if (bbt.TicksRemBeat == 0 && MidiClockCount > StartMidiClockCount)
                        {
                            //P.F.CurrentBBT = bbt;
                            RefreshBBT(bbt);
                        }
                        Debug.WriteLine("Callback: MidiClock: MidiClockCount = " + MidiClockCount);

                        //if (((MidiClockCount % MTime.MidiClocksPerBeat) == 0)  //next beat
                        //&& (MidiClockCount > StartMidiClockCount + LeadInClocks)) {
                        //  LocateBeat(MidiClockCount / MTime.MidiClocksPerBeat);
                        //}
                    }
                    MidiClockCount++;
                }
                return;

            case eMidiMsgType.StreamEnded:
                if (!indPause)
                {
                    //P.F.CurrentBBT = new clsMTime.clsBBT(0);
                    P.frmSC.Play?.NewReset();
                    RefreshBBT(new clsMTime.clsBBT(P.F.StartBar, 0, 0));
                    indPause = true;
                }
                return;

            case eMidiMsgType.Stop:
                if (MidiPlay.MidiInSync != null)
                {
                    indPlayActive = ePlay.SyncEnabled;
                }
                return;

            case eMidiMsgType.Start:
                //* should only be called if starting from beginning of song
                //* BIAB sends this whenever song is started, from any position
                if (P.frmStart.chkMidiStartStop.Checked)
                {
                    if (indPlayActive == ePlay.SyncEnabled)
                    {
                        indPlayActive = ePlay.SyncActive;
                    }
                    //StartMidiClockCount = 0;
                    //LeadInClocks = P.F.MTime.GetTSig(0).MidiClocksPerBar * (int)P.frmStart.nudLeadInBars.Value;
                    //MidiClockCount = -LeadInClocks;
                    //P.F.CurrentBBT = new clsMTime.clsBBT(0);
                    //StartSync();
                }
                return;

            case eMidiMsgType.Continue: //does not appear to be sent by BIAB
                if (P.frmStart.chkMidiStartStop.Checked)
                {
                    if (indPlayActive == ePlay.SyncEnabled)
                    {
                        indPlayActive = ePlay.SyncActive;
                    }
                    StartSync();
                }
                return;
            }
        }
Exemple #15
0
 internal void CallBack(eMidiMsgType mtype, clsFileStream filestream)
 {
     //* called from stream
     CallBack(mtype, null, filestream, null);
 }
Exemple #16
0
        internal int[] GetFillPercent(clsFileStream filestream, clsMTime.clsSegment segment, bool indbass)
        {
            //* return occupancy as a percent for each modded note in segment
            int  offsetqi  = 0;
            bool offsetpre = false;
            int  swing     = (int)P.frmCfgChords.trkSwing.Value - 50;

            if (segment is clsMTime.clsSegHalfBar && swing != 0)
            {
                offsetqi = swing * segment.SegQIWidth / 50;
                if (segment.SegBBTLo.BeatsRemBar > 0)
                {
                    offsetpre = true;
                }
            }
            int[] ret        = new int[12];
            int   maxpercent = 0;

            for (int n = 0; n < 12; n++)
            {
                int totqiall = 0;
                int totqion  = 0;
                int segqilo  = segment.SegQILo;
                int segqihi  = segment.SegQIHi;
                if (offsetpre)
                {
                    segqilo += offsetqi;
                }
                else
                {
                    segqihi += offsetqi;
                }
                if (indbass || P.frmCfgChords.chkWeightedScores.Checked)
                {
                    foreach (clsTrks.T trk in P.F.Chan.Next)
                    {
                        bool select = (indbass) ? P.F.FSTrackMap.TrkType[trk] == clsFileStream.eTrkType.Bass : filestream.TrkSelect[trk];
                        if (select && P.F.Chan[trk] != 9)   //not percussion
                        {
                            totqiall += segment.SegQIWidth; //qi * num selectedtrks
                            for (int qi = segqilo; qi <= segqihi; qi++)
                            {
                                //* may be trimmed - OK
                                //* may be quantized - not recommended, but should still work
                                if (IsF(qi, n) && this[qi, n, trk])
                                {
                                    totqion++;
                                }
                            }
                            //if (indbass) trk = trk + 1 - 1;
                        }
                    }
                }
                else //unweighted
                {
                    totqiall = segment.SegQIWidth;
                    for (int qi = segqilo; qi <= segqihi; qi++)
                    {
                        if (IsF(qi, n))
                        {
                            totqion++;
                        }
                    }
                }
                int percent = (totqiall == 0) ? 0 : (totqion * 100) / totqiall;
                maxpercent = Math.Max(maxpercent, percent);
                ret[n]     = percent;
            }

            if (!indbass && maxpercent > 0)
            {
                for (int i = 0; i < 12; i++)
                {
                    if (ret[i] > 0)
                    {
                        ret[i] = (ret[i] * 100) / maxpercent;
                    }
                }
            }
            return(ret);
        }
Exemple #17
0
        internal clsNoteMapMidi(clsOnOff onoff, clsTrks.Array <int> trkminpitch, clsTrks.Array <int> trkmaxpitch, clsFileStream filestream)
        {
            //NumTrks = numtrks;
            TrkMinPitch = trkminpitch;
            TrkMaxPitch = trkmaxpitch;
            int len = P.F.MaxBBT.MaxNoteMapQI;

            Filter = new byte[len, 12];
#if MemoryInfo
            long before = GC.GetTotalMemory(true);
#endif
            PropagatePW(filestream, len, null);
            _Map = new clsTrks.Array <ushort[]>(delegate() { return(new ushort[len]); });
            //NewMap = clsTrks.Array<ushort[]>.NewClass(delegate () { return new ushort[onoff.Length]; });
            InitMap(onoff, null, filestream.ExclPB);
            _FullMap = new clsTrks.Array <BigInteger[]>(delegate() { return(new BigInteger[len]); }); //BigInteger 128 bits
            //NewFullMap = clsTrks.Array<BigInteger[]>.NewClass(delegate () { return new BigInteger[onoff.Length]; });//BigInteger 128 bits
            InitFullMap(onoff, null, filestream.ExclPB);
#if MemoryInfo
            long after = GC.GetTotalMemory(true);
            long diff  = after - before;
            TotalMem += diff;
            Debug.WriteLine("clsNoteMapMidi new diff = " + diff + " total diff = " + TotalMem + " bytes");
#endif
            InitFilter(0, Filter.GetLength(0) - 1);
            EleW = new clsW(this);
            CreateOnOffPairs();
        }
Exemple #18
0
        internal void Populateclb(clsFileStream fsmm)
        {
            CSVFileSummary = fsmm;
            //int lasttrk = 1;
            clbTrk.Items.Clear();
            string fmt = "{0,2} {1,2} {2,5} {3,3} {4,3} {5,3} {6,3} {7,3} {8,-10} {9,6} {10,-24} {11,-40}";

            //txtTitle.Text = string.Format(fmt, "Tk", "Ch", "Count", "Min", "Max", "Min", "Max", "Rng", "Style", "Poly", "Patch", "Title");
            foreach (clsTrks.T trk in P.F.Chan.Next)
            {
                int      chan     = P.F.Chan[trk];
                string   chantxt  = "";
                string[] patchtxt = new string[] { "" };
                if (chan >= 0)
                {
                    chantxt = (chan + 1).ToString();
                    if (chan == 9) // percussion
                    {
                        patchtxt = new string[] { "*** channel 10 ***" };
                    }
                    else
                    {
                        clsFileStream fs = null;
                        if (P.F.FSTrackMap != null)
                        {
                            fs = P.F.FSTrackMap;
                        }
                        if (fs != null)
                        {
                            patchtxt = fs.MidiCtlrs.GetPatchList(chan);
                        }
                    }
                }

                int diff = fsmm.TrkMaxPitch[trk] - fsmm.TrkMinPitch[trk];
                if (diff < 0)
                {
                    diff = 0;
                }
                string poly  = (fsmm.Poly[trk] < 0) ? "" : string.Format("{0:N2}", fsmm.Poly[trk]);
                string chord = (fsmm.ChordNeg[trk] < 0) ? "" : string.Format("{0:N2}", fsmm.ChordNeg[trk]);
                string txt   = string.Format(fmt,
                                             trk.ToString(),
                                             chantxt,
                                             fsmm.OnCount[trk],
                                             (fsmm.OnCount[trk] == 0) ? "*" : NoteName.GetPitchStr(fsmm.TrkMinPitch[trk]),
                                             (fsmm.OnCount[trk] == 0) ? "*" : NoteName.GetPitchStr(fsmm.TrkMaxPitch[trk]),
                                             (fsmm.OnCount[trk] == 0) ? "*" : NoteName.GetPitchStrMidi(fsmm.TrkMinPitch[trk]),
                                             (fsmm.OnCount[trk] == 0) ? "*" : NoteName.GetPitchStrMidi(fsmm.TrkMaxPitch[trk]),
                                             diff,
                                             fsmm.TrkType[trk].ToString(),
                                             poly,
                                             patchtxt[0],
                                             fsmm.Title[trk].Trim(new char[] { '"' }));

                clbTrk.Items.Add(txt);
                for (int i = 1; i < patchtxt.Length; i++) //start at 2nd element
                {
                    clbTrk.Items.Add(string.Format(fmt, "", "", "", "", "", "", "", "", "", "", patchtxt[i], ""));
                }
            }
        }
Exemple #19
0
        internal void ShowList()
        {
            if (Type == eList.Msgs)
            {
                txtList.Lines = Msgs;
                return;
            }

            string[]      lines = null;
            clsFileStream fs    = null;

            if (P.F.FSTrackMap != null)
            {
                fs = P.F.FSTrackMap;
            }
            else if (P.F.FileStreamConv != null)
            {
                fs = P.F.FileStreamConv;
            }

            //* get first selected track, or null
            if (Type == eList.Strm)
            {
                clsTrks.T trk = null;
                clsFileStream.clsEvStrm[] strm = P.F.FSTrackMap.Strm;
                if (strm == null)
                {
                    return;
                }
                clsTrks.Array <bool> trkselect = P.F.frmTrackMap?.GetSelectedTrks();
                if (trkselect != null)
                {
                    foreach (clsTrks.T t in trkselect.Next)
                    {
                        if (trkselect[t])
                        {
                            trk = t;
                            break;
                        }
                    }
                }
                Text  = "Show Strm for ";
                Text += (trk == null) ? "all tracks" : "track " + trk.ToString();

                //* display headings
                List <string> list = new List <string>(110);
                string        fmt  = "{0,6} {1,3} {2,6} {3,6} {4}";
                list.Add((string.Format(fmt, "Seq", "Trk", "Ticks", "DITime", "Data")));

                //* show data from CurrentBBT
                int strmpos = clsFileStream.clsPlay.Find(P.F.FSTrackMap, strm, P.F.CurrentBBT.Ticks);
                int cnt     = 0;
                for (int i = strmpos; i < strm.Length; i++)
                {
                    clsFileStream.clsEvStrm s = strm[i];
                    if (trk != null && s.Trk != null && trk != s.Trk)
                    {
                        continue;
                    }
                    string t = (s.Trk == null) ? "*" : s.Trk.ToString();
                    list.Add(String.Format(fmt, i, t, s.Ticks, s.QTime, s.ToString()));
                    if (++cnt > 100)
                    {
                        break;
                    }
                }
                lines = list.ToArray();
            }
            else if (Type == eList.Attributes)
            {
                if (P.F.MTime == null)
                {
                    return;
                }
                Text = "Show Project and System Attributes";
                List <string> lineslist = new List <string>();
                //lineslist.Add("Version = " + P.Version);
                lineslist.Add("64-bit Operating System = " + Environment.Is64BitOperatingSystem);
                lineslist.Add("64-bit Process = " + Environment.Is64BitProcess);
                lineslist.Add("Debug Mode = " + Debugger.IsAttached);
                //#if APPDATAPATH
                //  lineslist.Add("AppDataPath = true");
                //#else
                //  lineslist.Add("AppDataPath = false");
                //#endif
        #if ADVANCED
                lineslist.Add("Advanced = true");
        #else
                lineslist.Add("Advanced = false");
        #endif
                lineslist.Add("TicksPerQuarterNote = " + P.F.MTime.TicksPerQNote);
                lineslist.Add("TicksPerQI = " + P.F.TicksPerQI);
                lineslist.Add("QIPerNote = " + P.F.QIPerNote);
                if (P.F.FSTrackMap?.Text00.Count > 0)
                {
                    lineslist.Add("");
                    lineslist.Add("Initial text events on MidiFile conductor track");
                    lineslist.Add("-----------------------------------------------");
                    foreach (string text in P.F.FSTrackMap?.Text00)
                    {
                        lineslist.Add(text);
                    }
                }
                lines = lineslist.ToArray();
            }
            else if (Type == eList.TSigs)
            {
                if (P.F.MTime?.TSigs == null)
                {
                    return;
                }
                Text = "Show Time Signatures";
                string fmt = "{0,3} {1,2}/{2,-2}";
                //* bar nn / dd
                lines = new string[P.F.MTime.TSigs.Length + 2];
                //lines[0] = "Source: Midi";
                lines[0] = string.Format(fmt, "Bar", "NN", "DD");
                for (int i = 0; i < P.F.MTime.TSigs.Length; i++)
                {
                    clsMTime.clsTSigBB tsig = P.F.MTime.TSigs[i];
                    lines[i + 1] = String.Format(fmt, tsig.Bar + 1, tsig.NN, tsig.DD);
                }
            }
            else if (Type == eList.Keys)
            {
                clsKeysTicks keys = P.F.Keys;
                if (keys == null)
                {
                    return;
                }
                Text = "Show Keys";
                string fmt = "{0,3} {1,4} {2,5} {3,-5}";
                //* bar beat pitch scale
                lines    = new string[keys.Keys.Count + 1];
                lines[0] = string.Format(fmt, "Bar", "Beat", "Pitch", "Scale");
                for (int i = 0; i < keys.Keys.Count; i++)
                {
                    clsKeyTicks key = keys.Keys[i];
                    lines[i + 1] = String.Format(fmt, key.BBT.Bar + 1, key.BBT.BeatsRemBar + 1, key.KeyNoteStr_ToSharpFlat, key.Scale);
                }
            }
            else if (Type == eList.Tempos)
            {
                if (fs == null || fs.TempoMap == null)
                {
                    return;
                }
                Text = "Show Tempos";
                string fmt = "{0,3} {1,4} {2,5} {3,9} {4,10}";
                //* bar beat tempo
                lines    = new string[Math.Max(2, fs.TempoMap.Count + 1)];
                lines[0] = string.Format(fmt, "Bar", "Beat", "Tempo", "MidiTempo", "MSecsPerQI");
                int miditempo, bpm, msecsperqi;
                if (fs.TempoMap.Count == 0)
                {
                    //miditempo = fs.TempoMap[0];  //default
                    miditempo  = fs.TempoMap.GetFirstValue(); //default
                    msecsperqi = (P.F.TicksPerQI * miditempo) / (P.F.MTime.TicksPerQNote * 1000);
                    //msecsperpi = (P.F.TicksPerPI * miditempo) / (P.F.MTime.TicksPerQNote * 1000);
                    int dd = P.F.MTime.GetTSig(0).DD;
                    bpm       = clsAudioSync.DivRound(dd * 60000000, 4 * miditempo);
                    lines[1]  = String.Format(fmt, 1, 1, bpm, miditempo, msecsperqi);
                    lines[1] += " (default)";
                }
                else
                {
                    //for (int i = 0; i < fs.TempoMap.Count; i++) {
                    //  int ticks = fs.TempoMap.KeyByIndex(i);
                    //  miditempo = fs.TempoMap.ValByIndex(i);
                    int linenum = 1;
                    foreach (KeyValuePair <int, int> pair in fs.TempoMap)
                    {
                        int ticks = pair.Key;
                        miditempo = pair.Value;
                        clsMTime.clsBBT bbt = new clsMTime.clsBBT(ticks);
                        msecsperqi = (P.F.TicksPerQI * miditempo) / (P.F.MTime.TicksPerQNote * 1000);
                        int dd = P.F.MTime.GetTSig(ticks).DD;
                        bpm = clsAudioSync.DivRound(dd * 60000000, 4 * miditempo);
                        //lines[i + 1] = String.Format(fmt, bbt.Bar + 1, bbt.BeatsRemBar + 1, bpm, miditempo, msecsperdi);
                        lines[linenum++] = String.Format(fmt, bbt.Bar + 1, bbt.BeatsRemBar + 1, bpm, miditempo, msecsperqi);
                    }
                }
            }
            else if (Type == eList.CtlrTots)
            {
                if (fs == null || fs.MidiCtlrs == null)
                {
                    return;                              //or P.F.MultiMap or P.F.MultiPlay???
                }
                Text = "Show Controller Totals";
                string fmt = "{0,4} {1,4} {2,4} {3,6} {4}";
                //string fmt = "{0,4} {1,4} {2,4} {3,4} {4,6} {5}";
                //* trk port chan ctlr total description
                List <string> l = new List <string>();
                l.Add(string.Format(fmt, " Trk", "Chan", "Ctlr", "Total", "Description"));
                for (int ctlr = 0; ctlr < fs.MidiCtlrs.DataLast.GetLength(0); ctlr++)
                {
                    for (int pc = 0; pc < 16; pc++)
                    {
                        if (fs.MidiCtlrs.DataLast[ctlr, pc] == null)
                        {
                            continue;
                        }
                        int    tot  = fs.MidiCtlrs.DataLast[ctlr, pc].Count;
                        string trk  = "*";
                        string desc = "???";
                        if (ctlr == clsMidiCtlrs.PatchCtlrNum)
                        {
                            desc = "Patch";
                        }
                        else
                        {
                            desc = MidiCtlrList.Desc[ctlr];
                        }
                        l.Add(String.Format(fmt, trk, (pc + 1), ctlr, tot, desc));
                    }
                }
                lines = l.ToArray();
            }
            else if (Type == eList.CtlrDetails)
            {
                if (fs == null || fs.MidiCtlrs == null)
                {
                    return;                              //or P.F.MultiMap or P.F.MultiPlay???
                }
                Text = "Show Controller Details";
                string fmt = "{0,4} {1,4} {2,4} {3,6} {4,9} {5,4} {6}";
                //string fmt = "{0,4} {1,4} {2,4} {3,4} {4,6} {5,9} {6,4} {7}";
                //* trk port chan ctlr ticks value description
                List <string> l = new List <string>();
                l.Add(string.Format(fmt, " Trk", "Chan", "Ctlr", "Ticks", "BBT", " Val", "Description"));
                for (int pc = 0; pc < 16; pc++)
                {
                    string trk = "*";
                    for (int ctlr = 0; ctlr < fs.MidiCtlrs.DataLast.GetLength(0); ctlr++)
                    {
                        string desc = "???";
                        //clsMidiCtlrs.clsMap<int> map = fs.MidiCtlrs.DataLast[ctlr, pc];
                        clsMap <int> map = fs.MidiCtlrs.DataLast[ctlr, pc];
                        if (map == null)
                        {
                            continue;
                        }
                        foreach (KeyValuePair <int, int> pair in map)
                        {
                            int             ticks = pair.Key;
                            clsMTime.clsBBT bbt   = new clsMTime.clsBBT(ticks);
                            int             val   = pair.Value;
                            if (ctlr == clsMidiCtlrs.PatchCtlrNum)
                            {
                                desc = "Patch: " + GeneralMidiList.Desc[val];
                            }
                            else
                            {
                                desc = MidiCtlrList.Desc[ctlr];
                            }
                            l.Add(String.Format(fmt, trk, (pc + 1), ctlr, ticks, bbt.ToString(), val, desc));
                        }
                    }
                }
                lines = l.ToArray();
            }
            else if (Type == eList.Debug)
            {
                Text = "Show Debug Info";
                List <string> l = new List <string>();
                l.Add("Current Ticks = " + P.F.CurrentBBT.Ticks);
                if (P.F != null)
                {
                    if (P.F.MTime != null)
                    {
                        l.Add("P.F.MTime.TicksPerQNote = " + P.F.MTime.TicksPerQNote);
                    }
                    l.Add("P.F.TicksPerDI = " + P.F.TicksPerQI);
                    //l.Add("P.F.TicksPerPI = " + P.F.TicksPerPI);
                    l.Add("P.F.MaxTicks = " + P.F.MaxBBT.Ticks);
                    l.Add("P.F.MaxDITime = " + P.F.MaxBBT.QI);
                    //l.Add("P.F.MaxPITime = " + P.F.MaxPITime);
                }
                lines = l.ToArray();
            }
            else if (Type == eList.ChordList) //standard chords
            {
                Text = "Show Chords";
                string fmt = "{0,-8} {1,-8} {2,-8} {3,-4} {4,-24}";
                lines    = new string[ChordAnalysis.USToTemplate.Values.Count + 1];
                lines[0] = string.Format(fmt, "Name", "Name", "Name", "Rank", "Notes");
                for (int i = 0; i < ChordAnalysis.FileSeqToTemplate.Values.Count; i++)
                {
                    ChordAnalysis.clsTemplate t = ChordAnalysis.FileSeqToTemplate.Values[i];
                    string notes = ""; //root note
                    for (int j = 0; j < 12; j++)
                    {
                        if (t.PC[j])
                        {
                            notes += NoteName.ToSharpFlat(NoteName.GetNoteName(0, 0, j)) + ' ';
                        }
                    }
                    List <string> names = ChordAnalysis.GetSynonyms(t);
                    string        name0 = names[0];
                    string        name1 = (names.Count > 1) ? names[1] : "";
                    string        name2 = (names.Count > 2) ? names[2] : "";
                    lines[i + 1] = String.Format(fmt, name0, name1, name2, t.Rank, notes);
                }
            }
            else
            {
                LogicError.Throw(eLogicError.X048);
                lines = new string[] { "Invalid Show Type" };
            }
            txtList.Lines = lines;
            txtList.Select(0, 0);
        } //method
Exemple #20
0
        //private Forms.frmCfgChords FrmCfgChords;

        //private bool indChordRoot {
        //  get { return P.frmSaveMidiFileAs?.chkChordRoot.Checked ?? false; }
        //}

        //private int intChordChan {
        //  get { return (int)(P.frmSaveMidiFileAs?.nudChordChan.Value ?? 16) - 1; }
        //}

        //private bool indSaveChordLabels {
        //  get { return P.frmSaveMidiFileAs?.chkSaveChordLabels.Checked ?? false; }
        //}

        //private bool indSaveMutedTracks {
        //  get { return P.frmSaveMidiFileAs?.chkSaveMutedTrks.Checked ?? true; }
        //}

        //private string txtChordTrackTitle {
        //  get { return P.frmSaveMidiFileAs?.txtChordTrackTitle.Text ?? "Chords"; }
        //}

        internal clsSaveMidiFile(clsFileStream fs)
        {
            FS = fs;
            //FrmCfgChords = frmcfgchords;
        }
Exemple #21
0
        private string Calculate(clsFileStream fs, int?inertia)
        {
            KeysList   = new List <clsKeysAlg>();
            KeysLabels = new List <string>();
            clsKeysAlg.eAlg alg = clsKeysAlg.eAlg.Weighted;
            if (optAlgFlat.Checked)
            {
                alg = clsKeysAlg.eAlg.Flat;
            }
            //clsFileStream csvfileconv;
            clsNoteMap notemap;

            if (chkChordFile.Checked)
            {
                if (P.F.CF?.Evs == null || P.F.CF.Evs.Count == 0)
                {
                    return("Empty ChordFile");
                }
                notemap = P.F.CF.NoteMap;
            }
            else
            {
                if (fs != null)
                {
                    notemap = fs.NoteMap;
                }
                else
                {
                    try {
                        notemap = (new clsFileStream(FileName, TrkSelect, true, false, true)).NoteMap;
                    }
                    catch (MidiFileException exc) {
                        return("MidiFileException: " + exc.Message);
                    }
                }
            }

            clsKeysAlg.eProfile profile = clsKeysAlg.eProfile.Default;
            if (optProfileJazz.Checked)
            {
                profile = clsKeysAlg.eProfile.Jazz;
            }
            else if (optProfileSpecial.Checked)
            {
                profile = clsKeysAlg.eProfile.Special;
            }
            Segments = new clsKeysAlg.clsSegments(notemap);
            if (Segments.indEmpty)
            {
                return("Empty Tracks");
            }
            CF = (chkLoadTxt.Checked && P.F.CF != null) ? CF = P.F.CF : null;
            KeysLabels.Add("Txt"); //leave in, even if text not present
            clsKeysAlg.Alg = alg;
            //clsKeysAlg.Trace = indTrace;
            clsKeysAlg.Segments = Segments;

            if (inertia.HasValue)
            {
                AddToKeysList(alg, profile, inertia.Value);
            }
            else
            {
                AddToKeysList(alg, profile, 0);
                AddToKeysList(alg, profile, 30);
                AddToKeysList(alg, profile, 50);
                AddToKeysList(alg, profile, 70);
                AddToKeysList(alg, profile, 90);
                AddToKeysList(alg, profile, 110);
            }

            CalcMinorScores();

            PopulatelvMod(true);
            //cmdDebugSegs.Enabled = true;
            return("");
        }