Beispiel #1
0
        public void TestMinMaxValues()
        {
            var options = new Dictionary <TokenType, List <Token> >
            {
                [TokenType.DecimalValues] = new List <Token>
                {
                    new Token(TokenType.Decimal, "-1.10", 0),
                    new Token(TokenType.Decimal, ".5", 0),
                    new Token(TokenType.Decimal, "1.5", 0)
                },
                [TokenType.IntValues] = new List <Token>
                {
                    new Token(TokenType.Number, "-10", 0),
                    new Token(TokenType.Number, "50", 0),
                    new Token(TokenType.Number, "101", 0)
                }
            };

            var(success, _) = OptionParser.TryParseOptions(new Command {
                Options = options
            }, out OptionsClassThree parsedOptions);
            Assert.IsTrue(success);
            Assert.AreEqual(0m, parsedOptions.DecimalValues[0]);
            Assert.AreEqual(.5m, parsedOptions.DecimalValues[1]);
            Assert.AreEqual(1m, parsedOptions.DecimalValues[2]);
            Assert.AreEqual(1, parsedOptions.IntValues[0]);
            Assert.AreEqual(50, parsedOptions.IntValues[1]);
            Assert.AreEqual(100, parsedOptions.IntValues[2]);
        }
Beispiel #2
0
        public static ProcessResultArray <Clip> Apply(Command command, params Clip[] clips)
        {
            (var success, var msg) = OptionParser.TryParseOptions(command, out ScanOptions options);
            if (!success)
            {
                return(new ProcessResultArray <Clip>(msg));
            }
            var processedClips = new Clip[clips.Length];

            for (var c = 0; c < clips.Length; c++)
            {
                var     clip          = clips[c];
                var     processedClip = new Clip(options.Window * options.Count, clip.IsLooping);
                decimal delta         = clip.Length / options.Count,
                        curPos        = 0;

                for (int i = 0; i < options.Count; i++)
                {
                    processedClip.Notes.AddRange(ClipUtilities.GetSplitNotesInRangeAtPosition(curPos, curPos + options.Window, clip.Notes, options.Window * i));
                    curPos += delta;
                }
                processedClips[c] = processedClip;
            }

            return(new ProcessResultArray <Clip>(processedClips));
        }
Beispiel #3
0
 public static ProcessResultArray <Clip> Apply(Command command, params Clip[] clips)
 {
     var(success, msg) = OptionParser.TryParseOptions(command, out FilterOptions options);
     if (!success)
     {
         return(new ProcessResultArray <Clip>(msg));
     }
     return(Apply(options, clips));
 }
Beispiel #4
0
 public static ProcessResultArray <Clip> Apply(Command command, ClipMetaData metadata, params Clip[] clips)
 {
     var(success, msg) = OptionParser.TryParseOptions(command, out InterleaveOptions options);
     if (!success)
     {
         return(new ProcessResultArray <Clip>(msg));
     }
     return(Apply(options, metadata, clips));
 }
Beispiel #5
0
 public static ProcessResult <Clip[]> Apply(Command command, params Clip[] clips)
 {
     (var success, var msg) = OptionParser.TryParseOptions(command, out RelengthOptions options);
     if (!success)
     {
         return(new ProcessResult <Clip[]>(msg));
     }
     return(Apply(options, clips));
 }
Beispiel #6
0
        public static ProcessResultArray <Clip> Apply(Command command, params Clip[] clips)
        {
            (var success, var msg) = OptionParser.TryParseOptions(command, out VelocityScaleOptions options);

            if (!success)
            {
                return(new ProcessResultArray <Clip>(msg));
            }
            return(Apply(options, clips));
        }
Beispiel #7
0
        public void TestEnumValues()
        {
            var options = new Dictionary <TokenType, List <Token> >();

            options[TokenType.EnumValue] = new List <Token>()
            {
                new Token(TokenType.EnumValue, "enumvalue2", 0)
            };
            var(success, msg) = OptionParser.TryParseOptions(new Command {
                Options = options
            }, out OptionsClassTwo parsedOptions);
            Assert.AreEqual(TestEnum.EnumValue2, parsedOptions.EnumValue);
        }
Beispiel #8
0
 public static ProcessResultArray <Clip> Apply(Command command, ClipMetaData metadata, Clip[] clips, InterleaveMode mode)
 {
     var(success, msg) = OptionParser.TryParseOptions(command, out InterleaveOptions options);
     if (!success)
     {
         return(new ProcessResultArray <Clip>(msg));
     }
     if (mode != NotSpecified)
     {
         options.Mode = mode;
     }
     return(Apply(options, metadata, clips));
 }
Beispiel #9
0
        public void TestCastNumberToMusicalDivision()
        {
            var command = Parser.ParseFormulaToChainedCommand("[0] interleave -mode time -ranges 1/8 2 1 4", new List <Clip> {
                Clip1
            }, new ClipMetaData(100, 0));

            Assert.IsTrue(command.Success);
            var(success, _) = OptionParser.TryParseOptions(command.Result.Commands.First(), out InterleaveOptions options);
            Assert.IsTrue(success);
            Assert.AreEqual(0.5m, options.Ranges[0]);
            Assert.AreEqual(8, options.Ranges[1]);
            Assert.AreEqual(4, options.Ranges[2]);
            Assert.AreEqual(16, options.Ranges[3]);
        }
Beispiel #10
0
 public static ProcessResult <Clip[]> Apply(Command command, Clip[] clips, bool doExtract = false)
 {
     var(success, msg) = OptionParser.TryParseOptions(command, out TakeOptions options);
     if (!success)
     {
         return(new ProcessResult <Clip[]>(msg));
     }
     if (doExtract)
     {
         options.Thin       = true;
         options.TakeCounts = new[] { 1 };
     }
     return(Apply(options, clips));
 }
Beispiel #11
0
        public static ProcessResultArray <Clip> ProcessCommand(Command command, Clip[] incomingClips, ClipMetaData targetMetadata)
        {
            var clips = new Clip[incomingClips.Length];

            for (var i = 0; i < incomingClips.Length; i++)
            {
                clips[i] = new Clip(incomingClips[i]);
            }

            return(command.Id switch
            {
                TokenType.Arpeggiate => Arpeggiate.Apply(command, clips),
                TokenType.Concat => Concat.Apply(clips),
                TokenType.Crop => Crop.Apply(command, clips),
                TokenType.Filter => Filter.Apply(command, clips),
                TokenType.Interleave => Interleave.Apply(command, targetMetadata, clips),
                TokenType.Legato => Legato.Apply(clips),
                TokenType.Mask => Mask.Apply(command, clips),
                TokenType.Monophonize => Monophonize.Apply(clips),
                TokenType.Padding => Padding.Apply(command, clips),
                TokenType.Quantize => Quantize.Apply(command, clips),
                TokenType.Ratchet => Ratchet.Apply(command, clips),
                TokenType.Relength => Relength.Apply(command, clips),
                TokenType.Remap => Remap.Apply(command, clips),
                TokenType.Resize => Resize.Apply(command, clips),
                TokenType.Scale => Scale.Apply(command, clips),
                TokenType.Scan => Scan.Apply(command, clips),
                TokenType.SetLength => SetLength.Apply(command, clips),
                TokenType.SetPitch => SetPitch.Apply(command, clips),
                TokenType.SetRhythm => SetRhythm.Apply(command, clips),
                TokenType.Shuffle => Shuffle.Apply(command, clips),
                TokenType.Skip => Skip.Apply(command, clips),
                TokenType.Slice => Slice.Apply(command, clips),
                TokenType.Take => Take.Apply(command, clips),
                TokenType.Transpose => Transpose.Apply(command, clips),
                TokenType.VelocityScale => VelocityScale.Apply(command, clips),
                TokenType.InterleaveEvent => ((Func <ProcessResultArray <Clip> >)(() =>
                {
                    var(success, msg) = OptionParser.TryParseOptions(command, out InterleaveOptions options);
                    if (!success)
                    {
                        return new ProcessResultArray <Clip>(msg);
                    }

                    options.Mode = InterleaveMode.Event;
                    return Interleave.Apply(options, targetMetadata, clips);
                }))(),
                _ => new ProcessResultArray <Clip>($"Unsupported command {command.Id}")
            });
Beispiel #12
0
        public void TestConvertBarsBeatsSixteenths()
        {
            var command = Parser.ParseFormulaToChainedCommand("[0] interleave -mode time -ranges 0.0.2 0.2.0 0.1.0 1.0.0 1.0.1", new List <Clip> {
                Clip1
            }, new ClipMetaData(100, 0));

            Assert.IsTrue(command.Success);
            var(success, _) = OptionParser.TryParseOptions(command.Result.Commands.First(), out InterleaveOptions options);
            Assert.IsTrue(success);
            Assert.AreEqual(0.5m, options.Ranges[0]);
            Assert.AreEqual(2, options.Ranges[1]);
            Assert.AreEqual(1, options.Ranges[2]);
            Assert.AreEqual(4, options.Ranges[3]);
            Assert.AreEqual(4.25m, options.Ranges[4]);
        }
Beispiel #13
0
        public void TestCastNumberWhenNoImplicitCastSet()
        {
            var command = Parser.ParseFormulaToChainedCommand("[0] resize 1/8", new List <Clip> {
                Clip1
            }, new ClipMetaData(100, 0));

            Assert.IsTrue(command.Success);
            var(success, _) = OptionParser.TryParseOptions(command.Result.Commands.First(), out ResizeOptions _);
            Assert.IsFalse(success);
            command = Parser.ParseFormulaToChainedCommand("[0] resize 0.5", new List <Clip> {
                Clip1
            }, new ClipMetaData(100, 0));
            (success, _) = OptionParser.TryParseOptions(command.Result.Commands.First(), out ResizeOptions _);
            Assert.IsTrue(success);
        }
Beispiel #14
0
        public void TestListValues()
        {
            var options = new Dictionary <TokenType, List <Token> >();

            options[TokenType.DecimalValue] = new List <Token>()
            {
                new Token(TokenType.MusicalDivision, "1/8", 0), new Token(TokenType.MusicalDivision, "1/16", 0)
            };
            options[TokenType.IntValue] = new List <Token>()
            {
                new Token(TokenType.Number, "14", 0), new Token(TokenType.Number, "2", 0), new Token(TokenType.Number, "900", 0)
            };
            var(success, msg) = OptionParser.TryParseOptions(new Command {
                Options = options
            }, out OptionsClassTwo parsedOptions);
            Assert.AreEqual(2, parsedOptions.DecimalValue.Length);
            Assert.AreEqual(3, parsedOptions.IntValue.Length);
        }
Beispiel #15
0
        public void TestValues()
        {
            var options = new Dictionary <TokenType, List <Token> >();

            options[TokenType.DecimalValue] = new List <Token>()
            {
                new Token(TokenType.MusicalDivision, "1/8", 0)
            };
            options[TokenType.IntValue] = new List <Token>()
            {
                new Token(TokenType.Number, "14", 0)
            };
            options[TokenType.SimpleBoolFlag] = new List <Token>();
            var(success, msg) = OptionParser.TryParseOptions(new Command {
                Options = options
            }, out OptionsClassOne parsedOptions);
            Assert.AreEqual(14, parsedOptions.IntValue);
            Assert.AreEqual(.5m, parsedOptions.DecimalValue);
            Assert.IsTrue(parsedOptions.SimpleBoolFlag);
        }
Beispiel #16
0
        public void TestMinMaxValue()
        {
            var options = new Dictionary <TokenType, List <Token> >();

            options[TokenType.IntValue] = new List <Token>()
            {
                new Token(TokenType.Number, "1000", 0)
            };
            var(success, msg) = OptionParser.TryParseOptions(new Command {
                Options = options
            }, out OptionsClassOne parsedOptions);
            Assert.AreEqual(100, parsedOptions.IntValue);
            options[TokenType.IntValue] = new List <Token>()
            {
                new Token(TokenType.Number, "0", 0)
            };
            parsedOptions  = new OptionsClassOne();
            (success, msg) = OptionParser.TryParseOptions(new Command {
                Options = options
            }, out parsedOptions);
            Assert.AreEqual(1, parsedOptions.IntValue);
        }
Beispiel #17
0
 public static ProcessResult <Clip[]> Apply(Command command, params Clip[] clips)
 {
     var(success, msg) = OptionParser.TryParseOptions(command, out TransposeOptions options);
     return(!success ? new ProcessResult <Clip[]>(msg) : Apply(options, clips));
 }
Beispiel #18
0
 public static ProcessResultArray <Clip> Apply(Command command, params Clip[] clips)
 {
     var(success, msg) = OptionParser.TryParseOptions(command, out LoopOptions options);
     return(success ? Apply(options, clips) : new ProcessResultArray <Clip>(msg));
 }
Beispiel #19
0
        public static ProcessResultArray <Clip> ProcessCommand(Command command, Clip[] incomingClips, ClipMetaData targetMetadata)
        {
            var clips = new Clip[incomingClips.Length];

            for (var i = 0; i < incomingClips.Length; i++)
            {
                clips[i] = new Clip(incomingClips[i]);
            }

            ProcessResultArray <Clip> resultContainer;

            switch (command.Id)
            {
            case TokenType.Arpeggiate:
                resultContainer = Arpeggiate.Apply(command, clips);
                break;

            case TokenType.Concat:
                resultContainer = Concat.Apply(clips);
                break;

            case TokenType.Crop:
                resultContainer = Crop.Apply(command, clips);
                break;

            case TokenType.Filter:
                resultContainer = Filter.Apply(command, clips);
                break;

            case TokenType.Interleave:
                resultContainer = Interleave.Apply(command, targetMetadata, clips);
                break;

            case TokenType.InterleaveEvent:
                var(success, msg) = OptionParser.TryParseOptions(command, out InterleaveOptions options);
                if (!success)
                {
                    return(new ProcessResultArray <Clip>(msg));
                }
                options.Mode    = InterleaveMode.Event;
                resultContainer = Interleave.Apply(options, targetMetadata, clips);
                break;

            case TokenType.Legato:
                resultContainer = Legato.Apply(clips);
                break;

            case TokenType.Mask:
                resultContainer = Mask.Apply(command, clips);
                break;

            case TokenType.Monophonize:
                resultContainer = Monophonize.Apply(clips);
                break;

            case TokenType.Quantize:
                resultContainer = Quantize.Apply(command, clips);
                break;

            case TokenType.Ratchet:
                resultContainer = Ratchet.Apply(command, clips);
                break;

            case TokenType.Relength:
                resultContainer = Relength.Apply(command, clips);
                break;

            case TokenType.Resize:
                resultContainer = Resize.Apply(command, clips);
                break;

            case TokenType.Scale:
                resultContainer = Scale.Apply(command, clips);
                break;

            case TokenType.Scan:
                resultContainer = Scan.Apply(command, clips);
                break;

            case TokenType.SetLength:
                resultContainer = SetLength.Apply(command, clips);
                break;

            case TokenType.SetRhythm:
                resultContainer = SetRhythm.Apply(command, clips);
                break;

            case TokenType.Shuffle:
                resultContainer = Shuffle.Apply(command, clips);
                break;

            case TokenType.Skip:
                resultContainer = Skip.Apply(command, clips);
                break;

            case TokenType.Slice:
                resultContainer = Slice.Apply(command, clips);
                break;

            case TokenType.Take:
                resultContainer = Take.Apply(command, clips);
                break;

            case TokenType.Transpose:
                resultContainer = Transpose.Apply(command, clips);
                break;

            default:
                return(new ProcessResultArray <Clip>($"Unsupported command {command.Id}"));
            }
            return(resultContainer);
        }