コード例 #1
0
ファイル: DrawerSettings.cs プロジェクト: bntre/cs-rationals
 // Serialization
 public static void Save(DrawerSettings s, XmlWriter w)
 {
     //
     w.WriteElementString("limitPrime", s.subgroup != null ? "" : Rationals.Utils.GetPrime(s.limitPrimeIndex).ToString());
     w.WriteElementString("subgroup", Rational.FormatRationals(s.subgroup, "."));
     w.WriteElementString("narrows", Rational.FormatRationals(s.narrows, "."));
     //
     w.WriteElementString("harmonicityName", s.harmonicityName);
     w.WriteElementString("rationalCountLimit", s.rationalCountLimit.ToString());
     //
     w.WriteElementString("slopeOrigin", s.slopeOrigin.FormatFraction());
     w.WriteElementString("slopeChainTurns", s.slopeChainTurns.ToString());
     //
     //w.WriteElementString("degreeCount", s.degreeCount.ToString());
     w.WriteElementString("degreeThreshold", s.degreeThreshold.ToString());
     //
     w.WriteElementString("selection", FormatIntervals(s.selection));
     if (s.temperament != null)
     {
         foreach (Tempered t in s.temperament)
         {
             w.WriteStartElement("temper");
             w.WriteAttributeString("rational", t.rational.FormatFraction());
             w.WriteAttributeString("cents", t.cents.ToString());
             w.WriteEndElement();
         }
     }
     w.WriteElementString("temperamentMeasure", s.temperamentMeasure.ToString());
     w.WriteElementString("edGrids", GridDrawer.EDGrid.Format(s.edGrids));
     w.WriteElementString("pointRadius", s.pointRadiusLinear.ToString());
 }
コード例 #2
0
        static void Test_Narrows()
        {
            Debug.WriteLine("Test_Narrows");

            Rational[] rs = Rational.ParseRationals(
                "2.3.5"
                );

            Debug.WriteLine("Subgroup: " + Rational.FormatRationals(rs, "."));

            Subgroup subgroup = new Subgroup(rs);

            Debug.WriteLine("Narrows: " + Rational.FormatRationals(subgroup.GetNarrows()));
        }
コード例 #3
0
        private void UpdateSubgroupTip(string customError = null)
        {
            string tip   = null;
            string error = null;

            if (_gridDrawer.Subgroup != null)
            {
                tip = String.Format("Base: {0}\nNarrows: {1}",
                                    _gridDrawer.Subgroup.GetBaseItem(),
                                    Rational.FormatRationals(_gridDrawer.Subgroup.GetNarrows())
                                    );
                error = _gridDrawer.Subgroup.GetError();
            }
            SetControlTip(textBoxSubgroup, tip, customError ?? error);
        }
コード例 #4
0
ファイル: DrawerSettings.cs プロジェクト: bntre/cs-rationals
        public static string FormatSubgroup(Rational[] subgroup, Rational[] narrows)
        {
            string result = "";

            if (subgroup != null)
            {
                result += Rational.FormatRationals(subgroup, ".");
            }
            if (narrows != null)
            {
                if (result != "")
                {
                    result += " ";
                }
                result += "(" + Rational.FormatRationals(narrows, ".") + ")";
            }
            return(result);
        }
コード例 #5
0
        static void Test_PartialProvider_Piano()
        {
            var format = new WaveFormat {
                bytesPerSample = 2,
                sampleRate     = 44100,
                //sampleRate = 22050,
                channels = 1,
            };

            string harmonicity = "Barlow";

            Rational[] subgroup = Rational.ParseRationals("2.3.5.11");
            Partial[]  partials = MakePartials(harmonicity, subgroup, 15);

            Debug.WriteLine("Subgroup {0}", Rational.FormatRationals(subgroup));
            foreach (Partial p in partials)
            {
                Debug.WriteLine("Partial {0} harm: {1}", p.rational, p.harmonicity);
            }


            using (var engine = new WaveEngine(format, bufferLengthMs: 30, restartOnFailure: true))
            {
                var partialProvider = new PartialProvider();

                engine.SetSampleProvider(partialProvider);
                engine.Play();

                Console.WriteLine("1-9 to play note\nEsc to exit");

                while (true)
                {
                    bool playing = true;
                    while (true)
                    {
                        playing = engine.IsPlaying();
                        if (!playing)
                        {
                            break;
                        }
                        if (Console.KeyAvailable)
                        {
                            break;
                        }
                        Thread.Sleep(1); // sleep here
                    }
                    if (!playing)
                    {
                        break;
                    }
                    var k = Console.ReadKey(true);
                    if (k.Key == ConsoleKey.Escape)
                    {
                        break; // engine stopped on dispose
                    }
                    else if (ConsoleKey.D1 <= k.Key && k.Key <= ConsoleKey.D9)
                    {
                        int n = (int)k.Key - (int)ConsoleKey.D1 + 1; // 1..9
                        var r = new Rational(1 + n, 2);              // 2/2, 3/2, 4/2, 5/2,..
                        if (k.Modifiers.HasFlag(ConsoleModifiers.Shift))
                        {
                            r *= 4;
                        }
                        if (k.Modifiers.HasFlag(ConsoleModifiers.Control))
                        {
                            r /= 4;
                        }
                        //AddNote(partialProvider, r);
                        AddNote(partialProvider, r.ToCents(), partials);
                    }
                }

                Debug.WriteLine("Ending. Provider status: {0}", (object)partialProvider.FormatStatus());
            }
        }