// Use this for initialization void Start() { levelString = "Assets/Scripts/Level" + levelCounter + ".json"; levelCounter++; parsingTime.ParseLevel(levelString); mix = GameObject.Find("MixerObject").GetComponent<Mixer>(); }
private byte ProcessBlock(byte block, byte[] keys) { var encryptedBlock = StartPermutation(block); encryptedBlock = new Mixer().Mix(encryptedBlock, keys); encryptedBlock = EndPermutation(encryptedBlock); return encryptedBlock; }
public void PropertiesInMixinAndChild_Mix_OnlyMissingPropertiesToImplement() { var sourceCode = new SourceCode(Files.Person, Files.Name); var personClass = sourceCode.Class(nameof(PersonWithFullName)); var mixinField = personClass.FindMixinReference("_name"); var child = new ClassFactory(sourceCode.Semantic).Create(personClass); var mixin = new MixinReferenceFactory(sourceCode.Semantic).Create(mixinField); var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); // Assert: all properties of mixin should be implemented Assert.AreEqual(2, mixer.MembersToImplement.Count()); }
public void PropertiesInBaseClass_Mix_NoPropertyToImplement() { var sourceCode = new SourceCode(Files.Person, Files.Name); var personClass = sourceCode.Class(nameof(ThirdPersonClass)); var mixinField = personClass.FindMixinReference("_name"); var child = new ClassFactory(sourceCode.Semantic).Create(personClass); var mixin = new MixinReferenceFactory(sourceCode.Semantic).Create(mixinField); var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); // Assert: all properties of mixin should be implemented Assert.IsEmpty(mixer.MembersToImplement); }
public void MethodImplementedWithOtherParameter_Include_MethodIncluded() { var sourceCode = new SourceCode(Files.Person, Files.Worker); var personClass = sourceCode.Class(nameof(PersonWithOtherWorkMethod)); var mixinReference = personClass.FindMixinReference("_worker"); var semanticModel = sourceCode.Semantic; var mixin = new MixinReferenceFactory(semanticModel).Create(mixinReference); var child = new ClassFactory(semanticModel).Create(personClass); var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); // no method to implement Assert.AreEqual(1,mixer.MethodsToImplement.Count(x => x.Name == "Work")); }
public void MixinWithStaticMethod_Include_MethodNotIncluded() { var sourceCode = new SourceCode(Files.Person, Files.Worker); var personClass = sourceCode.Class(nameof(PersonWithStaticMethodMixin)); var mixinReference = personClass.FindMixinReference("_worker"); var semanticModel = sourceCode.Semantic; var mixin = new MixinReferenceFactory(semanticModel).Create(mixinReference); var child = new ClassFactory(semanticModel).Create(personClass); var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); // no method to implement Assert.IsEmpty(mixer.MethodsToImplement); }
public void MixinWithMethod_Include_MethodsIncluded() { var sourceCode = new SourceCode(Files.Person, Files.Worker); var personClass = sourceCode.Class(nameof(Person)); var mixinReference = personClass.FindMixinReference("_worker"); var semanticModel = sourceCode.Semantic; var mixin = new MixinReferenceFactory(semanticModel).Create(mixinReference); var child = new ClassFactory(semanticModel).Create(personClass); var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); Assert.AreEqual(mixer.MethodsToImplement.Count(), mixin.Class.Methods.Count()); foreach (var service in mixin.Class.Methods) Assert.AreEqual(1, mixer.MethodsToImplement.Count(x => x.Name == service.Name)); }
public void Test5() { var skeleton = new CoreSkeleton(skelPath); var mesh = new CoreMesh(meshPath, skeleton); var anim = new CoreAnimation(animPath, skeleton); var skelInstance = new Skeleton(skeleton); var mixer = new Mixer(); // play the animation mixer.Play(anim).Once(); mixer.Update(0); skelInstance.Animate(mixer); var verts = mesh.GetTransformedVertices(skelInstance); var indices = mesh.GetIndices(); }
public void MixinClassWithProperty_Include_PropertiesIncluded() { // arrange var sourceCode = new SourceCode(Files.Person, Files.Name); var personClass = sourceCode.Class(nameof(Person)); var mixinReference = personClass.FindMixinReference("_name"); var semanticModel = sourceCode.Semantic; var mixin = new MixinReferenceFactory(semanticModel).Create(mixinReference); var child = new ClassFactory(semanticModel).Create(personClass); // act var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); // assert all properties of the mixin should have been added Assert.AreEqual(mixin.Class.Properties.Count(),mixer.PropertiesToImplement.Count()); // check that every method of mixin appears only once in the child foreach (var service in mixin.Class.Properties) Assert.AreEqual(1, mixer.PropertiesToImplement.Count(x => x.Name == service.Name)); }
public void MixinWithPropertyOnlyGetter_Include_PropertyHasGetter() { // arrange // 1. load source files and get class and mixin declarations var sourceCode = new SourceCode(Files.Person, Files.Name); var personClass = sourceCode.Class(nameof(PersonWithGetterName)); var mixinReference = personClass.FindMixinReference("_name"); var semanticModel = sourceCode.Semantic; // 2. create instances for mixin and child mixin var mixin = new MixinReferenceFactory(semanticModel).Create(mixinReference); var child = new ClassFactory(semanticModel).Create(personClass); // act var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); // assert. Only one property in resulting class Assert.AreEqual(1, mixer.PropertiesToImplement.Count()); // that one property should only have a getter Assert.AreEqual(1, mixer.PropertiesToImplement.Count(x => x.IsReadOnly)); }
public void Test4() { // testing fluent interface var skeleton = new CoreSkeleton(skelPath); var animation = new CoreAnimation(animPath, skeleton); var mixer = new Mixer(); bool callbackHappened = false; mixer.Play(animation).Once().WithWeight(1.0f).AndThen(() => callbackHappened = true); // now take a skeleton instance, and calculate its state. var skelInstance = new Skeleton(skeleton); skelInstance.Animate(mixer); mixer.Update(0.2f); Assert.IsTrue(callbackHappened); }
public void MixinInterfaceWithProperty_Include_PropertiesIncluded() { // arrange // 1. load source files and get class and mixin declarations var sourceCode = new SourceCode(Files.Person, Files.Name); var personClass = sourceCode.Class(nameof(Person)); var mixinReference = personClass.FindMixinReference("_interfaceName"); var semanticModel = sourceCode.Semantic; // 2. create instances for mixin and child mixin var mixin = new MixinReferenceFactory(semanticModel).Create(mixinReference); var child = new ClassFactory(semanticModel).Create(personClass); // act var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); // assert. The child should have the same properties as the mixin Assert.AreEqual(mixin.Class.Properties.Count(), mixer.PropertiesToImplement.Count()); // check that every method of mixin appears only once in the child foreach (var service in mixin.Class.Properties) Assert.AreEqual(1, mixer.PropertiesToImplement.Count(x => x.Name == service.Name)); }
private Flowsheet SetFlowsheetContent(NewSystemPreferences newSystemPrefs, ArrayList items) { Flowsheet flowsheet = null; IEnumerator e = items.GetEnumerator(); while (e.MoveNext()) { object obj = e.Current; if (obj is EvaporationAndDryingSystem) { EvaporationAndDryingSystem persisted = (EvaporationAndDryingSystem)obj; persisted.SetObjectData(); flowsheet = new Flowsheet(newSystemPrefs, persisted); } else if (obj is GasStreamControl) { GasStreamControl persistedCtrl = (GasStreamControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); DryingGasStream stream = flowsheet.EvaporationAndDryingSystem.GetGasStream(solvableName); GasStreamControl newCtrl = new GasStreamControl(flowsheet, new Point(0,0), stream); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is MaterialStreamControl) { MaterialStreamControl persistedCtrl = (MaterialStreamControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); DryingMaterialStream stream = flowsheet.EvaporationAndDryingSystem.GetMaterialStream(solvableName); MaterialStreamControl newCtrl = new MaterialStreamControl(flowsheet, new Point(0,0), stream); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is DryerControl) { DryerControl persistedCtrl = (DryerControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Dryer uo = flowsheet.EvaporationAndDryingSystem.GetDryer(solvableName); DryerControl newCtrl = new DryerControl(flowsheet, new Point(0,0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is HeatExchangerControl) { HeatExchangerControl persistedCtrl = (HeatExchangerControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); HeatExchanger uo = flowsheet.EvaporationAndDryingSystem.GetHeatExchanger(solvableName); HeatExchangerControl newCtrl = new HeatExchangerControl(flowsheet, new Point(0,0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is CycloneControl) { CycloneControl persistedCtrl = (CycloneControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Cyclone uo = flowsheet.EvaporationAndDryingSystem.GetCyclone(solvableName); CycloneControl newCtrl = new CycloneControl(flowsheet, new Point(0,0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is EjectorControl) { EjectorControl persistedCtrl = (EjectorControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Ejector uo = flowsheet.EvaporationAndDryingSystem.GetEjector(solvableName); EjectorControl newCtrl = new EjectorControl(flowsheet, new Point(0,0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is WetScrubberControl) { WetScrubberControl persistedCtrl = (WetScrubberControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); WetScrubber uo = flowsheet.EvaporationAndDryingSystem.GetWetScrubber(solvableName); WetScrubberControl newCtrl = new WetScrubberControl(flowsheet, new Point(0,0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is MixerControl) { MixerControl persistedCtrl = (MixerControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Mixer uo = flowsheet.EvaporationAndDryingSystem.GetMixer(solvableName); MixerControl newCtrl = new MixerControl(flowsheet, new Point(0,0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is TeeControl) { TeeControl persistedCtrl = (TeeControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Tee uo = flowsheet.EvaporationAndDryingSystem.GetTee(solvableName); TeeControl newCtrl = new TeeControl(flowsheet, new Point(0,0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is FlashTankControl) { FlashTankControl persistedCtrl = (FlashTankControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); FlashTank uo = flowsheet.EvaporationAndDryingSystem.GetFlashTank(solvableName); FlashTankControl newCtrl = new FlashTankControl(flowsheet, new Point(0,0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is FanControl) { FanControl persistedCtrl = (FanControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Fan uo = flowsheet.EvaporationAndDryingSystem.GetFan(solvableName); FanControl newCtrl = new FanControl(flowsheet, new Point(0,0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is ValveControl) { ValveControl persistedCtrl = (ValveControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Valve uo = flowsheet.EvaporationAndDryingSystem.GetValve(solvableName); ValveControl newCtrl = new ValveControl(flowsheet, new Point(0,0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is BagFilterControl) { BagFilterControl persistedCtrl = (BagFilterControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); BagFilter uo = flowsheet.EvaporationAndDryingSystem.GetBagFilter(solvableName); BagFilterControl newCtrl = new BagFilterControl(flowsheet, new Point(0,0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is AirFilterControl) { AirFilterControl persistedCtrl = (AirFilterControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); AirFilter uo = flowsheet.EvaporationAndDryingSystem.GetAirFilter(solvableName); AirFilterControl newCtrl = new AirFilterControl(flowsheet, new Point(0,0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is CompressorControl) { CompressorControl persistedCtrl = (CompressorControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Compressor uo = flowsheet.EvaporationAndDryingSystem.GetCompressor(solvableName); CompressorControl newCtrl = new CompressorControl(flowsheet, new Point(0,0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is HeaterControl) { HeaterControl persistedCtrl = (HeaterControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Heater uo = flowsheet.EvaporationAndDryingSystem.GetHeater(solvableName); HeaterControl newCtrl = new HeaterControl(flowsheet, new Point(0,0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is CoolerControl) { CoolerControl persistedCtrl = (CoolerControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Cooler uo = flowsheet.EvaporationAndDryingSystem.GetCooler(solvableName); CoolerControl newCtrl = new CoolerControl(flowsheet, new Point(0,0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is ElectrostaticPrecipitatorControl) { ElectrostaticPrecipitatorControl persistedCtrl = (ElectrostaticPrecipitatorControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); ElectrostaticPrecipitator uo = flowsheet.EvaporationAndDryingSystem.GetElectrostaticPrecipitator(solvableName); ElectrostaticPrecipitatorControl newCtrl = new ElectrostaticPrecipitatorControl(flowsheet, new Point(0,0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is PumpControl) { PumpControl persistedCtrl = (PumpControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Pump uo = flowsheet.EvaporationAndDryingSystem.GetPump(solvableName); PumpControl newCtrl = new PumpControl(flowsheet, new Point(0,0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is RecycleControl) { RecycleControl persistedCtrl = (RecycleControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Recycle uo = flowsheet.EvaporationAndDryingSystem.GetRecycle(solvableName); RecycleControl newCtrl = new RecycleControl(flowsheet, new Point(0,0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is SolvableConnection) { SolvableConnection persistedDc = (SolvableConnection)obj; SolvableConnection dc = new SolvableConnection(flowsheet); dc.SetObjectData(persistedDc.SerializationInfo, persistedDc.StreamingContext); flowsheet.ConnectionManager.Connections.Add(dc); } else if (obj is FlowsheetPreferences) { FlowsheetPreferences flowsheetPrefs = obj as FlowsheetPreferences; flowsheetPrefs.SetObjectData(flowsheetPrefs.SerializationInfo, flowsheetPrefs.StreamingContext); flowsheet.InitializeCurrentUnitSystem(flowsheetPrefs.CurrentUnitSystemName); flowsheet.NumericFormat = flowsheetPrefs.NumericFormat; flowsheet.DecimalPlaces = flowsheetPrefs.DecimalPlaces; } else if (obj is ProsimoUI.CustomEditor.CustomEditor) { ProsimoUI.CustomEditor.CustomEditor persistedEditor = (ProsimoUI.CustomEditor.CustomEditor)obj; flowsheet.CustomEditor.SetObjectData(persistedEditor.SerializationInfo, persistedEditor.StreamingContext); } } if (this.CheckFlowsheetVersion(items, flowsheet)) flowsheet.IsDirty = false; else flowsheet = null; return flowsheet; }
private void SetPitchPercent(float value) { pitchPercent = value; Mixer.SetFloat(masterPitchFieldName, pitchPercent); }
public MixerControl(Flowsheet flowsheet, Point location, Mixer mixer) : base(flowsheet, location, mixer) { }
public void MixinWithGenericParameter_Include_MixinImplemented() { var sourceCode = new SourceCode(Files.Person, Files.Worker); var personClass = sourceCode.Class(nameof(PersonWithGenericClassMixin)); var mixinReference = personClass.FindMixinReference("_worker"); var semanticModel = sourceCode.Semantic; var mixin = new MixinReferenceFactory(semanticModel).Create(mixinReference); var child = new ClassFactory(semanticModel).Create(personClass); var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); // there should be one method to implement Assert.AreEqual(1, mixer.MethodsToImplement.Count()); // parameter and return type of the method should be int Assert.AreEqual("int", mixer.MethodsToImplement.Single().ReturnType.ToString()); Assert.AreEqual("int", mixer.MethodsToImplement.Single().GetParameter(0).Type.ToString()); }
public void Stop() { Mixer.StopHandle(_handle); }
public void MixinWithIndexer_Include_IndexerImplemented() { // arrange var sourceCode = new SourceCode(Files.Person, Files.Collection); var personClass = sourceCode.Class(nameof(PersonWithIndexer)); var mixinReference = personClass.FindMixinReference("_collection"); var semanticModel = sourceCode.Semantic; var mixin = new MixinReferenceFactory(semanticModel).Create(mixinReference); var child = new ClassFactory(semanticModel).Create(personClass); // act var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); // child should also have an indexer property now Assert.AreEqual(1, mixer.PropertiesToImplement.Count()); Assert.AreEqual("string this[int index]", mixer.PropertiesToImplement.Single().ToString()); }
public void ChildWithOverrideProperty_Include_PropertyOverrideNotCreated() { var sourceCode = new SourceCode(Files.Person, Files.Name); var personClass = sourceCode.Class(nameof(PersonWithOverriddenProperty)); var mixinReference = personClass.FindMixinReference("_name"); var semanticModel = sourceCode.Semantic; var mixin = new MixinReferenceFactory(semanticModel).Create(mixinReference); var child = new ClassFactory(semanticModel).Create(personClass); var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); // no property to override because child overrides it already Assert.AreEqual(0, mixer.PropertiesToImplement.Count()); }
/// <summary> /// Callback from Windows Volume Control /// </summary> /// <param name="mixer"></param> /// <param name="line"></param> private void mMixer_MixerLineChanged(Mixer mixer, MixerLine line) { mAvoidEvents = true; try { float balance = -1; MixerLine frontEndLine = (MixerLine)toolStripTrackBar1.Tag; if (frontEndLine == line) { int volume = 0; if (line.Channels != 2) { volume = line.Volume; } else { line.Channel = Channel.Left; int left = line.Volume; line.Channel = Channel.Right; int right = line.Volume; if (left > right) { volume = left; // TIP: Do not reset the balance if both left and right channel have 0 value if (left != 0 && right != 0) { balance = (volume > 0) ? -(1 - (right / (float)left)) : 0; } } else { volume = right; // TIP: Do not reset the balance if both left and right channel have 0 value if (left != 0 && right != 0) { balance = (volume > 0) ? 1 - (left / (float)right) : 0; } } } if (volume >= 0) { toolStripTrackBar1.Value = volume; } } // adjust toolstrip checkboxes if ((MixerLine)toolStripMicMuteButton.Tag == line) { toolStripMicMuteButton.Checked = line.Volume == 0 ? true : false; } else if ((MixerLine)toolStripMuteButton.Tag == line) { toolStripMuteButton.Checked = line.Mute; } } finally { mAvoidEvents = false; } }
private void UpdateStreamUI() { //this.panel.Visible = false; //this.groupBox.Visible = false; //this.groupBox.Controls.Clear(); //this.inletControls.Clear(); //int x = INITIAL_LOCATION; //int w = VALUE_WIDTH; //int s = INITIAL_GROUPBOX_WIDTH; //int p = INITIAL_FORM_WIDTH; Mixer mixer = this.MixerCtrl.Mixer; bool hasStreamIn = false; bool hasStreamOut = false; ProcessStreamBase streamIn = null; if (mixer.InletStreams.Count > 0) { hasStreamIn = true; streamIn = (ProcessStreamBase)mixer.InletStreams[0]; } ProcessStreamBase streamOut = mixer.Outlet; Boolean bFirstControl = true; if (streamOut != null) { hasStreamOut = true; } if (hasStreamIn) { IEnumerator e = mixer.InletStreams.GetEnumerator(); while (e.MoveNext()) { ProcessStreamBase processStreamBase = (ProcessStreamBase)e.Current; ProcessStreamBaseControl processInCtrl = (ProcessStreamBaseControl)this.MixerCtrl.Flowsheet.StreamManager.GetProcessStreamBaseControl(processStreamBase.Name); if (bFirstControl) { initializeGrid(processInCtrl, columnIndex, false, "Inlet/Outlet"); columnIndex += 2; bFirstControl = false; } else { initializeGrid(processInCtrl, columnIndex, true, "Inlet/Outlet"); columnIndex++; } //this.groupBox.Controls.Add(textBoxStreamInName); //UI.SetStatusColor(textBoxStreamInName, processStreamBase.SolveState); } } if (hasStreamOut) { ProcessStreamBaseControl processOutCtrl = (ProcessStreamBaseControl)this.MixerCtrl.Flowsheet.StreamManager.GetProcessStreamBaseControl(streamOut.Name); if (bFirstControl) { initializeGrid(processOutCtrl, columnIndex, false, "Inlet/Outlet"); columnIndex += 2; bFirstControl = false; } else { initializeGrid(processOutCtrl, columnIndex, true, "Inlet/Outlet"); columnIndex++; } //UserControl ctrl = null; // if (streamOut is ProcessStream)) // { // ProcessStreamControl processOutCtrl = (ProcessStreamControl)this.MixerCtrl.Flowsheet.StreamManager.GetProcessStreamBaseControl(streamOut.Name); //ctrl = new ProcessStreamValuesControl(processOutCtrl); // } // else if (streamOut is DryingGasStream) // { // GasStreamControl gasOutCtrl = (GasStreamControl)this.MixerCtrl.Flowsheet.StreamManager.GetProcessStreamBaseControl(streamOut.Name); // ctrl = new GasStreamValuesControl(gasOutCtrl); // } // else if (streamOut is DryingMaterialStream) // { // MaterialStreamControl materialOutCtrl = (MaterialStreamControl)this.MixerCtrl.Flowsheet.StreamManager.GetProcessStreamBaseControl(streamOut.Name); // ctrl = new MaterialStreamValuesControl(materialOutCtrl); // } // ctrl.Location = new Point(x, 12 + 20 + 2); // this.groupBox.Size = new Size(s, this.groupBoxHeight); // this.groupBox.Controls.Add(ctrl); // this.Size = new Size(p, this.formHeight); // textBoxStreamOutName.Text = streamOut.Name; // textBoxStreamOutName.Location = new Point(x, 12); // this.textBoxStreamOutName.SetSolvable(streamOut); // this.groupBox.Controls.Add(this.textBoxStreamOutName); //UI.SetStatusColor(this.statusBar, streamOut.BSolveState); } //this.panel.Visible = true; }
public void ChildWithAbstractMethodFromBase_Include_AbstractMethodOverridden() { // file Person with base class is also needed here var sourceCode = new SourceCode(Files.Person, Files.NotCompilable, Files.Worker); var personClass = sourceCode.Class("PersonFromAbstractWork"); var mixinReference = personClass.FindMixinReference("_worker"); var semanticModel = sourceCode.Semantic; var mixin = new MixinReferenceFactory(semanticModel).Create(mixinReference); var child = new ClassFactory(semanticModel).Create(personClass); var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); // there should be one method that overrides the abstract method Assert.AreEqual(1, mixer.MethodsToImplement.Count()); // only one method from the mixin should be implemented, the other one // is alredy implemented by childs base Assert.AreEqual(1, mixer.MethodsToImplement.Count(x => x.Name == "Work")); Assert.IsTrue(mixer.MethodsToImplement.Single().IsOverride); }
public void ChildWithOverrideMethod_Include_MethodOverrideNotCreated() { var sourceCode = new SourceCode(Files.Person, Files.Worker); var personClass = sourceCode.Class(nameof(PersonWithOverriddenMethod)); var mixinReference = personClass.FindMixinReference("_worker"); var semanticModel = sourceCode.Semantic; var mixin = new MixinReferenceFactory(semanticModel).Create(mixinReference); var child = new ClassFactory(semanticModel).Create(personClass); var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); // there should not be any method to override, // because the child itself already overrides the method Assert.AreEqual(0, mixer.MethodsToImplement.Count()); }
public void ChildWithBaseMethod_Include_BaseMethodNotImplemented() { var sourceCode = new SourceCode(Files.Person, Files.Worker); var personClass = sourceCode.Class(nameof(DerivedPerson)); var mixinReference = personClass.FindMixinReference("_worker"); var semanticModel = sourceCode.Semantic; var mixin = new MixinReferenceFactory(semanticModel).Create(mixinReference); var child = new ClassFactory(semanticModel).Create(personClass); var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); // there should be two methods, from base mixin and derived mixin Assert.AreEqual(1, mixer.MethodsToImplement.Count()); // only one method from the mixin should be implemented, the other one // is alredy implemented by childs base Assert.AreEqual(1, mixer.MethodsToImplement.Count(x => x.Name == "Work")); }
public JsonResult Create(int?DestinationHairColorID, int?ActualHairColorID) { Mixer _mixer = db.Mixers.SingleOrDefault(m => m.ActualHairColorID == ActualHairColorID && m.DestinationHairColorID == DestinationHairColorID); string _userID = User.Identity.GetUserId(); // Balance _balance =await db.Balances.Include(m=>m.Pays).SingleOrDefaultAsync(m => m.UserID == _userID); var PayCoins = db.PayCoins.Include(m => m.User).Where(m => m.UserID == _userID).ToList(); var bal = 0; foreach (var item in PayCoins) { if (item.InOutType == PayCoin.PayInType) { bal += item.NumberOfCoins; } else if (item.InOutType == PayCoin.PayOutType) { bal -= item.NumberOfCoins; } } //Pay _pay=new Pay() //{ // Balance =await db.Balances.Include(m=>m.User).Where(m=>m.UserID==_userID).SingleOrDefaultAsync(), //}; if (bal > 0) { //PayCoin coin = new PayCoin() //{ // InOutType = PayCoin.PayOutType, // NumberOfCoins = 1, // RegisterDate = DateTime.Today, // UserID = _userID //}; //db.PayCoins.Add(coin); //db.SaveChanges(); Cart _newCart = new Cart() { Mixer = _mixer, PayCoin = new PayCoin() { InOutType = PayCoin.PayOutType, NumberOfCoins = 1, RegisterDate = DateTime.Today, UserID = _userID, //Pay = new Pay() //{ // Balance =db.Balances.Where(m=>m.UserID==_userID).SingleOrDefault(), // InOutType = Pay.PayOut, // PayPlan = null, // State = true //} }, RegisterDate = DateTime.Now, StartDay = DateTime.Now, ConfirmDate = DateTime.Now, EndDate = DateTime.Now.AddDays(int.Parse(db.Settings.Where(m => m.Setting_Name == Setting.SHOWDAYS_NO).SingleOrDefault().Setting_Value)) }; db.Carts.Add(_newCart); db.SaveChanges(); return(Json(_mixer)); } else { Tuple <bool, string> msg; bool type = false; string text = "موجودی شما کافی نیست"; msg = new Tuple <bool, string>(type, text); return(Json(msg)); } }
public void MixinWithBaseClass_Include_BothMethodsImplemented() { var sourceCode = new SourceCode(Files.Person, Files.Worker); var personClass = sourceCode.Class(nameof(PersonWithDerivedWorker)); var mixinReference = personClass.FindMixinReference("_worker"); var semanticModel = sourceCode.Semantic; var mixin = new MixinReferenceFactory(semanticModel).Create(mixinReference); var child = new ClassFactory(semanticModel).Create(personClass); var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); // there should be two methods, from base mixin and derived mixin Assert.AreEqual(2, mixer.MethodsToImplement.Count()); // method from base should be in the implementation list Assert.AreEqual(1, mixer.MethodsToImplement.Count(x => x.Name == "Work")); // method from derived should be in the implementation list Assert.AreEqual(1, mixer.MethodsToImplement.Count(x => x.Name == "AdditionalWork")); }
/// <summary> /// Load configuration from dictionary /// </summary> /// <param name="dictionary">Dictionary with dosbox configuration data.</param> /// <returns>DosBoxConfiguration data</returns> public DosBoxConfiguration LoadDictionary(IDictionary <string, object> dictionary) { foreach (var keyValue in dictionary) { switch (keyValue.Key) { case "sdl": if (keyValue.Value is IDictionary <string, object> ) { SDL.LoadDictionary(keyValue.Value as IDictionary <string, object>); } break; case "dosbox": if (keyValue.Value is IDictionary <string, object> ) { DosBox.LoadDictionary(keyValue.Value as IDictionary <string, object>); } break; case "render": if (keyValue.Value is IDictionary <string, object> ) { Render.LoadDictionary(keyValue.Value as IDictionary <string, object>); } break; case "cpu": if (keyValue.Value is IDictionary <string, object> ) { CPU.LoadDictionary(keyValue.Value as IDictionary <string, object>); } break; case "mixer": if (keyValue.Value is IDictionary <string, object> ) { Mixer.LoadDictionary(keyValue.Value as IDictionary <string, object>); } break; case "midi": if (keyValue.Value is IDictionary <string, object> ) { Midi.LoadDictionary(keyValue.Value as IDictionary <string, object>); } break; case "sblaster": if (keyValue.Value is IDictionary <string, object> ) { SoundBlaster.LoadDictionary(keyValue.Value as IDictionary <string, object>); } break; case "gus": if (keyValue.Value is IDictionary <string, object> ) { GUS.LoadDictionary(keyValue.Value as IDictionary <string, object>); } break; case "speaker": if (keyValue.Value is IDictionary <string, object> ) { Speaker.LoadDictionary(keyValue.Value as IDictionary <string, object>); } break; case "joystick": if (keyValue.Value is IDictionary <string, object> ) { Joystick.LoadDictionary(keyValue.Value as IDictionary <string, object>); } break; case "serial": if (keyValue.Value is IDictionary <string, object> ) { Serial.LoadDictionary(keyValue.Value as IDictionary <string, object>); } break; case "dos": if (keyValue.Value is IDictionary <string, object> ) { DOS.LoadDictionary(keyValue.Value as IDictionary <string, object>); } break; case "ipx": if (keyValue.Value is IDictionary <string, object> ) { IPX.LoadDictionary(keyValue.Value as IDictionary <string, object>); } break; case "autoexec": if (keyValue.Value is IDictionary <string, object> ) { Autoexec.LoadDictionary(keyValue.Value as IDictionary <string, object>); } break; default: break; } } return(this); }
private void RenderButton_Click(object sender, EventArgs e) { if (_progress != null) { // Cancel the rendering _progress.Cancel(); return; } _progress = new MainFormProgressOutput(this); var outputs = new List <IGraphicsOutput> { _progress }; lock (_settings) { if (_settings.Preview.Enabled) { outputs.Add(new PreviewOutput(_settings.Preview.Frameskip)); } if (_settings.EncodeVideo.Enabled) { LocateProgram("ffmpeg.exe", _programSettings.FfmpegPath, p => _programSettings.FfmpegPath = p); using (var saveFileDialog = new SaveFileDialog { Title = "Select destination", Filter = "Video files (*.mp4;*.mkv;*.avi;*.qt)|*.mp4;*.mkv;*.avi;*.qt|All files (*.*)|*.*" }) { if (saveFileDialog.ShowDialog(this) != DialogResult.OK) { // Cancel the whole operation _progress = null; foreach (var output in outputs) { output.Dispose(); } return; } var outputFilename = saveFileDialog.FileName; if (_settings.MasterAudio.IsAutomatic) { var filename = outputFilename + ".wav"; Mixer.MixToFile(_settings.Channels, filename, MasterMixReplayGain.Checked); MasterAudioPath.Text = filename; _settings.MasterAudio.Path = filename; } else { _settings.MasterAudio.Path = MasterAudioPath.Text; } outputs.Add(new FfmpegOutput( _programSettings.FfmpegPath, outputFilename, _settings.Width, _settings.Height, _settings.FrameRate, _programSettings.FfmpegExtraParameters, _settings.MasterAudio.Path)); } } } RenderButton.Text = "Cancel render"; // Start a background thread to do the rendering work Task.Factory.StartNew(() => { try { var renderer = CreateWaveformRenderer(); renderer.Render(outputs); } catch (Exception exception) { BeginInvoke(new Action(() => MessageBox.Show(exception.Message))); } finally { foreach (var graphicsOutput in outputs) { graphicsOutput.Dispose(); } _progress = null; BeginInvoke(new Action(() => RenderButton.Text = "Render")); } }); }
public void MixinWithGenericProperty_Include_PropertyImplemented() { // arrange var sourceCode = new SourceCode(Files.Person, Files.Name); var personClass = sourceCode.Class(nameof(PersonWithGenericMixin)); var mixinReference = personClass.FindMixinReference("_name"); var semanticModel = sourceCode.Semantic; var mixin = new MixinReferenceFactory(semanticModel).Create(mixinReference); var child = new ClassFactory(semanticModel).Create(personClass); // act var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); // child should have "Name" property Assert.AreEqual(1, mixer.PropertiesToImplement.Count(x => x.Name == "Names")); // name property should be of type "IEnumerable<string>" var typeName = mixer.PropertiesToImplement.Single().Type.ToString(); Assert.AreEqual("System.Collections.Generic.IEnumerable<string>", typeName); }
public void Complex_UsersInput_And_Formulas_Extracting_Deserialize_And_Final_Merge() { var filePathLeft = Path.Combine(GetDataFilesPath(), "left_json.json"); var filePathRight = Path.Combine(GetDataFilesPath(), "right_json.json"); var fileExistsLeft = File.Exists(filePathLeft); var fileExistsRight = File.Exists(filePathRight); Assert.True(fileExistsLeft); Assert.True(fileExistsRight); var targetLeft = new TestClass(); var targetRight = new TestClass(); using (StreamReader sr = File.OpenText(filePathLeft)) { var objJSON = JsonConvert.DeserializeObject <ExpandoObject>(sr.ReadToEnd()); Assert.NotNull(objJSON); new ObjectsMapper().Map <TestClass, Inner>((ExpandoObject)objJSON, targetLeft); // TODO: like var target = ObjectsMapper.MapInto<TestClass>(objJSON); } using (StreamReader sr = File.OpenText(filePathRight)) { var objJSON = JsonConvert.DeserializeObject <ExpandoObject>(sr.ReadToEnd()); Assert.NotNull(objJSON); new ObjectsMapper().Map <TestClass, Inner>((ExpandoObject)objJSON, targetRight); // TODO: like var target = ObjectsMapper.MapInto<TestClass>(objJSON); } Assert.NotNull(targetLeft); Assert.NotNull(targetRight); _output.WriteLine("Left:"); _output.WriteLine($"Id: {targetLeft.Id}"); _output.WriteLine($"Name: {targetLeft.Name}"); _output.WriteLine($"Total: {targetLeft.Total}"); _output.WriteLine($"Inner 1-st Class: {targetLeft.Inners.First().Class}"); _output.WriteLine("Right:"); _output.WriteLine($"Id: {targetRight.Id}"); _output.WriteLine($"Name: {targetRight.Name}"); _output.WriteLine($"Total: {targetRight.Total}"); _output.WriteLine($"Inner 1-st Class: {targetRight.Inners.First().Class}"); dynamic mixedObject = Mixer.MixObjects(targetLeft, targetRight); _output.WriteLine("====Mixed====:"); _output.WriteLine($"Id: {mixedObject.Id}"); _output.WriteLine($"Name: {mixedObject.Name}"); _output.WriteLine($"Total: {mixedObject.Total}"); _output.WriteLine($"Inner 1-st Class: {mixedObject.Inners[0].Class}"); var target = new TestClass(); new ObjectsMapper().Map <TestClass, Inner>(mixedObject, target); // TODO: like var target = ObjectsMapper.MapInto<TestClass>(objJSON); _output.WriteLine("====Mapped====:"); _output.WriteLine($"Id: {target.Id}"); _output.WriteLine($"Name: {target.Name}"); _output.WriteLine($"Total: {target.Total}"); _output.WriteLine($"Inner 1-st Class: {target.Inners.First().Class}"); Assert.NotNull(target); }
public void ChildWithAbstractProperty_Include_AbstractPropertyOverridden() { // we need Person file and NotCompilable because // the base class is defined in Person file var sourceCode = new SourceCode(Files.Person, Files.NotCompilable, Files.Name); var personClass = sourceCode.Class("PersonFromAbstractName"); var mixinReference = personClass.FindMixinReference("_name"); var semanticModel = sourceCode.Semantic; var mixin = new MixinReferenceFactory(semanticModel).Create(mixinReference); var child = new ClassFactory(semanticModel).Create(personClass); var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); // there should be two methods, from base mixin and derived mixin Assert.AreEqual(1, mixer.PropertiesToImplement.Count()); // only one method from the mixin should be implemented, the other one // is alredy implemented by childs base Assert.AreEqual(1, mixer.PropertiesToImplement.Count(x => x.Name == "Name")); Assert.IsTrue(mixer.PropertiesToImplement.Single().IsOverride); }
/// <summary> /// Identifies the class/type of the device and returns it. /// </summary> /// <param name="plantTag">Plant tag</param> /// <param name="module">Name of the module in plant</param> /// <param name="istIds">Mapping of opc ua node id's</param> /// <returns></returns> public Device Validator(string plantTag, string module, IstOPCUANodeIds istIds) { Device local; switch (plantTag[0].ToString()) { case "P": switch (plantTag) { case "PIC": local = new Device(plantTag); break; case "PROP_V": local = new Device(plantTag); break; default: local = new Pump(plantTag); break; } break; case "V": // Valve modeld in opc ua if (istIds.TagToNodeId[module].ContainsKey(plantTag)) { // RelayValve if (istIds.TagToNodeId[module][plantTag].Core.Contains("#")) { local = new RelayValve(plantTag); } else // Normal valve { local = new Valve(plantTag); } } else // only modeld in Linked Data // Handventil. Achtung codedopplung. { local = new HandValve(plantTag); } break; case "F": // TODO: Fix device typ local = new Device(plantTag); break; case "L": // TODO: NIcht eindeutig ob binär oder linear local = new BinarySensor(plantTag); break; case "R": local = new Mixer(plantTag); break; case "T": local = new TemperatureSensor(plantTag); break; case "B": local = new Tank(plantTag); break; case "W": // Spechial case: WT if (plantTag [1].ToString() == "T") { local = new DeviceGUI(plantTag); } else { local = new Device(plantTag); } break; default: local = new Device(plantTag); break; } return(local); }
public void MixinWithToString_Include_ToStringShouldBeImplemented() { var sourceCode = new SourceCode(Files.Person, Files.Worker); var personClass = sourceCode.Class(nameof(PersonWithToString)); var mixinReference = personClass.FindMixinReference("_toString"); var semanticModel = sourceCode.Semantic; var mixin = new MixinReferenceFactory(semanticModel).Create(mixinReference); var child = new ClassFactory(semanticModel).Create(personClass); var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); // ToString should be in list of methods to override Assert.IsTrue(mixer.MethodsToImplement.Any(x => x.Name == "ToString")); // ToString in mixin must have override keyword Assert.IsTrue(mixer.MethodsToImplement.Single(x => x.Name == "ToString").IsOverrideFromObject); }
private Flowsheet SetFlowsheetContent(NewProcessSettings newProcessSettings, ApplicationPreferences appPrefs, ArrayList items, string flowsheetName) { Flowsheet flowsheet = null; FlowsheetVersion flowsheetVersion = null; IEnumerator e = items.GetEnumerator(); while (e.MoveNext()) { object obj = e.Current; if (obj is EvaporationAndDryingSystem) { EvaporationAndDryingSystem persisted = (EvaporationAndDryingSystem)obj; persisted.SetSystemFileName(flowsheetName); // call this before SetObjectData() persisted.SetObjectData(); flowsheet = new Flowsheet(newProcessSettings, appPrefs, persisted); } else if (obj is GasStreamControl) { GasStreamControl persistedCtrl = (GasStreamControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); DryingGasStream stream = flowsheet.EvaporationAndDryingSystem.GetGasStream(solvableName); GasStreamControl newCtrl = new GasStreamControl(flowsheet, new Point(0, 0), stream); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is MaterialStreamControl) { MaterialStreamControl persistedCtrl = (MaterialStreamControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); DryingMaterialStream stream = flowsheet.EvaporationAndDryingSystem.GetMaterialStream(solvableName); MaterialStreamControl newCtrl = new MaterialStreamControl(flowsheet, new Point(0, 0), stream); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is DryerControl) { DryerControl persistedCtrl = (DryerControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Dryer uo = flowsheet.EvaporationAndDryingSystem.GetDryer(solvableName); DryerControl newCtrl = new DryerControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is HeatExchangerControl) { HeatExchangerControl persistedCtrl = (HeatExchangerControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); HeatExchanger uo = flowsheet.EvaporationAndDryingSystem.GetHeatExchanger(solvableName); HeatExchangerControl newCtrl = new HeatExchangerControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is CycloneControl) { CycloneControl persistedCtrl = (CycloneControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Cyclone uo = flowsheet.EvaporationAndDryingSystem.GetCyclone(solvableName); CycloneControl newCtrl = new CycloneControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is EjectorControl) { EjectorControl persistedCtrl = (EjectorControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Ejector uo = flowsheet.EvaporationAndDryingSystem.GetEjector(solvableName); EjectorControl newCtrl = new EjectorControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is WetScrubberControl) { WetScrubberControl persistedCtrl = (WetScrubberControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); WetScrubber uo = flowsheet.EvaporationAndDryingSystem.GetWetScrubber(solvableName); WetScrubberControl newCtrl = new WetScrubberControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is ScrubberCondenserControl) { ScrubberCondenserControl persistedCtrl = (ScrubberCondenserControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); ScrubberCondenser uo = flowsheet.EvaporationAndDryingSystem.GetScrubberCondenser(solvableName); ScrubberCondenserControl newCtrl = new ScrubberCondenserControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is MixerControl) { MixerControl persistedCtrl = (MixerControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Mixer uo = flowsheet.EvaporationAndDryingSystem.GetMixer(solvableName); MixerControl newCtrl = new MixerControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is TeeControl) { TeeControl persistedCtrl = (TeeControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Tee uo = flowsheet.EvaporationAndDryingSystem.GetTee(solvableName); TeeControl newCtrl = new TeeControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is FlashTankControl) { FlashTankControl persistedCtrl = (FlashTankControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); FlashTank uo = flowsheet.EvaporationAndDryingSystem.GetFlashTank(solvableName); FlashTankControl newCtrl = new FlashTankControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is FanControl) { FanControl persistedCtrl = (FanControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Fan uo = flowsheet.EvaporationAndDryingSystem.GetFan(solvableName); FanControl newCtrl = new FanControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is ValveControl) { ValveControl persistedCtrl = (ValveControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Valve uo = flowsheet.EvaporationAndDryingSystem.GetValve(solvableName); ValveControl newCtrl = new ValveControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is BagFilterControl) { BagFilterControl persistedCtrl = (BagFilterControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); BagFilter uo = flowsheet.EvaporationAndDryingSystem.GetBagFilter(solvableName); BagFilterControl newCtrl = new BagFilterControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is AirFilterControl) { AirFilterControl persistedCtrl = (AirFilterControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); AirFilter uo = flowsheet.EvaporationAndDryingSystem.GetAirFilter(solvableName); AirFilterControl newCtrl = new AirFilterControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is CompressorControl) { CompressorControl persistedCtrl = (CompressorControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Compressor uo = flowsheet.EvaporationAndDryingSystem.GetCompressor(solvableName); CompressorControl newCtrl = new CompressorControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is HeaterControl) { HeaterControl persistedCtrl = (HeaterControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Heater uo = flowsheet.EvaporationAndDryingSystem.GetHeater(solvableName); HeaterControl newCtrl = new HeaterControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is CoolerControl) { CoolerControl persistedCtrl = (CoolerControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Cooler uo = flowsheet.EvaporationAndDryingSystem.GetCooler(solvableName); CoolerControl newCtrl = new CoolerControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is ElectrostaticPrecipitatorControl) { ElectrostaticPrecipitatorControl persistedCtrl = (ElectrostaticPrecipitatorControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); ElectrostaticPrecipitator uo = flowsheet.EvaporationAndDryingSystem.GetElectrostaticPrecipitator(solvableName); ElectrostaticPrecipitatorControl newCtrl = new ElectrostaticPrecipitatorControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is PumpControl) { PumpControl persistedCtrl = (PumpControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Pump uo = flowsheet.EvaporationAndDryingSystem.GetPump(solvableName); PumpControl newCtrl = new PumpControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is RecycleControl) { RecycleControl persistedCtrl = (RecycleControl)obj; string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string)); Recycle uo = flowsheet.EvaporationAndDryingSystem.GetRecycle(solvableName); RecycleControl newCtrl = new RecycleControl(flowsheet, new Point(0, 0), uo); newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext); flowsheet.Controls.Add(newCtrl); } else if (obj is SolvableConnection) { SolvableConnection persistedDc = (SolvableConnection)obj; SolvableConnection dc = new SolvableConnection(flowsheet); dc.SetObjectData(persistedDc.SerializationInfo, persistedDc.StreamingContext); dc.UpdateConnection(); flowsheet.ConnectionManager.AddConnection(dc); } else if (obj is FlowsheetPreferences) { FlowsheetPreferences flowsheetPrefs = obj as FlowsheetPreferences; flowsheetPrefs.SetObjectData(flowsheetPrefs.SerializationInfo, flowsheetPrefs.StreamingContext); flowsheet.BackColor = flowsheetPrefs.BackColor; } else if (obj is ProsimoUI.CustomEditor.CustomEditor) { ProsimoUI.CustomEditor.CustomEditor persistedEditor = (ProsimoUI.CustomEditor.CustomEditor)obj; flowsheet.CustomEditor.SetObjectData(persistedEditor.SerializationInfo, persistedEditor.StreamingContext); } else if (obj is FlowsheetVersion) { flowsheetVersion = obj as FlowsheetVersion; flowsheetVersion.SetObjectData(flowsheetVersion.SerializationInfo, flowsheetVersion.StreamingContext); } } if (flowsheetVersion != null) { flowsheet.Version = flowsheetVersion; } FlowsheetVersionStatus flowsheetVersionStatus = CheckFlowsheetVersion(flowsheet); if (flowsheetVersionStatus == FlowsheetVersionStatus.Ok) { flowsheet.IsDirty = false; } else if (flowsheetVersionStatus == FlowsheetVersionStatus.Upgraded) { flowsheet.IsDirty = true; } else if (flowsheetVersionStatus == FlowsheetVersionStatus.NotOk) { flowsheet = null; } return(flowsheet); }
/// <summary> /// 关闭并释放资源 /// </summary> public void Close() { if (m_pWaveIn != null) { m_pWaveIn.Stop(); m_pWaveIn.Dispose(); } trackBarIn.Dispose(); trackBarIn= null; trackBarOut.Dispose(); trackBarOut = null; mixerF.Close(); mixerF = null; if (outdtl != null) outdtl = null; if (indtl != null) indtl = null; }
/// <summary> /// This is the timestepping procedure /// </summary> /// <param name="TimeStep"></param> public void Update(DateTime NewTime) { CurrentTimeStep = NewTime.Subtract(CurrentTime); #region Sum of Sinks and sources //Sum the sources var GWFlow = GroundwaterBoundaries.Where(var => var.IsSource(CurrentTime)).Select(var => var.GetSourceWater(CurrentTime, CurrentTimeStep)); var SourceFlow = Sources.Select(var => var.GetSourceWater(CurrentTime, CurrentTimeStep)); IWaterPacket InFlow = WaterMixer.Mix(GWFlow.Concat(SourceFlow)); double InflowVolume = 0; if (InFlow != null) { InflowVolume = InFlow.Volume; } //Sum the Evaporation boundaries double EvapoVolume = _evapoBoundaries.Sum(var => var.GetSinkVolume(CurrentTime, CurrentTimeStep)); //Sum the sinks double SinkVolume = Sinks.Sum(var => var.GetSinkVolume(CurrentTime, CurrentTimeStep)); //Add the sinking groundwater boundaries SinkVolume += GroundwaterBoundaries.Where(var => !var.IsSource(CurrentTime)).Sum(var => var.GetSinkVolume(CurrentTime, CurrentTimeStep)); double sumSinkSources = InflowVolume - EvapoVolume - SinkVolume; //If we have no water from upstream but Inflow, remove water from inflow to fill stream if (sumSinkSources / Volume > 5) { AddWaterPacket(CurrentTime, NewTime, InFlow.Substract(sumSinkSources - Volume * 5)); InflowVolume = InFlow.Volume; sumSinkSources = InflowVolume - EvapoVolume - SinkVolume; } //Sort the incoming water an put in to queue PrePareIncomingWater(); //Calculate the surplus WaterToRoute = _waterInStream.Sum(var => var.Volume) + InflowVolume - EvapoVolume - SinkVolume - Volume + _incomingWater.Sum(var => var.Volume); //If the loss is bigger than available water, reduce Evaporation and Sinks if (WaterToRoute + Volume < 0) { double reductionfactor = 1 + (WaterToRoute + Volume) / (EvapoVolume + SinkVolume); EvapoVolume *= reductionfactor; SinkVolume *= reductionfactor; WaterToRoute = 0; } //Convert to rates double qu = sumSinkSources / CurrentTimeStep.TotalSeconds / Volume; double qop = _incomingWater.Sum(var => var.Volume) / CurrentTimeStep.TotalSeconds; double qout = qu * Volume + qop; //Create a mixer class Mixer M = new Mixer(InFlow, EvapoVolume, SinkVolume); #endregion #region Stored water //Send stored water out if (WaterToRoute > 0) { double OutflowTime = 0; //The volume that needs to flow out to meet the watertotroute double VToSend = WaterToRoute; if (qu != 0) { VToSend = qout / qu * (1 - 1 / (Math.Exp(qu * CurrentTimeStep.TotalSeconds))); } //There is water in the stream that should be routed while (VToSend > 0 & _waterInStream.Count > 0) { IWaterPacket IW; //Mixing during flow towards end of stream double dv = _waterInStream.Peek().Volume *(Math.Exp(qu * OutflowTime) - 1); //Check if the entire water packet should flow out or it should be split if (_waterInStream.Peek().Volume + dv < VToSend) { IW = _waterInStream.Dequeue(); } else { IW = _waterInStream.Peek().Substract(VToSend); } //Update how mush water is yet to be routed VToSend -= IW.Volume; //Now do the mix M.Mix(dv, IW); //Calculate outflow time double dt; if (qu == 0) { dt = IW.Volume / qop; } else { dt = Math.Log(qout / (qout - qu * IW.Volume)) / qu; } //Mixing during outflow M.Mix(qout * dt - IW.Volume, IW); IW.MoveInTime(TimeSpan.FromSeconds(OutflowTime + dt / 2), IW.Volume / Depth); SendWaterDownstream(IW); OutflowTime += dt; } } //Now move the remaining packets to their final destination and time foreach (IWaterPacket IWP in _waterInStream) { if (qu != 0) { M.Mix(IWP.Volume * (Math.Exp(qu * CurrentTimeStep.TotalSeconds) - 1), IWP); } IWP.MoveInTime(CurrentTimeStep, IWP.Volume / Depth); } #endregion #region Water packets traveling right through double inflowtime = 0; //No water in stream and incoming water. Just pass through if (_waterInStream.Count == 0 & _incomingWater.Count > 0) { //Calculate how much incoming water is required to fill stream volume; double VToStore = Volume; if (qu != 0) { VToStore = qop / qu * Math.Log(Volume * qu / qop + 1); } //Now send water through double incomingVolume = _incomingWater.Sum(var => var.Volume); //Send packets through until the remaining will just fill the stream while (incomingVolume > VToStore + 1e-12 & _incomingWater.Count != 0) { IWaterPacket WP; if (incomingVolume - _incomingWater.Peek().Volume > VToStore) { WP = _incomingWater.Dequeue(); } else { WP = _incomingWater.Peek().Substract(incomingVolume - VToStore); } incomingVolume -= WP.Volume; //Keep track of inflow time. inflowtime += WP.Volume / qop; if (qu != 0) { double dvr = WP.Volume * qu * Volume / qop; M.Mix(dvr, WP); } //Calculate the time a water package uses to travel through the stream TimeSpan CurrentTravelTime; if (qu != 0) { CurrentTravelTime = TimeSpan.FromSeconds(1 / qu * Math.Log(Volume * qu / qop + 1)); } else { CurrentTravelTime = TimeSpan.FromSeconds(Volume / qout); } //Moves right through WP.MoveInTime(CurrentTravelTime, WP.Volume / Depth); SendWaterDownstream(WP); } } #endregion #region Fill the stream //The remaining incoming water is moved forward and stays in the stream. while (_incomingWater.Count > 0) { IWaterPacket WP = _incomingWater.Dequeue(); double dt = WP.Volume / qop; inflowtime += dt; double dt2 = CurrentTimeStep.TotalSeconds - inflowtime; //How much of the timestep is left when this packet has moved in. if (qu != 0) { //Volume change during inflow double Vnew = qop * (Math.Exp(qu * dt) - 1) / qu; //Volume change while in stream Vnew *= Math.Exp(qu * dt2); M.Mix(Vnew - WP.Volume, WP); } //The time is half the inflowtime + the time in stream WP.MoveInTime(TimeSpan.FromSeconds(dt2 + dt / 2), WP.Volume / Depth); _waterInStream.Enqueue(WP); } #endregion Output.Outflow.AddSiValue(CurrentTime, NewTime, WaterToRoute / CurrentTimeStep.TotalSeconds); CurrentTime = NewTime; StartofFlowperiod = CurrentTime; }
static void Main(string[] args) { try { var settings = new Settings(); // ReSharper disable once RedundantNameQualifier using (var parser = new CommandLine.Parser(x => { x.CaseSensitive = false; x.IgnoreUnknownArguments = true; })) { if (!parser.ParseArguments(args, settings)) { Console.Error.WriteLine(settings.GetUsage()); return; } } if (!settings.YouTubeOnly) { if (settings.InputFiles == null) { RunMultiDumper(ref settings); } else { // We want to expand any wildcards in the input file list (and also fully qualify them) var inputs = new List <string>(); foreach (var inputFile in settings.InputFiles) { if (File.Exists(inputFile)) { inputs.Add(Path.GetFullPath(inputFile)); continue; } var pattern = Path.GetFileName(inputFile); if (pattern == null) { throw new Exception($"Failed to match {inputFile}"); } var pathPart = inputFile.Substring(0, inputFile.Length - pattern.Length); var directory = pathPart.Length > 0 ? Path.GetFullPath(pathPart) : Directory.GetCurrentDirectory(); var files = Directory.EnumerateFiles(directory, pattern).ToList(); if (files.Count == 0) { throw new Exception($"Failed to match {inputFile}"); } inputs.AddRange(files.OrderByAlphaNumeric(x => x)); } settings.InputFiles = inputs; } if (settings.InputFiles == null || !settings.InputFiles.Any()) { Console.Error.WriteLine(settings.GetUsage()); throw new Exception("No inputs specified"); } var channels = settings.InputFiles .AsParallel() .Select(filename => { var channel = new Channel { Filename = filename, LineColor = ParseColor(settings.LineColor), LineWidth = settings.LineWidth, FillColor = ParseColor(settings.FillColor), Label = Channel.GuessNameFromMultidumperFilename(filename), Algorithm = CreateTriggerAlgorithm(settings.TriggerAlgorithm), TriggerLookaheadFrames = settings.TriggerLookahead, ZeroLineWidth = settings.ZeroLineWidth, ZeroLineColor = ParseColor(settings.ZeroLineColor), LabelFont = settings.ChannelLabelsFont == null ? null : new Font(settings.ChannelLabelsFont, settings.ChannelLabelsSize), LabelColor = ParseColor(settings.ChannelLabelsColor) }; channel.LoadDataAsync().Wait(); channel.ViewWidthInMilliseconds = settings.ViewWidthMs; return(channel); }).Where(ch => ch.SampleCount > 0).ToList(); if (settings.AutoScalePercentage > 0) { float max; bool IsYm2413Percussion(Channel ch) => ch.Label.StartsWith("YM2413 ") && !ch.Label.StartsWith("YM2413 Tone"); if (settings.AutoScaleIgnoreYM2413Percussion) { var channelsToUse = channels.Where(channel => !IsYm2413Percussion(channel)).ToList(); if (channelsToUse.Count == 0) { // Fall back on overall max if all channels are percussion max = channels.Max(ch => ch.Max); } else { max = channelsToUse.Max(ch => ch.Max); } } else { max = channels.Max(ch => ch.Max); } var scale = settings.AutoScalePercentage / 100 / max; foreach (var channel in channels) { channel.Scale = scale; } } if (settings.ChannelLabelsFromVgm && settings.VgmFile != null) { TryGuessLabelsFromVgm(channels, settings.VgmFile); } if (settings.OutputFile != null) { // Emit normalized data to a WAV file for later mixing if (settings.MasterAudioFile == null && !settings.NoMasterMix) { settings.MasterAudioFile = settings.OutputFile + ".wav"; Mixer.MixToFile(channels, settings.MasterAudioFile, !settings.NoMasterMixReplayGain); } } Render(settings, channels); foreach (var channel in channels) { channel.Dispose(); } } if (settings.YouTubeTitle != null) { UploadToYouTube(settings).Wait(); } } catch (Exception e) { Console.Error.WriteLine($"Fatal: {e}"); } }
/// <summary> /// _accepts the only a 'Mixer' typed instance /// </summary> private void _acceptOnlyAMixer(Mixer aMixer) { Debug.Log(" _acceptOnlyAMixer: " + aMixer); }
private void UpdateUI() { this.panel.Visible = false; this.groupBox.Visible = false; this.groupBox.Controls.Clear(); this.inletControls.Clear(); int x = INITIAL_LOCATION; int w = VALUE_WIDTH; int s = INITIAL_GROUPBOX_WIDTH; int p = INITIAL_FORM_WIDTH; Mixer mixer = this.MixerCtrl.Mixer; bool hasStreamIn = false; bool hasStreamOut = false; ProcessStreamBase streamIn = null; if (mixer.InletStreams.Count > 0) { hasStreamIn = true; streamIn = (ProcessStreamBase)mixer.InletStreams[0]; } ProcessStreamBase streamOut = mixer.Outlet; if (streamOut != null) { hasStreamOut = true; } if (hasStreamIn || hasStreamOut) { this.groupBox.Visible = true; ProcessStreamBase labelsStream = null; if (hasStreamIn) { labelsStream = streamIn; } else if (hasStreamOut) { labelsStream = streamOut; } UserControl ctrl = null; if (labelsStream is ProcessStream) { ctrl = new ProcessStreamLabelsControl((ProcessStream)labelsStream); } else if (labelsStream is DryingGasStream) { ctrl = new GasStreamLabelsControl((DryingGasStream)labelsStream); } else if (labelsStream is DryingMaterialStream) { ctrl = new MaterialStreamLabelsControl((DryingMaterialStream)labelsStream); } ctrl.Location = new Point(4, 12 + 20 + 2); this.groupBox.Size = new Size(s, this.groupBoxHeight); this.groupBox.Controls.Add(ctrl); this.Size = new Size(p, this.formHeight); s = s + w; p = p + w; } if (hasStreamIn) { IEnumerator e = mixer.InletStreams.GetEnumerator(); while (e.MoveNext()) { ProcessStreamBase processStreamBase = (ProcessStreamBase)e.Current; UserControl ctrl = null; if (processStreamBase is ProcessStream) { ProcessStreamControl processInCtrl = (ProcessStreamControl)this.MixerCtrl.Flowsheet.StreamManager.GetProcessStreamBaseControl(processStreamBase.Name); ctrl = new ProcessStreamValuesControl(processInCtrl); } else if (processStreamBase is DryingGasStream) { GasStreamControl gasInCtrl = (GasStreamControl)this.MixerCtrl.Flowsheet.StreamManager.GetProcessStreamBaseControl(processStreamBase.Name); ctrl = new GasStreamValuesControl(gasInCtrl); } else if (processStreamBase is DryingMaterialStream) { MaterialStreamControl materialInCtrl = (MaterialStreamControl)this.MixerCtrl.Flowsheet.StreamManager.GetProcessStreamBaseControl(processStreamBase.Name); ctrl = new MaterialStreamValuesControl(materialInCtrl); } ctrl.Location = new Point(x, 12 + 20 + 2); this.groupBox.Size = new Size(s, this.groupBoxHeight); this.groupBox.Controls.Add(ctrl); this.Size = new Size(p, this.formHeight); ProsimoUI.SolvableNameTextBox textBoxStreamInName = new ProsimoUI.SolvableNameTextBox(processStreamBase); textBoxStreamInName.Width = 80; textBoxStreamInName.Height = 20; textBoxStreamInName.Text = processStreamBase.Name; textBoxStreamInName.Location = new Point(x, 12); this.inletControls.Add(textBoxStreamInName, textBoxStreamInName.Text); this.groupBox.Controls.Add(textBoxStreamInName); UI.SetStatusColor(textBoxStreamInName, processStreamBase.SolveState); s = s + w; x = x + w; p = p + w; } } if (hasStreamOut) { UserControl ctrl = null; if (streamOut is ProcessStream) { ProcessStreamControl processOutCtrl = (ProcessStreamControl)this.MixerCtrl.Flowsheet.StreamManager.GetProcessStreamBaseControl(streamOut.Name); ctrl = new ProcessStreamValuesControl(processOutCtrl); } else if (streamOut is DryingGasStream) { GasStreamControl gasOutCtrl = (GasStreamControl)this.MixerCtrl.Flowsheet.StreamManager.GetProcessStreamBaseControl(streamOut.Name); ctrl = new GasStreamValuesControl(gasOutCtrl); } else if (streamOut is DryingMaterialStream) { MaterialStreamControl materialOutCtrl = (MaterialStreamControl)this.MixerCtrl.Flowsheet.StreamManager.GetProcessStreamBaseControl(streamOut.Name); ctrl = new MaterialStreamValuesControl(materialOutCtrl); } ctrl.Location = new Point(x, 12 + 20 + 2); this.groupBox.Size = new Size(s, this.groupBoxHeight); this.groupBox.Controls.Add(ctrl); this.Size = new Size(p, this.formHeight); textBoxStreamOutName.Text = streamOut.Name; textBoxStreamOutName.Location = new Point(x, 12); this.textBoxStreamOutName.SetSolvable(streamOut); this.groupBox.Controls.Add(this.textBoxStreamOutName); UI.SetStatusColor(this.textBoxStreamOutName, streamOut.SolveState); } this.panel.Visible = true; }
private static void mixer_ControlChanged(object sender, Mixer.MixerEventArgs e) { Instance.HandleGUIOnControlChange(); }
public void SetUp() { _mixer = new Mixer(); }
static void Main(string[] args) { SDL.Init(InitFlags.Everything); Log.Priorities.SetAll(LogPriority.Verbose); Log.OutputFunction = (cat, prio, msg) => { Console.WriteLine($"[{prio}] {cat}: {msg}"); }; Log.Message(LogCategory.Application, LogPriority.Debug, "Foo and bar!?"); TTF.Init(); Events.Watch += (ref Event e) => { //Console.WriteLine(e.ToString()); }; Console.WriteLine("Registering timer"); int callbackCount = 0; IDisposable?d = null; d = SDLSharp.Timer.AddTimer(500, n => { Console.WriteLine($"{n}: Timer callback {callbackCount++}"); if (callbackCount > 4 && d != null) { Console.WriteLine("I've had it with this callback business!"); d.Dispose(); } return(500 * (uint)callbackCount); }); Console.WriteLine($"{d} registered"); Console.WriteLine("Ok, here we go:"); Console.WriteLine($"Running SDL version {SDL.RuntimeVersion} {SDL.RuntimeRevision} {SDL.RuntimeRevisionNumber}"); Console.WriteLine($"\tSDL_image version {Image.RuntimeVersion}"); Console.WriteLine($"\tSDL_ttf version {TTF.RuntimeVersion}"); Console.WriteLine($"Video drivers: {string.Join("; ", Video.Drivers)}"); Console.WriteLine($"Audio drivers: {string.Join("; ", Audio.Drivers)}"); Console.WriteLine($"Audio input devices: {string.Join("; ", Audio.InputDevices)}"); Console.WriteLine($"Audio output devices: {string.Join("; ", Audio.InputDevices)}"); if (Clipboard.HasText()) { Console.Write("Clipboard contains: "); Console.WriteLine(Clipboard.GetText()); } else { Console.Write("Clipboard is empty. An empty string looks like: "); Console.WriteLine(Clipboard.GetText()); } foreach (var display in Video.Displays) { Console.WriteLine($"Display {display.Index}"); Console.WriteLine($" Name={display.Name}"); Console.WriteLine($" Bounds={display.Bounds}"); Console.WriteLine($" UsableBounds={display.UsableBounds}"); Console.WriteLine($" DPI={display.DPI}"); Console.WriteLine($" Modes.Current={display.Modes.Current}"); Console.WriteLine($" Modes.Desktop={display.Modes.Desktop}"); for (int i = 0; i < display.Modes.Count; ++i) { Console.WriteLine($" Modes.[{i}]={display.Modes[i]}"); } } for (int i = 0; i < Renderer.Drivers.Count; ++i) { var ri = Renderer.Drivers[i]; Console.WriteLine($"Render driver {i}"); Console.WriteLine($" Name={ri.Name}"); Console.WriteLine($" Flags={ri.Flags}"); Console.WriteLine($" MaxTextureWidth={ri.MaxTextureWidth}"); Console.WriteLine($" MaxTextureHeight={ri.MaxTextureHeight}"); for (int j = 0; j < ri.Formats.Count; ++j) { Console.WriteLine($" Formats.[{j}]={PixelFormat.GetName(ri.Formats[j])}"); } } foreach (var joy in Joystick.Devices) { Console.WriteLine($"{joy}"); Console.WriteLine($"\tGuid={joy.Guid}"); Console.WriteLine($"\tName={joy.Name}"); Console.WriteLine($"\tIsController={joy.IsController}"); using (var j = joy.Open()) { Console.WriteLine($"\t\tOpened {j}"); Console.WriteLine($"\t\tID={j.ID}"); Console.WriteLine($"\t\tName={j.Name}"); Console.WriteLine($"\t\tGuid={j.Guid}"); Console.WriteLine($"\t\tPowerLevel={j.PowerLevel}"); Console.WriteLine($"\t\tNumAxes={j.Axes.Count}"); Console.WriteLine($"\t\tButtons={j.Buttons.Count}"); Console.WriteLine($"\t\tHats={j.Hats.Count}"); Console.WriteLine($"\t\tBalls={j.Balls.Count}"); } if (joy.IsController) { using (var c = joy.OpenController()) { foreach (var axis in Enum.GetValues(typeof(GameControllerAxis)).Cast <GameControllerAxis>()) { if (axis == GameControllerAxis.Invalid || axis == GameControllerAxis.Max) { continue; } var b = c.Axes.GetBind(axis); Console.WriteLine($"\t\tAxis[{axis}/{GameController.AxisName(axis)}].Bind={b}"); } foreach (var btn in Enum.GetValues(typeof(GameControllerButton)).Cast <GameControllerButton>()) { if (btn == GameControllerButton.Invalid || btn == GameControllerButton.Max) { continue; } var b = c.Buttons.GetBind(btn); Console.WriteLine($"\t\tButtons[{btn}/{GameController.ButtonName(btn)}].Bind={b}"); } Console.WriteLine($"\t\tMapping={c.Mapping}"); } } } foreach (var dev in Audio.OutputDevices) { var fmt = new AudioStreamFormat(44000, AudioDataFormat.Float32Bit, 1, 0, 1024); var changes = AllowedAudioStreamChange.Any; Console.Write($"Requesting {fmt} from audio output '{dev}' allowing changes to {changes}..."); try { using (var a = Audio.OpenOutput(dev, changes, fmt, out var obtained)) { Console.WriteLine($"\tgot {obtained}"); } } catch (Exception ex) { Console.WriteLine($"\tFailed w/ error: {ex}"); } } foreach (var dev in Audio.InputDevices) { var fmt = new AudioStreamFormat(44000, AudioDataFormat.Float32Bit, 1, 0, 1024); var changes = AllowedAudioStreamChange.Any; Console.Write($"Requesting {fmt} from audio input '{dev}' allowing changes to {changes}..."); try { using (var a = Audio.OpenInput(dev, changes, fmt, out var obtained)) { Console.WriteLine($"\tgot {a} with format {obtained}"); } } catch (Exception ex) { Console.WriteLine($"\tFailed w/ error: {ex}"); } } Mixer.Open(44100, AudioDataFormat.Float32Bit, 2, 1024); Mixer.Init(MixerLoaders.MP3); Console.WriteLine($"Opened the mixer hz={Mixer.DeviceFrequency} f={Mixer.DeviceFormat} ch={Mixer.DeviceChannels}"); Console.WriteLine($"\tAvailable music decoders {string.Join("; ", MusicTrack.Decoders)}"); Console.WriteLine($"\tAvailable chunk decoders {string.Join("; ", MixerChunk.Decoders)}"); PrintChannels(); Mixer.Channels.Count = 8; PrintChannels(); using var caketown = MusicTrack.Load("./assets/Caketown 1.mp3"); Console.WriteLine($"Loaded {caketown}"); Task.Run(async() => { Mixer.Music.Play(caketown); Mixer.Music.Finished += (se, ev) => Console.WriteLine("Music finished"); await Task.Delay(1000); Mixer.Music.Pause(); Console.WriteLine($"{caketown} paused"); await Task.Delay(1000); Mixer.Music.Resume(); Console.WriteLine($"{caketown} resumed"); await Task.Delay(1000); Mixer.Music.Rewind(); Console.WriteLine($"{caketown} rewound"); await Task.Delay(1000); Console.WriteLine($"{caketown} fading out"); Mixer.Music.FadeOut(1000); Console.WriteLine($"{caketown} faded out"); Mixer.Music.Halt(); Console.WriteLine($"{caketown} halted"); }); using var alarm = MixerChunk.Load("./assets/wobbleboxx.com/Rise01.wav"); var flags = WindowFlags.Shown | WindowFlags.Resizable; using (var window = Video.CreateWindow("Foo änd bar", Window.UndefinedPosition, Window.UndefinedPosition, 600, 400, flags)) using (var renderer = Renderer.Create(window, -1, RendererFlags.Accelerated)) { Console.WriteLine($"Created window {window}"); Mixer.Channels.ChannelFinished += (se, ev) => Console.WriteLine($"{ev.Channel} finished"); window.SetHitTest((Window w, in SDLSharp.Point p) => { Console.WriteLine($"Hit test at {(System.Drawing.Point)p} in window '{w}'"); Events.Current.Push((Action)(() => { if (Mixer.Channels.Play(alarm, 1)) { Console.Write("Playing sound "); } else { Console.Write("NOT playing sound "); } PrintChannels(); })); return(HitTestResult.Normal); });
private static void mixer_ControlChanged(object sender, Mixer.MixerEventArgs e) { Instance.HandleGUIOnControlChange(); GUIGraphicsContext.VolumeOverlay = true; GUIGraphicsContext.VolumeOverlayTimeOut = DateTime.Now; Instance.UpdateVolumeProperties(); }
public void ChildHasBaseClassWithBaseClassesWithProperty_Include_PropertyNotReimplemented() { // arrange var sourceCode = new SourceCode(Files.Person, Files.Name); var personClass = sourceCode.Class(nameof(ThirdPersonClass)); var mixinReference = personClass.FindMixinReference("_name"); var semanticModel = sourceCode.Semantic; var mixin = new MixinReferenceFactory(semanticModel).Create(mixinReference); var child = new ClassFactory(semanticModel).Create(personClass); // act var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); // nothing to implement for the mixer, child already has property Assert.IsEmpty(mixer.PropertiesToImplement); }
public void ChildHasInterfaceWithProperty_Include_PropertyImplemented() { // arrange var sourceCode = new SourceCode(Files.NotCompilable, Files.Name); var personClass = sourceCode.Class("DerivedFromInterfaceClass"); var mixinReference = personClass.FindMixinReference("_name"); var semanticModel = sourceCode.Semantic; var mixin = new MixinReferenceFactory(semanticModel).Create(mixinReference); var child = new ClassFactory(semanticModel).Create(personClass); // act var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); // assert: Child should have one "Name" property Assert.AreEqual(1, mixer.PropertiesToImplement.Count(x => x.Name == "Name")); // this one property should have only getter (signature from interface and mixin is the same) Assert.IsTrue(mixer.PropertiesToImplement.Single(x => x.Name == "Name").IsReadOnly); }
public void MixinWithStaticProperty_Include_PropertyNotImplemented() { // arrange var sourceCode = new SourceCode(Files.Person, Files.Name); var personClass = sourceCode.Class(nameof(PersonWithStaticMixin)); var mixinReference = personClass.FindMixinReference("_name"); var semanticModel = sourceCode.Semantic; var mixin = new MixinReferenceFactory(semanticModel).Create(mixinReference); var child = new ClassFactory(semanticModel).Create(personClass); // act var mixer = new Mixer(); mixer.IncludeMixinInChild(mixin, child); // assert: Child should not have a "Name" property Assert.IsEmpty(mixer.PropertiesToImplement); }
/// <summary> /// This is the timestepping procedure /// </summary> /// <param name="TimeStep"></param> public void Update(DateTime NewTime) { CurrentTimeStep = NewTime.Subtract(CurrentTime); #region Sum of Sinks and sources //Sum the sources var GWFlow = GroundwaterBoundaries.Where(var => var.IsSource(CurrentTime)).Select(var => var.GetSourceWater(CurrentTime, CurrentTimeStep)); var SourceFlow = Sources.Select(var => var.GetSourceWater(CurrentTime, CurrentTimeStep)); IWaterPacket InFlow = WaterMixer.Mix(GWFlow.Concat(SourceFlow)); double InflowVolume = 0; if (InFlow != null) InflowVolume = InFlow.Volume; //Sum the Evaporation boundaries double EvapoVolume = _evapoBoundaries.Sum(var => var.GetSinkVolume(CurrentTime, CurrentTimeStep)); //Sum the sinks double SinkVolume = Sinks.Sum(var => var.GetSinkVolume(CurrentTime, CurrentTimeStep)); //Add the sinking groundwater boundaries SinkVolume += GroundwaterBoundaries.Where(var => !var.IsSource(CurrentTime)).Sum(var => var.GetSinkVolume(CurrentTime, CurrentTimeStep)); double sumSinkSources = InflowVolume - EvapoVolume - SinkVolume; //If we have no water from upstream but Inflow, remove water from inflow to fill stream if (sumSinkSources / Volume > 5) { AddWaterPacket(CurrentTime, NewTime, InFlow.Substract(sumSinkSources - Volume * 5)); InflowVolume = InFlow.Volume; sumSinkSources = InflowVolume - EvapoVolume - SinkVolume; } //Sort the incoming water an put in to queue PrePareIncomingWater(); //Calculate the surplus WaterToRoute = _waterInStream.Sum(var => var.Volume) + InflowVolume - EvapoVolume - SinkVolume - Volume + _incomingWater.Sum(var => var.Volume); //If the loss is bigger than available water, reduce Evaporation and Sinks if (WaterToRoute + Volume < 0) { double reductionfactor = 1 + (WaterToRoute + Volume) / (EvapoVolume + SinkVolume); EvapoVolume *= reductionfactor; SinkVolume *= reductionfactor; WaterToRoute = 0; } //Convert to rates double qu = sumSinkSources / CurrentTimeStep.TotalSeconds / Volume; double qop = _incomingWater.Sum(var => var.Volume) / CurrentTimeStep.TotalSeconds; double qout = qu * Volume + qop; //Create a mixer class Mixer M = new Mixer(InFlow, EvapoVolume, SinkVolume); #endregion #region Stored water //Send stored water out if (WaterToRoute > 0) { double OutflowTime = 0; //The volume that needs to flow out to meet the watertotroute double VToSend = WaterToRoute; if (qu != 0) { VToSend = qout / qu * (1 - 1 / (Math.Exp(qu * CurrentTimeStep.TotalSeconds))); } //There is water in the stream that should be routed while (VToSend > 0 & _waterInStream.Count > 0) { IWaterPacket IW; //Mixing during flow towards end of stream double dv = _waterInStream.Peek().Volume * (Math.Exp(qu * OutflowTime) - 1); //Check if the entire water packet should flow out or it should be split if (_waterInStream.Peek().Volume + dv < VToSend) IW = _waterInStream.Dequeue(); else IW = _waterInStream.Peek().Substract(VToSend); //Update how mush water is yet to be routed VToSend -= IW.Volume; //Now do the mix M.Mix(dv, IW); //Calculate outflow time double dt; if (qu == 0) dt = IW.Volume / qop; else { dt = Math.Log(qout / (qout - qu * IW.Volume)) / qu; } //Mixing during outflow M.Mix(qout * dt - IW.Volume, IW); IW.MoveInTime(TimeSpan.FromSeconds(OutflowTime + dt / 2), IW.Volume/Depth); SendWaterDownstream(IW); OutflowTime += dt; } } //Now move the remaining packets to their final destination and time foreach (IWaterPacket IWP in _waterInStream) { if (qu != 0) M.Mix(IWP.Volume * (Math.Exp(qu * CurrentTimeStep.TotalSeconds) - 1), IWP); IWP.MoveInTime(CurrentTimeStep, IWP.Volume / Depth); } #endregion #region Water packets traveling right through double inflowtime = 0; //No water in stream and incoming water. Just pass through if (_waterInStream.Count == 0 & _incomingWater.Count > 0) { //Calculate how much incoming water is required to fill stream volume; double VToStore = Volume; if (qu != 0) VToStore = qop / qu * Math.Log(Volume * qu / qop + 1); //Now send water through double incomingVolume = _incomingWater.Sum(var => var.Volume); //Send packets through until the remaining will just fill the stream while (incomingVolume > VToStore + 1e-12 & _incomingWater.Count != 0) { IWaterPacket WP; if (incomingVolume - _incomingWater.Peek().Volume > VToStore) WP = _incomingWater.Dequeue(); else WP = _incomingWater.Peek().Substract(incomingVolume - VToStore); incomingVolume -= WP.Volume; //Keep track of inflow time. inflowtime += WP.Volume / qop; if (qu != 0) { double dvr = WP.Volume * qu * Volume / qop; M.Mix(dvr, WP); } //Calculate the time a water package uses to travel through the stream TimeSpan CurrentTravelTime; if (qu != 0) CurrentTravelTime = TimeSpan.FromSeconds(1 / qu * Math.Log(Volume * qu / qop + 1)); else CurrentTravelTime = TimeSpan.FromSeconds(Volume / qout); //Moves right through WP.MoveInTime(CurrentTravelTime, WP.Volume / Depth); SendWaterDownstream(WP); } } #endregion #region Fill the stream //The remaining incoming water is moved forward and stays in the stream. while (_incomingWater.Count > 0) { IWaterPacket WP = _incomingWater.Dequeue(); double dt = WP.Volume / qop; inflowtime += dt; double dt2 = CurrentTimeStep.TotalSeconds - inflowtime; //How much of the timestep is left when this packet has moved in. if (qu != 0) { //Volume change during inflow double Vnew = qop * (Math.Exp(qu * dt) - 1) / qu; //Volume change while in stream Vnew *= Math.Exp(qu * dt2); M.Mix(Vnew - WP.Volume, WP); } //The time is half the inflowtime + the time in stream WP.MoveInTime(TimeSpan.FromSeconds(dt2 + dt / 2), WP.Volume / Depth); _waterInStream.Enqueue(WP); } #endregion Output.Outflow.AddSiValue(CurrentTime, NewTime, WaterToRoute / CurrentTimeStep.TotalSeconds); CurrentTime =NewTime; StartofFlowperiod = CurrentTime; }
/// <summary> /// Load the default DosBox configuration /// </summary> /// <returns>DosBoxConfiguration data</returns> public DosBoxConfiguration LoadDeafult() { SDL.AddAutoLock() .AddFullDouble() .AddFullResolution(Resolution.Original) .AddFullScreen() .AddOutput(VideoOutput.Surface) .AddPriorityFocused() .AddPriorityMinimized() .AddSensitivity() .AddUseScanCodes() .AddWaitOnError() .AddWindowResolution(Resolution.Original); DosBox.AddCaptures() .AddMachine() .AddMemSize(); Render.AddAspect() .AddFrameskip() .AddScaler(ScalerType.Normal2x); CPU.AddCore() .AddCPUType() .AddCycles(new CPUCycles("auto")) .AddCycleUp() .AddCycleDown(); Mixer.AddNoSound() .AddRate() .AddBlockSize() .AddPreBuffer(); Midi.AddMPU401() .AddMidiDevice(); SoundBlaster.AddSBType() .AddSBBase() .AddIRQ() .AddDMA() .AddHDMA() .AddSoundMixer() .AddOplMode() .AddOplEmu() .AddOplRate(); GUS.AddGUS() .AddGusRate() .AddGusBase() .AddGusIRQ() .AddGusDMA() .AddUltraDir(); Speaker.AddPCSpeaker() .AddPCRate() .AddTandy() .AddTandyRate() .AddDisney(); Joystick.AddJoystickType() .AddTimed() .AddAutoFire() .AddSwap34() .AddButtonWrap(); Serial.AddSerial1(Options.Serial.CreateDummy()) .AddSerial2(Options.Serial.CreateDummy()) .AddSerial3(Options.Serial.CreateDisabled()) .AddSerial4(Options.Serial.CreateDisabled()); DOS.AddXMS() .AddEMS() .AddUMB() .AddKeyboardLayout(KeyboardLayout.Auto); IPX.AddIPX(); return(this); }
/// <summary> /// _accepts the only a 'Mixer' typed instance /// </summary> private void _acceptOnlyAMixer (Mixer aMixer) { Debug.Log (" _acceptOnlyAMixer: " + aMixer); }
private void TryGetVolumeControl() { if (Wave == null) { return; } try { int waveInDeviceNumber = Wave.DeviceNumber; if (Environment.OSVersion.Version.Major >= 6) // Vista and over { var mixerLine = Wave.GetMixerLine(); foreach (var control in mixerLine.Controls) { Common.DebugHelper.WriteLine("{0} Mixer Line Control {1} [{2}]", mixerLine.Name, control.Name, control.ControlType); } foreach (var control in mixerLine.Controls) { if (control.ControlType == MixerControlType.Volume) { if (control.IsUnsigned) { try { this.volumeControl = control as UnsignedMixerControl; break; } catch { this.volumeControl = null; } } else if (control.IsSigned) { try { this.altVolumeControl = control as SignedMixerControl; } catch { this.altVolumeControl = null; } } } } } else { var mixer = new Mixer(waveInDeviceNumber); foreach (var destination in mixer.Destinations.Where(d => d.ComponentType == MixerLineComponentType.DestinationWaveIn)) { foreach (var source in destination.Sources .Where(source => source.ComponentType == MixerLineComponentType.SourceMicrophone)) { foreach (var control in source.Controls .Where(control => control.ControlType == MixerControlType.Volume)) { if (control.IsUnsigned) { try { volumeControl = control as UnsignedMixerControl; break; } catch { volumeControl = null; } } else if (control.IsSigned) { try { this.altVolumeControl = control as SignedMixerControl; } catch { this.altVolumeControl = null; } } } } } } } catch { volumeControl = null; altVolumeControl = null; } }