float runApplyFunction(ApplyFunction e) { var func = env_.GetFunction(e.Name.Name); var args = e.Args.Select(arg => runExp(arg)).ToArray(); // closureの環境を作成する var oldEnv = env_; env_ = new Env(oldEnv); for (int i = 0; i < args.Length; i++) { var arg = args[i]; env_.Set("@" + (i + 1), arg); } try { runBlock(func.Body); } catch (ReturnJump) { // return によって終了する } var returnValue = env_.GetReturnValue(); env_ = oldEnv; return(returnValue); }
/// <summary> /// In case the transactions do not have the commands to apply, use this method to apply any commands you want with a /// given <seealso cref="ApplyFunction"/> instead. /// </summary> /// <param name="applier"> to use </param> /// <param name="function"> which knows what to do with the <seealso cref="TransactionApplier"/>. </param> /// <param name="transactions"> are only used to create <seealso cref="TransactionApplier"/>s. The actual work is delegated to the /// function. </param> /// <returns> the boolean-and result of all function operations. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static boolean apply(org.neo4j.kernel.impl.api.BatchTransactionApplier applier, ApplyFunction function, org.neo4j.kernel.impl.api.TransactionToApply... transactions) throws Exception public static bool Apply(BatchTransactionApplier applier, ApplyFunction function, params TransactionToApply[] transactions) { bool result = true; foreach (TransactionToApply tx in transactions) { using (TransactionApplier txApplier = applier.StartTx(tx, new LockGroup())) { result &= function(txApplier); } } applier.Close(); return(result); }
public static void Test() { ApplyFunction.ApplyFunc(ele => Printing.Println(ele), SolveNQueen(4), SolveNQueen(5), SolveNQueen(6), SolveNQueen(7), SolveNQueen(8), SolveNQueen(9), SolveNQueen(10), SolveNQueen(11), SolveNQueen(12) ); }
public void SetUp() { _out = new ConstantSignal <double>(() => 0.0); if (_midiManager != null) { _plugin.MidiProcessor.NoteOff -= _midiManager.NoteOff; _plugin.MidiProcessor.NoteOn -= _midiManager.NoteOn; } _midiManager = new MidiManager(NoteChannels); _plugin.MidiProcessor.NoteOff += _midiManager.NoteOff; _plugin.MidiProcessor.NoteOn += _midiManager.NoteOn; _scratchBuffer1 = new double[this.BlockSize, 1]; _scratchBuffer2 = new double[this.BlockSize, 1]; _scratchBuffer3 = new double[this.BlockSize, 1]; _scratchBuffer4 = new double[this.BlockSize, 1]; _scratchBuffer5 = new double[this.BlockSize, 1]; _scratchBuffer6 = new double[this.BlockSize, 1]; _scratchBufferChannels1 = new double[this.BlockSize, NoteChannels]; _scratchBufferChannels2 = new double[this.BlockSize, NoteChannels]; _scratchBufferChannels3 = new double[this.BlockSize, NoteChannels]; _scratchBufferChannels4 = new double[this.BlockSize, NoteChannels]; _scratchBufferChannels5 = new double[this.BlockSize, NoteChannels]; _scratchBufferChannels6 = new double[this.BlockSize, NoteChannels]; _blockSize = BlockSize; _sampleRate = SampleRate; var sine1 = new Oscillator(NoteChannels, this.SampleRate) { Shape = Oscillator.WaveShape.Sine, Frequency = _midiManager.ChannelFrequencies, OctaveShift = new ConstantSignal <int>(() => _plugin.Model.Path1OctaveShift), Amplitude = new ConstantSignal <double>(() => _plugin.Model.Sine) }; sine1.Out.Buffer = _scratchBufferChannels1; var square1 = new Oscillator(NoteChannels, this.SampleRate) { Shape = Oscillator.WaveShape.Square, Frequency = _midiManager.ChannelFrequencies, OctaveShift = new ConstantSignal <int>(() => _plugin.Model.Path1OctaveShift), Amplitude = new ConstantSignal <double>(() => _plugin.Model.Square) }; square1.Out.Buffer = _scratchBufferChannels2; var triangle1 = new Oscillator(NoteChannels, this.SampleRate) { Shape = Oscillator.WaveShape.Triangle, Frequency = _midiManager.ChannelFrequencies, OctaveShift = new ConstantSignal <int>(() => _plugin.Model.Path1OctaveShift), Amplitude = new ConstantSignal <double>(() => _plugin.Model.Triangle) }; triangle1.Out.Buffer = _scratchBufferChannels3; var sine2 = new Oscillator(NoteChannels, this.SampleRate) { Shape = Oscillator.WaveShape.Sine, Frequency = _midiManager.ChannelFrequencies, OctaveShift = new ConstantSignal <int>(() => _plugin.Model.Path2OctaveShift), Amplitude = new ConstantSignal <double>(() => _plugin.Model.Sine) }; sine2.Out.Buffer = _scratchBufferChannels4; var square2 = new Oscillator(NoteChannels, this.SampleRate) { Shape = Oscillator.WaveShape.Square, Frequency = _midiManager.ChannelFrequencies, OctaveShift = new ConstantSignal <int>(() => _plugin.Model.Path2OctaveShift), Amplitude = new ConstantSignal <double>(() => _plugin.Model.Square) }; square2.Out.Buffer = _scratchBufferChannels5; var triangle2 = new Oscillator(NoteChannels, this.SampleRate) { Shape = Oscillator.WaveShape.Triangle, Frequency = _midiManager.ChannelFrequencies, OctaveShift = new ConstantSignal <int>(() => _plugin.Model.Path2OctaveShift), Amplitude = new ConstantSignal <double>(() => _plugin.Model.Triangle) }; triangle2.Out.Buffer = _scratchBufferChannels6; var sourceSum1 = new Sum("sourceSum"); sourceSum1.Inputs.Add(sine1.Out); sourceSum1.Inputs.Add(square1.Out); sourceSum1.Inputs.Add(triangle1.Out); sourceSum1.Buffer = _scratchBufferChannels1; var sourceSum2 = new Sum("sourceSum2"); sourceSum2.Inputs.Add(sine2.Out); sourceSum2.Inputs.Add(square2.Out); sourceSum2.Inputs.Add(triangle2.Out); sourceSum2.Buffer = _scratchBufferChannels4; var adsr1 = new Adsr(NoteChannels, this.SampleRate) { ReleaseDuration = new ConstantSignal <double>(() => _plugin.Model.ReleaseDuration / 5), AttackDuration = new ConstantSignal <double>(() => _plugin.Model.AttackDuration / 10), DecayDuration = new ConstantSignal <double>(() => _plugin.Model.DecayDuration / 10), Attack = new ConstantSignal <double>(() => _plugin.Model.AttackStrength), Sustain = new ConstantSignal <double>(() => _plugin.Model.SustainStrength), Triggers = _midiManager.ChannelTriggers, Input = sourceSum1 }; adsr1.Out.Buffer = _scratchBufferChannels1; var adsr2 = new Adsr(NoteChannels, this.SampleRate) { ReleaseDuration = new ConstantSignal <double>(() => _plugin.Model.ReleaseDuration / 5), AttackDuration = new ConstantSignal <double>(() => _plugin.Model.AttackDuration / 10), DecayDuration = new ConstantSignal <double>(() => _plugin.Model.DecayDuration / 10), Attack = new ConstantSignal <double>(() => _plugin.Model.AttackStrength), Sustain = new ConstantSignal <double>(() => _plugin.Model.SustainStrength), Triggers = _midiManager.ChannelTriggers, Input = sourceSum2 }; adsr2.Out.Buffer = _scratchBufferChannels4; var delayOsc = new Oscillator(1, SampleRate) { Shape = Oscillator.WaveShape.Triangle, Frequency = new ConstantSignal <double>(() => _plugin.Model.Delay1PlaybackSpeedFreq), Amplitude = new ConstantSignal <double>(() => Math.Pow(_plugin.Model.Delay1PlaybackSpeedMod, 3) / 2), Base = new ConstantSignal <double>(() => 1) }; delayOsc.Out.Buffer = _scratchBuffer1; var delay1 = new Delay() { DelayLength = new ConstantSignal <int>(() => _plugin.Model.Delay1Length), PlaybackSpeed = delayOsc.Out, Gain = new ConstantSignal <double>(() => _plugin.Model.Delay1Gain) }; delay1.Out.Buffer = _scratchBuffer2; var combine1 = new Mix("Combine"); combine1.Inputs.Add(delay1.Out); combine1.Inputs.Add(adsr1.Out.Flat((sum, cur) => sum + cur, 0d)); combine1.Strengths.Add(new ConstantSignal <double>(() => _plugin.Model.Wet1)); combine1.Strengths.Add(new ConstantSignal <double>(() => 1 - _plugin.Model.Wet1)); combine1.Buffer = _scratchBuffer3; var lowPass1 = new LowPass("lowpass1") { Scale = new ConstantSignal <int>(() => _plugin.Model.Filter1), Input = combine1 }; lowPass1.Buffer = _scratchBuffer4; delay1.Input = lowPass1; var combine2 = new Mix("Combine2"); combine2.Inputs.Add(delay1.Out); combine2.Inputs.Add(adsr2.Out.Flat((sum, cur) => sum + cur, 0d)); combine2.Strengths.Add(new ConstantSignal <double>(() => _plugin.Model.Gain1)); combine2.Strengths.Add(new ConstantSignal <double>(() => _plugin.Model.Gain2)); combine2.Buffer = _scratchBuffer6; var softClip = new ApplyFunction(sample => sample / (1 + Math.Abs(sample)), "SoftClip") { Buffer = _scratchBuffer6, Input = combine2 }; _out = softClip; }
public static object[] AllPrintlnln(params dynamic[] values) => ApplyFunction.ApplyFunc(ele => Printlnln(ele), values);
public Effect(ApplyFunction apply, Size?readBlock = null, Size?writeBlock = null) : base(readBlock ?? new Size(1, 1), writeBlock ?? new Size(1, 1)) => this.apply = apply ?? throw new ArgumentNullException(nameof(apply));