Exemplo n.º 1
0
 public LogicException(string message, LogicError error, Exception inner)
     : base(message, inner)
 {
     this.Errors = new LogicErrors {
         error
     };
 }
Exemplo n.º 2
0
 private int GetInertia()
 {
     if (optPenalty0.Checked)
     {
         return(0);
     }
     if (optPenalty30.Checked)
     {
         return(1);
     }
     if (optPenalty50.Checked)
     {
         return(2);
     }
     if (optPenalty70.Checked)
     {
         return(3);
     }
     if (optPenalty90.Checked)
     {
         return(4);
     }
     if (optPenalty110.Checked)
     {
         return(5);
     }
     LogicError.Throw(eLogicError.X083);
     return(0);
 }
Exemplo n.º 3
0
        private void GetDescs()
        {
            CHPDescs = new string[CHPPaths.Length];
            CHPExts  = new string[CHPPaths.Length];
            for (int k = 0; k < CHPPaths.Length; k++)
            {
                CHPExts[k] = Path.GetExtension(CHPPaths[k]);
            }
            int index = 0;

            try {
                for (; index < CHPPaths.Length; index++)
                {
                    if (File.Exists(CHPPaths[index]))
                    {
                        using (StreamReader str = new StreamReader(CHPPaths[index])) {
                            string line;
                            while ((line = str.ReadLine()) != null)
                            {
                                if (!line.StartsWith("*"))
                                {
                                    break;         //old starting comments
                                }
                            }
                            string[] f = line.Split(new char[] { ' ' }, 5, StringSplitOptions.RemoveEmptyEntries);
                            CHPDescs[index] = CHPExts[index];
                            if (f.Length == 5)
                            {
                                SetDesc(index, f[4]);
                            }
                            else
                            {
                                SetDesc(index, "*** No Description ***");
                            }
                        }
                    }
                    else //file not present
                    {
                        if (indLoad)
                        {
                            LogicError.Throw(eLogicError.X139); //leave blank and continue
                        }
                        SetDesc(index, "*** File not present ***");
                    }
                }
            }
            catch (Exception exc) {
                string msg = "Error reading ChordFile " + CHPPaths[index] + ": " + exc.Message;
                MessageBox.Show(msg);
                return;
            }
        }
Exemplo n.º 4
0
 internal void SetoptAlignTrim()
 {
     if (optAlignTrimBar.Checked)
     {
         P.F.frmChordMap.AlignTrim = eAlign.Bar;
     }
     else if (optAlignTrimHalfBar.Checked)
     {
         P.F.frmChordMap.AlignTrim = eAlign.HalfBar;
     }
     else if (optAlignTrimBeat.Checked)
     {
         P.F.frmChordMap.AlignTrim = eAlign.Beat;
     }
     else
     {
         LogicError.Throw(eLogicError.X042);
         P.F.frmChordMap.AlignTrim = eAlign.Beat;
     }
 }
Exemplo n.º 5
0
 private void optAlign_CheckedChanged(object sender, EventArgs e)
 {
     if (sender is RadioButton)
     {
         RadioButton opt = (RadioButton)sender;
         if (!opt.Checked)
         {
             return;
         }
     }
     if (optAlignQuantize.Checked)
     {
         P.F.frmChordMap.Align         = eAlign.Interval;
         P.F.frmChordMap.QuantizeTicks = P.F.MTime.DD2Ticks((int)nudQuantizeNN.Value, (int)nudQuantizeDD.Value);
         //nudChordWidth.Value = Math.Max(1, QuantizeTicks / CSVFileConv.TicksPerQI);
     }
     else if (optAlignBar.Checked)
     {
         P.F.frmChordMap.Align = eAlign.Bar;
     }
     else if (optAlignHalfBar.Checked)
     {
         P.F.frmChordMap.Align = eAlign.HalfBar;
     }
     else if (optAlignBeat.Checked)
     {
         P.F.frmChordMap.Align = eAlign.Beat;
     }
     else
     {
         LogicError.Throw(eLogicError.X042);
         P.F.frmChordMap.Align = eAlign.Beat;
     }
     //*for (int i = 0; i < 100; i++) {  //1 second
     //ApplyFilter();
     //*}
     //Refresh();
 }
Exemplo n.º 6
0
 private static void CreateKeyToActions()
 {
     //* (re)create KeyToActions from ActionsToKey
     for (int i = 0; i < KeyToActions.Length; i++)
     {
         KeyToActions[i] = new List <string>(2);
     }
     foreach (KeyValuePair <string, string> pair in ActionToKey)
     {
         if (pair.Value.Length == 0)
         {
             continue;
         }
         //int key = (pair.Value == "Pedal") ? 12 : Array.IndexOf(NoteName.MajKeyNames, pair.Value);
         int key = Array.IndexOf(CmbItems, pair.Value);
         if (key < 0) //string not found
         {
             LogicError.Throw(eLogicError.X072);
             key = 12; //pedal
         }
         KeyToActions[key].Add(pair.Key);
     }
     //SetFrmSCChkBoxes();
 }
Exemplo n.º 7
0
 public static T AddError <T>(this T result, LogicError logicError) where T : ILogicResult
 {
     result.Errors.Add(logicError);
     return(result);
 }
Exemplo n.º 8
0
 public LogicException(LogicError error, Exception inner)
     : this(string.Empty, error, inner)
 {
 }
Exemplo n.º 9
0
        public static void Write(LogPlamInfo pi, String className, String methodName, LogicError ex)
        {
            String message = String.Format("<[{0}][{1}]>", ex.Message, ex.StackTrace);

            Write(pi, LogMessageType.LogicError, className, methodName, message);
        }
Exemplo n.º 10
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
Exemplo n.º 11
0
        private void PopulatelvMod(bool headers)
        {
            //* create table of key strings
            string[,] txt  = new string[KeysList[0].Keys.Count, KeysList.Count + 1];
            string[,] txtx = new string[KeysList[0].Keys.Count, KeysList.Count + 1];
            for (int seg = 0; seg < KeysList[0].Keys.Count; seg++)
            {
                if (CF != null)
                {
                    txt[seg, 0]  = GetFileKey(seg).KeyStrShort;
                    txtx[seg, 0] = GetFileKey(seg).KeyStrShort;
                }
                for (int i = 0; i < KeysList.Count; i++) //for each algorithm type
                {
                    clsKeyTicks key = KeysList[i].Keys[seg];
                    if (key != null)
                    {
                        if (seg != key.BBT.Bar)
                        {
                            LogicError.Throw(eLogicError.X034);
                        }
                        txt[seg, i + 1]  = key.KeyStrShort;
                        txtx[seg, i + 1] = key.KeyStrShort;
                    }
                }
            }

            //* replace repeated keys with "*"
            for (int i = 0; i < KeysList.Count + 1; i++) //txtfile and each algorithm type
            //for (int seg = 1; seg < KeysList[0].Keys.Count - 1; seg++) {
            //  if (txtx[seg, i] == txtx[seg - 1, i] && txtx[seg, i] == txtx[seg + 1, i]) {
            //    txt[seg, i] = "*";
            //  }
            //}
            {
                for (int seg = 1; seg < KeysList[0].Keys.Count; seg++)
                {
                    if (txtx[seg, i] == txtx[seg - 1, i])
                    {
                        txt[seg, i] = "*";
                    }
                }
            }

            //* load lvmod
            lvMod.BeginUpdate();
            lvMod.Clear();
            if (headers)
            {
                lvMod.Columns.Add("Bar", 30);
                foreach (string lbl in KeysLabels)
                {
                    lvMod.Columns.Add(lbl, 40);
                }
            }
            for (int seg = 0; seg < KeysList[0].Keys.Count; seg++)
            {
                List <string> lvstr = new List <string>();
                lvstr.Add((seg + 1).ToString());         //bar num
                lvstr.Add(txt[seg, 0]);                  //txt file
                for (int i = 0; i < KeysList.Count; i++) //for each algorithm type
                {
                    lvstr.Add(txt[seg, i + 1]);
                }
                lvMod.Items.Add(new ListViewItem(lvstr.ToArray())); //add segment
            }
            lvMod.EndUpdate();
        }
Exemplo n.º 12
0
        private void CalcMinorScores()
        {
            //* calculate minor key scores for different minor key types
            //* use currently selected inertia(penalty), alg, profile

            //* calculate totals of each pitchclass for segements(bars) in a minor key
            int[] pctots = new int[12]; //pitchclass totals
            for (int i = 0; i < 12; i++)
            {
                pctots[i] = 0;
            }
            int index = (KeysList.Count > 1) ? GetInertia() : 0;

            if (KeysList.Count == 0)
            {
                LogicError.Throw(eStopError.Y003); //unable to reproduce this, but it did happen!
                return;
            }
            clsKeysAlg keysalg = KeysList[index];

            clsKeysAlg.clsSegments segs = clsKeysAlg.Segments;
            for (int segnum = 0; segnum < keysalg.Keys.Count; segnum++)
            {
                clsKeyTicks key = keysalg.Keys[segnum];
                if (key != null && key.Scale == "minor")
                {
                    if (segnum != key.BBT.Bar)
                    {
                        LogicError.Throw(eLogicError.X094);
                        break;
                    }
                    for (int pc = 0; pc < 12; pc++)
                    {
                        pctots[pc] += segs.Segs[segnum][pc];
                    }
                }
            }

            //* calculate totals of l/l- t/t- combinations
            int totharmonic = pctots[8] + pctots[11]; //l- t
            int totmelup    = pctots[9] + pctots[11]; //l t
            int totmeldown  = pctots[8] + pctots[10]; //l- t-
            int totspecial  = pctots[9] + pctots[10]; //l t-

            lblTotHarmonic.Text = totharmonic.ToString();
            lblTotMelUp.Text    = totmelup.ToString();
            lblTotMelDown.Text  = totmeldown.ToString();
            lblTotSpecial.Text  = totspecial.ToString();

            eMinorKeyType maxtottype = eMinorKeyType.Harmonic;
            int           maxtot     = totharmonic;

            if (totmelup > maxtot)
            {
                maxtottype = eMinorKeyType.MelodicUp;
                maxtot     = totmelup;
            }

            if (totmeldown > maxtot)
            {
                maxtottype = eMinorKeyType.MelodicDown;
                maxtot     = totmeldown;
            }

            if (totspecial > maxtot)
            {
                maxtottype = eMinorKeyType.Special;
                maxtot     = totspecial;
            }

            FontStyle fontstyle;

            fontstyle           = (maxtottype == eMinorKeyType.Harmonic) ? FontStyle.Bold : FontStyle.Regular;
            lblTotHarmonic.Font = new Font(lblTotHarmonic.Font, fontstyle);

            fontstyle        = (maxtottype == eMinorKeyType.MelodicUp) ? FontStyle.Bold : FontStyle.Regular;
            lblTotMelUp.Font = new Font(lblTotMelUp.Font, fontstyle);

            fontstyle          = (maxtottype == eMinorKeyType.MelodicDown) ? FontStyle.Bold : FontStyle.Regular;
            lblTotMelDown.Font = new Font(lblTotMelDown.Font, fontstyle);

            fontstyle          = (maxtottype == eMinorKeyType.Special) ? FontStyle.Bold : FontStyle.Regular;
            lblTotSpecial.Font = new Font(lblTotSpecial.Font, fontstyle);

            if (chkUseHighestMinorKeyType.Checked)
            {
                P.frmStart.MinorKeyType = maxtottype;
            }
        }