public void TestMultipatchConversionWithMultipleRings() { Rectangular[] positions = new[] { new Rectangular(0.0, 5.0), new Rectangular(5.0, 10.0), new Rectangular(10.0, 5.0), new Rectangular(5.0, 0.0), new Rectangular(0.0, 5.0), new Rectangular(2.0, 5.0), new Rectangular(5.0, 2.0), new Rectangular(8.0, 5.0), new Rectangular(5.0, 8.0), new Rectangular(2.0, 5.0) }; CartographicExtent extent = new CartographicExtent(0.0, 0.0, 10.0, 10.0); int[] parts = new[] { 0, 5 }; MultiPatchPartType[] partTypes = new[] { MultiPatchPartType.Ring, MultiPatchPartType.Ring }; double[] zValues = new[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; double[] measures = new[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; MultiPatchShape multipatch = new MultiPatchShape(0, m_metadata, extent, parts, partTypes, positions, 0.0, 0.0, zValues, 0.0, 0.0, measures); MultiPatch patch = new MultiPatch(multipatch, m_document, Color.Blue); patch.Write(); string result = m_stringWriter.ToString(); Regex polygonPattern = new Regex(m_polygonPattern); Assert.AreEqual(2, polygonPattern.Matches(result).Count); }
public void TestMultipatchConversionWithTriangleStrip() { Rectangular[] positions = new[] { new Rectangular(0.0, 0.0), new Rectangular(0.0, 1.0), new Rectangular(1.0, 0.0), new Rectangular(1.0, 1.0), new Rectangular(2.0, 0.0), new Rectangular(2.0, 1.0), new Rectangular(3.0, 0.0) }; CartographicExtent extent = new CartographicExtent(0.0, 0.0, 3.0, 1.0); int[] parts = new[] { 0 }; MultiPatchPartType[] partTypes = new[] { MultiPatchPartType.TriangleStrip }; double[] zValues = new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 }; double[] measures = new[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; MultiPatchShape multipatch = new MultiPatchShape(0, m_metadata, extent, parts, partTypes, positions, 0.0, 0.0, zValues, 0.0, 0.0, measures); MultiPatch patch = new MultiPatch(multipatch, m_document, Color.Blue); patch.Write(); string result = m_stringWriter.ToString(); Regex trianglePattern = new Regex(m_trianglePattern); Assert.AreEqual(5, trianglePattern.Matches(result).Count); }
public void TestMultipatchConversionWithInnerAndOuterRings() { Rectangular[] positions = new[] { new Rectangular(0.0, 5.0), new Rectangular(5.0, 10.0), new Rectangular(10.0, 5.0), new Rectangular(5.0, 0.0), new Rectangular(0.0, 5.0), new Rectangular(2.0, 5.0), new Rectangular(5.0, 2.0), new Rectangular(8.0, 5.0), new Rectangular(5.0, 8.0), new Rectangular(2.0, 5.0) }; CartographicExtent extent = new CartographicExtent(0.0, 0.0, 10.0, 10.0); int[] parts = new[] { 0, 5 }; MultiPatchPartType[] partTypes = new[] { MultiPatchPartType.OuterRing, MultiPatchPartType.InnerRing }; double[] zValues = new[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; double[] measures = new[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; MultiPatchShape multipatch = new MultiPatchShape(0, m_metadata, extent, parts, partTypes, positions, 0.0, 0.0, zValues, 0.0, 0.0, measures); MultiPatch patch = new MultiPatch(multipatch, m_document, Color.Blue); patch.Write(); string result = m_stringWriter.ToString(); Assert.IsTrue(Regex.IsMatch(result, m_polygonPattern)); }
public static IMultiPatch EnvelopeToBoundingBox(IEnvelope2 ienvelope2_0) { object value = Missing.Value; double double_; double double_2; double double_3; double double_4; ienvelope2_0.QueryCoords(out double_, out double_2, out double_3, out double_4); double zMin = ienvelope2_0.ZMin; double zMax = ienvelope2_0.ZMax; IMultiPatch multiPatch = new MultiPatch() as IMultiPatch; IGeometryCollection geometryCollection = multiPatch as IGeometryCollection; IPointCollection pointCollection = new TriangleStrip(); Utils3D.MakeZMAware(pointCollection as IGeometry, true); pointCollection.AddPoint(Utils3D.Create3DPoint(double_, double_2, zMin), ref value, ref value); pointCollection.AddPoint(Utils3D.Create3DPoint(double_, double_2, zMax), ref value, ref value); pointCollection.AddPoint(Utils3D.Create3DPoint(double_3, double_2, zMin), ref value, ref value); pointCollection.AddPoint(Utils3D.Create3DPoint(double_3, double_2, zMax), ref value, ref value); pointCollection.AddPoint(Utils3D.Create3DPoint(double_3, double_4, zMin), ref value, ref value); pointCollection.AddPoint(Utils3D.Create3DPoint(double_3, double_4, zMax), ref value, ref value); pointCollection.AddPoint(Utils3D.Create3DPoint(double_, double_4, zMin), ref value, ref value); pointCollection.AddPoint(Utils3D.Create3DPoint(double_, double_4, zMax), ref value, ref value); pointCollection.AddPoint(Utils3D.Create3DPoint(double_, double_2, zMin), ref value, ref value); pointCollection.AddPoint(Utils3D.Create3DPoint(double_, double_2, zMax), ref value, ref value); geometryCollection.AddGeometry(pointCollection as IGeometry, ref value, ref value); return(multiPatch); }
private Patch LoadSfzPatch(Stream stream, string patchName, string directory) { SfzReader sfz = new SfzReader(stream, patchName); MultiPatch multi = new MultiPatch(patchName); multi.LoadSfz(sfz.Regions, assets, directory); return(multi); }
//---------------------------------------------------------------------------------- public static MultiPatch MaakTrianglesMP() { MultiPatch pMultiPatch = new MultiPatch(); IGeometryCollection pGCol = (IGeometryCollection)pMultiPatch; IPointCollection pTriangles = new Triangles(); IGeometry2 pGeom = (IGeometry2)pTriangles; int nfcs = ImportInArcscene.binReader.ReadInt32(); for (int i = 1; i <= nfcs * 3; i++) { double ptx = ImportInArcscene.binReader.ReadSingle(); double pty = ImportInArcscene.binReader.ReadSingle(); double ptz = ImportInArcscene.binReader.ReadSingle(); pTriangles.AddPoint(PuntTransformatie(ptx, pty, ptz), ref _missing, ref _missing); } pGCol.AddGeometry(pGeom, ref _missing, ref _missing); return(pMultiPatch); }
private void LoadSf2(Stream stream) { SoundFont sf = new SoundFont(stream); bankName = sf.Info.BankName; comment = sf.Info.Comments; //load samples for (int x = 0; x < sf.Presets.SampleHeaders.Length; x++) { assets.SampleAssetList.Add(new SampleDataAsset(sf.Presets.SampleHeaders[x], sf.SampleData)); } //create instrument regions first Sf2Region[][] inst = ReadSf2Instruments(sf.Presets.Instruments); //load each patch foreach (PresetHeader p in sf.Presets.PresetHeaders) { Generator[] globalGens = null; int i; if (p.Zones[0].Generators.Length == 0 || p.Zones[0].Generators[p.Zones[0].Generators.Length - 1].GeneratorType != GeneratorEnum.Instrument) { globalGens = p.Zones[0].Generators; i = 1; } else { i = 0; } List <Sf2Region> regionList = new List <Sf2Region>(); while (i < p.Zones.Length) { byte presetLoKey = 0; byte presetHiKey = 127; byte presetLoVel = 0; byte presetHiVel = 127; if (p.Zones[i].Generators[0].GeneratorType == GeneratorEnum.KeyRange) { if (BitConverter.IsLittleEndian) { presetLoKey = (byte)(p.Zones[i].Generators[0].AmountInt16 & 0xFF); presetHiKey = (byte)((p.Zones[i].Generators[0].AmountInt16 >> 8) & 0xFF); } else { presetHiKey = (byte)(p.Zones[i].Generators[0].AmountInt16 & 0xFF); presetLoKey = (byte)((p.Zones[i].Generators[0].AmountInt16 >> 8) & 0xFF); } if (p.Zones[i].Generators.Length > 1 && p.Zones[i].Generators[1].GeneratorType == GeneratorEnum.VelocityRange) { if (BitConverter.IsLittleEndian) { presetLoVel = (byte)(p.Zones[i].Generators[1].AmountInt16 & 0xFF); presetHiVel = (byte)((p.Zones[i].Generators[1].AmountInt16 >> 8) & 0xFF); } else { presetHiVel = (byte)(p.Zones[i].Generators[1].AmountInt16 & 0xFF); presetLoVel = (byte)((p.Zones[i].Generators[1].AmountInt16 >> 8) & 0xFF); } } } else if (p.Zones[i].Generators[0].GeneratorType == GeneratorEnum.VelocityRange) { if (BitConverter.IsLittleEndian) { presetLoVel = (byte)(p.Zones[i].Generators[0].AmountInt16 & 0xFF); presetHiVel = (byte)((p.Zones[i].Generators[0].AmountInt16 >> 8) & 0xFF); } else { presetHiVel = (byte)(p.Zones[i].Generators[0].AmountInt16 & 0xFF); presetLoVel = (byte)((p.Zones[i].Generators[0].AmountInt16 >> 8) & 0xFF); } } if (p.Zones[i].Generators[p.Zones[i].Generators.Length - 1].GeneratorType == GeneratorEnum.Instrument) { Sf2Region[] insts = inst[p.Zones[i].Generators[p.Zones[i].Generators.Length - 1].AmountInt16]; for (int x = 0; x < insts.Length; x++) { byte instLoKey; byte instHiKey; byte instLoVel; byte instHiVel; if (BitConverter.IsLittleEndian) { instLoKey = (byte)(insts[x].Generators[(int)GeneratorEnum.KeyRange] & 0xFF); instHiKey = (byte)((insts[x].Generators[(int)GeneratorEnum.KeyRange] >> 8) & 0xFF); instLoVel = (byte)(insts[x].Generators[(int)GeneratorEnum.VelocityRange] & 0xFF); instHiVel = (byte)((insts[x].Generators[(int)GeneratorEnum.VelocityRange] >> 8) & 0xFF); } else { instHiKey = (byte)(insts[x].Generators[(int)GeneratorEnum.KeyRange] & 0xFF); instLoKey = (byte)((insts[x].Generators[(int)GeneratorEnum.KeyRange] >> 8) & 0xFF); instHiVel = (byte)(insts[x].Generators[(int)GeneratorEnum.VelocityRange] & 0xFF); instLoVel = (byte)((insts[x].Generators[(int)GeneratorEnum.VelocityRange] >> 8) & 0xFF); } if ((instLoKey <= presetHiKey && presetLoKey <= instHiKey) && (instLoVel <= presetHiVel && presetLoVel <= instHiVel)) { Sf2Region r = new Sf2Region(); Array.Copy(insts[x].Generators, r.Generators, r.Generators.Length); ReadSf2Region(r, globalGens, p.Zones[i].Generators, true); regionList.Add(r); } } } i++; } MultiPatch mp = new MultiPatch(p.Name); mp.LoadSf2(regionList.ToArray(), assets); assets.PatchAssetList.Add(new PatchAsset(mp.Name, mp)); AssignPatchToBank(mp, p.BankNumber, p.PatchNumber, p.PatchNumber); } }
private void _read() { _shapeType = ((ShapefileMain.ShapeType)m_io.ReadS4le()); if (ShapeType != ShapefileMain.ShapeType.NullShape) { switch (ShapeType) { case ShapefileMain.ShapeType.PointM: { _shapeParameters = new PointM(m_io, this, m_root); break; } case ShapefileMain.ShapeType.PolygonZ: { _shapeParameters = new PolygonZ(m_io, this, m_root); break; } case ShapefileMain.ShapeType.MultiPointM: { _shapeParameters = new MultiPointM(m_io, this, m_root); break; } case ShapefileMain.ShapeType.PolyLineZ: { _shapeParameters = new PolyLineZ(m_io, this, m_root); break; } case ShapefileMain.ShapeType.MultiPointZ: { _shapeParameters = new MultiPointZ(m_io, this, m_root); break; } case ShapefileMain.ShapeType.MultiPoint: { _shapeParameters = new MultiPoint(m_io, this, m_root); break; } case ShapefileMain.ShapeType.PolygonM: { _shapeParameters = new PolygonM(m_io, this, m_root); break; } case ShapefileMain.ShapeType.Polygon: { _shapeParameters = new Polygon(m_io, this, m_root); break; } case ShapefileMain.ShapeType.Point: { _shapeParameters = new Point(m_io, this, m_root); break; } case ShapefileMain.ShapeType.PolyLineM: { _shapeParameters = new PolyLineM(m_io, this, m_root); break; } case ShapefileMain.ShapeType.PolyLine: { _shapeParameters = new PolyLine(m_io, this, m_root); break; } case ShapefileMain.ShapeType.PointZ: { _shapeParameters = new PointZ(m_io, this, m_root); break; } case ShapefileMain.ShapeType.MultiPatch: { _shapeParameters = new MultiPatch(m_io, this, m_root); break; } } } }
public override void OnMouseDown(int int_2, int int_3, int int_4, int int_5) { IPoint point; object obj; object obj2; this._plugin.SceneGraph.Locate(this._plugin.ActiveViewer, int_4, int_5, esriScenePickMode.esriScenePickGeography, true, out point, out obj, out obj2); if (point != null) { IClone clone = point as IClone; IPoint point2 = clone.Clone() as IPoint; point2.Z /= this._plugin.SceneGraph.VerticalExaggeration; point2.SpatialReference = this._plugin.Scene.SpatialReference; IDisplay3D display3D = this._plugin.SceneGraph as IDisplay3D; display3D.FlashLocation(point2); if (this.ipointCollection_0 == null) { this.ipointCollection_0 = new Polyline(); (this.ipointCollection_0 as IGeometry).SpatialReference = this._plugin.Scene.SpatialReference; } object value = Missing.Value; this.ipointCollection_0.AddPoint(point, ref value, ref value); IPolyline polyline = null; if (this.ipointCollection_0.PointCount == 2) { clone = (this.ipointCollection_0 as IClone); polyline = (clone.Clone() as IPolyline); this.ipointCollection_0 = null; } if (polyline != null) { this.bool_0 = false; this.ipointCollection_0 = null; IPoint fromPoint = polyline.FromPoint; fromPoint.Z = this.isurface_0.GetElevation(fromPoint); IPoint toPoint = polyline.ToPoint; toPoint.Z = this.isurface_0.GetElevation(toPoint); if (!this.isurface_0.IsVoidZ(fromPoint.Z) && !this.isurface_0.IsVoidZ(toPoint.Z)) { fromPoint.Z += ToolSceneLineOfSight.ObserverOffset; toPoint.Z += ToolSceneLineOfSight.TargetOffset; object obj3 = 1; IPoint point3; IPolyline ipolyline_; IPolyline ipolyline_2; bool flag; this.isurface_0.GetLineOfSight(fromPoint, toPoint, out point3, out ipolyline_, out ipolyline_2, out flag, ToolSceneLineOfSight.bCurvEnabled, ToolSceneLineOfSight.bCurvEnabled, ref obj3); ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol(); IRgbColor rgbColor = new RgbColor(); simpleLineSymbol.Width = 2.0; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol(); IMultiPatch multiPatch = new MultiPatch() as IMultiPatch; multiPatch.SpatialReference = this._plugin.Scene.SpatialReference; IMultiPatch multiPatch2 = new MultiPatch() as IMultiPatch; multiPatch2.SpatialReference = this._plugin.Scene.SpatialReference; double num; GeometryOperator.CreateVerticalLOSPatches(flag, fromPoint, toPoint, ipolyline_, ipolyline_2, multiPatch as IGeometryCollection, multiPatch2 as IGeometryCollection, out num); if (!multiPatch.IsEmpty) { rgbColor.Green = 255; rgbColor.Red = 0; simpleFillSymbol.Color = rgbColor; this.AddGraphic(this._plugin.Scene, multiPatch, simpleFillSymbol as ISymbol, false, false, ""); } if (!multiPatch2.IsEmpty) { rgbColor.Green = 0; rgbColor.Red = 255; simpleFillSymbol.Color = rgbColor; this.AddGraphic(this._plugin.Scene, multiPatch2, simpleFillSymbol as ISymbol, false, false, ""); } } } } }
private static string MakeTextList(byte[] data, string title) { //Console.WriteLine($"MakeTextList: data length = {data.Length} bytes"); StringBuilder sb = new StringBuilder(); sb.Append("SINGLE patches:\n"); int offset = 0; for (int i = 0; i < SinglePatchCount; i++) { byte[] singleData = new byte[SinglePatch.DataSize]; Buffer.BlockCopy(data, offset, singleData, 0, SinglePatch.DataSize); //Console.WriteLine($"Constructing single patch from {singleData.Length} bytes of data starting at {offset}"); SinglePatch single = new SinglePatch(singleData); string name = PatchUtil.GetPatchName(i); sb.Append($"S{name} {single.Name}\n"); if ((i + 1) % 16 == 0) { sb.Append("\n"); } offset += SinglePatch.DataSize; } sb.Append("\n"); sb.Append("MULTI patches:\n"); for (int i = 0; i < MultiPatchCount; i++) { byte[] multiData = new byte[MultiPatch.DataSize]; Buffer.BlockCopy(data, offset, multiData, 0, MultiPatch.DataSize); //Console.WriteLine($"Constructing multi patch from {multiData.Length} bytes of data starting at {offset}"); MultiPatch multi = new MultiPatch(multiData); string name = PatchUtil.GetPatchName(i); sb.Append($"M{name} {multi.Name}\n"); if ((i + 1) % 16 == 0) { sb.Append("\n"); } offset += MultiPatch.DataSize; } /* * sb.Append("\n"); * sb.Append("DRUM:\n"); * byte[] drumData = new byte[DrumPatch.DataSize]; * Buffer.BlockCopy(data, offset, drumData, 0, DrumPatch.DataSize); * Console.WriteLine($"Constructing drum patch from {drumData.Length} bytes of data starting at {offset}"); * DrumPatch drumPatch = new DrumPatch(drumData); */ offset += DrumPatch.DataSize; sb.Append("\n"); sb.Append("EFFECT SETTINGS:\n"); for (int i = 0; i < 32; i++) { byte[] effectData = new byte[EffectPatch.DataSize]; Buffer.BlockCopy(data, offset, effectData, 0, EffectPatch.DataSize); //Console.WriteLine($"Constructing effect patch from {effectData.Length} bytes of data starting at {offset}"); EffectPatch effectPatch = new EffectPatch(effectData); sb.Append($"E-{i+1,2} {effectPatch}"); offset += EffectPatch.DataSize; } return(sb.ToString()); }
public static int RunInitAndReturnExitCode(InitOptions opts) { List <SinglePatch> singlePatches = new List <SinglePatch>(); for (int i = 0; i < SinglePatchCount; i++) { SinglePatch single = new SinglePatch(); singlePatches.Add(single); } List <MultiPatch> multiPatches = new List <MultiPatch>(); for (int i = 0; i < MultiPatchCount; i++) { MultiPatch multi = new MultiPatch(); multiPatches.Add(multi); } // Create a System Exclusive header for an "All Patch Data Dump" SystemExclusiveHeader header = new SystemExclusiveHeader(); header.ManufacturerID = 0x40; // Kawai header.Channel = 0; // MIDI channel 1 header.Function = (byte)SystemExclusiveFunction.AllPatchDataDump; header.Group = 0; // synthesizer group header.MachineID = 0x04; // K4/K4r ID header.Substatus1 = 0; // INT header.Substatus2 = 0; // always zero List <byte> data = new List <byte>(); data.Add(SystemExclusiveHeader.Initiator); data.AddRange(header.ToData()); // Single patches: 64 * 131 = 8384 bytes of data foreach (SinglePatch s in singlePatches) { data.AddRange(s.ToData()); } // Multi patches: 64 * 77 = 4928 bytes of data // The K4 MIDI spec has an error in the "All Patch Data" description; // multi patches are listed as 87, not 77 bytes foreach (MultiPatch m in multiPatches) { data.AddRange(m.ToData()); } // Drums: 682 bytes of data DrumPatch drums = new DrumPatch(); data.AddRange(drums.ToData()); List <EffectPatch> effectPatches = new List <EffectPatch>(); for (int i = 0; i < EffectPatchCount; i++) { EffectPatch effect = new EffectPatch(); effectPatches.Add(effect); } // Effect patches: 32 * 35 = 1120 bytes of data foreach (EffectPatch e in effectPatches) { data.AddRange(e.ToData()); } data.Add(SystemExclusiveHeader.Terminator); // SysEx initiator: 1 // SysEx header: 7 // Single patches: 8384 // Multi patches: 4928 // Drum settings: 682 // Effect patches: 1120 // SysEx terminator: 1 // Total bytes: 15123 // Write the data to the output file File.WriteAllBytes(opts.OutputFileName, data.ToArray()); return(0); }
private static string MakeHtmlList(byte[] data, string title) { string GetNoteName(int noteNumber) { string[] notes = new string[] { "C", "C#", "D", "Eb", "E", "F", "F#", "G", "G#", "A", "Bb", "B" }; int octave = noteNumber / 12 + 1; string name = notes[noteNumber % 12]; return(name + octave); } StringBuilder sb = new StringBuilder(); sb.Append(String.Format("<h1>{0}</h1>\n", title)); SinglePatch[][] singleBanks = new SinglePatch[BankCount][]; //BankCount, PatchesPerBank]; int offset = 0; int patchSize = SinglePatch.DataSize; for (int bankNumber = 0; bankNumber < BankCount; bankNumber++) { SinglePatch[] patches = new SinglePatch[PatchesPerBank]; for (int patchNumber = 0; patchNumber < PatchesPerBank; patchNumber++) { byte[] singleData = new byte[patchSize]; Buffer.BlockCopy(data, offset, singleData, 0, patchSize); SinglePatch single = new SinglePatch(singleData); patches[patchNumber] = single; offset += patchSize; } singleBanks[bankNumber] = patches; } // Now we should have all the single patches collected in four lists of 16 each sb.Append("<table>\n"); sb.Append("<tr>\n <th>SINGLE</th>\n"); for (int bankNumber = 0; bankNumber < BankCount; bankNumber++) { char bankLetter = "ABCD"[bankNumber]; sb.Append(String.Format(" <th>{0}</th>\n", bankLetter)); } sb.Append("</tr>\n"); for (int patchNumber = 0; patchNumber < PatchesPerBank; patchNumber++) { sb.Append("<tr>\n"); sb.Append(String.Format(" <td>{0,2}</td>\n", patchNumber + 1)); for (int bankNumber = 0; bankNumber < BankCount; bankNumber++) { SinglePatch[] patches = singleBanks[bankNumber]; string patchId = PatchUtil.GetPatchName(bankNumber * patchNumber); SinglePatch single = patches[patchNumber]; sb.Append(String.Format($" <td>{single.Name:10}</td>\n")); } sb.Append("</tr>\n"); } sb.Append("</table>\n"); // // Multi patches // patchSize = MultiPatch.DataSize; MultiPatch[][] multiBanks = new MultiPatch[BankCount][]; for (int bankNumber = 0; bankNumber < BankCount; bankNumber++) { MultiPatch[] patches = new MultiPatch[PatchesPerBank]; for (int patchNumber = 0; patchNumber < PatchesPerBank; patchNumber++) { byte[] multiData = new byte[patchSize]; Buffer.BlockCopy(data, offset, multiData, 0, patchSize); MultiPatch multi = new MultiPatch(multiData); patches[patchNumber] = multi; offset += patchSize; } multiBanks[bankNumber] = patches; } sb.Append("<table>\n"); sb.Append("<tr>\n <th>MULTI</th>\n"); for (int bankNumber = 0; bankNumber < BankCount; bankNumber++) { char bankLetter = "ABCD"[bankNumber]; sb.Append(String.Format(" <th>{0}</th>\n", bankLetter)); } sb.Append("</tr>\n"); for (int patchNumber = 0; patchNumber < PatchesPerBank; patchNumber++) { sb.Append("<tr>\n"); sb.Append(String.Format(" <td>{0,2}</td>\n", patchNumber + 1)); for (int bankNumber = 0; bankNumber < BankCount; bankNumber++) { MultiPatch[] patches = multiBanks[bankNumber]; string patchId = PatchUtil.GetPatchName(bankNumber * patchNumber); MultiPatch single = patches[patchNumber]; sb.Append(String.Format($" <td>{single.Name:10}</td>\n")); } sb.Append("</tr>\n"); } sb.Append("</table>\n"); patchSize = DrumPatch.DataSize; // TODO: List drum // Crash when setting tune of drum note (value out of range) /* * sb.Append("<table>\n"); * sb.Append("<caption>DRUM</caption>\n"); * sb.Append("<tr><th>Note</th><th>Parameters</th></tr>\n"); * * patchSize = DrumPatch.DataSize; * byte[] drumData = new byte[patchSize]; * Buffer.BlockCopy(data, offset, drumData, 0, patchSize); * var drum = new DrumPatch(drumData); * for (int i = 0; i < 128; i++) * { * var note = drum.Notes[i]; * sb.Append($"<tr><td>E-{GetNoteName(i)}</td><td>{note}</td></tr>\n"); * } * * sb.Append("</table>\n"); */ offset += patchSize; sb.Append("<table>\n"); sb.Append("<caption>EFFECT</caption>\n"); sb.Append("<tr><th>#</th><th>Type and parameters</th></tr>\n"); patchSize = EffectPatch.DataSize; for (int i = 0; i < 32; i++) { byte[] effectData = new byte[patchSize]; Buffer.BlockCopy(data, offset, effectData, 0, patchSize); //Console.WriteLine($"Constructing effect patch from {effectData.Length} bytes of data starting at {offset}"); EffectPatch effectPatch = new EffectPatch(effectData); sb.Append($"<tr><td>E-{i+1,2}</td><td>{effectPatch}</td></tr>\n"); offset += patchSize; } sb.Append("</table>\n"); return(sb.ToString()); }
public void LoadSf2(IReadable input) { Reset(); Logger.Debug("Reading SF2"); var sf = new SoundFont(); sf.Load(input); Logger.Debug("Building patchbank"); Name = sf.Info.BankName; Comments = sf.Info.Comments; //load samples foreach (var sampleHeader in sf.Presets.SampleHeaders) { _assets.SampleAssets.Add(new SampleDataAsset(sampleHeader, sf.SampleData)); } //create instrument regions first var sfinsts = ReadSf2Instruments(sf.Presets.Instruments); //load each patch foreach (var p in sf.Presets.PresetHeaders) { Generator[] globalGens = null; int i; if (p.Zones[0].Generators.Length == 0 || p.Zones[0].Generators[p.Zones[0].Generators.Length - 1].GeneratorType != GeneratorEnum.Instrument) { globalGens = p.Zones[0].Generators; i = 1; } else { i = 0; } var regionList = new FastList <Sf2Region>(); while (i < p.Zones.Length) { byte presetLoKey = 0; byte presetHiKey = 127; byte presetLoVel = 0; byte presetHiVel = 127; if (p.Zones[i].Generators[0].GeneratorType == GeneratorEnum.KeyRange) { if (TypeUtils.IsLittleEndian) { presetLoKey = TypeUtils.ToUInt8(p.Zones[i].Generators[0].AmountInt16 & 0xFF); presetHiKey = TypeUtils.ToUInt8((p.Zones[i].Generators[0].AmountInt16 >> 8) & 0xFF); } else { presetHiKey = TypeUtils.ToUInt8(p.Zones[i].Generators[0].AmountInt16 & 0xFF); presetLoKey = TypeUtils.ToUInt8((p.Zones[i].Generators[0].AmountInt16 >> 8) & 0xFF); } if (p.Zones[i].Generators.Length > 1 && p.Zones[i].Generators[1].GeneratorType == GeneratorEnum.VelocityRange) { if (TypeUtils.IsLittleEndian) { presetLoVel = TypeUtils.ToUInt8(p.Zones[i].Generators[1].AmountInt16 & 0xFF); presetHiVel = TypeUtils.ToUInt8((p.Zones[i].Generators[1].AmountInt16 >> 8) & 0xFF); } else { presetHiVel = TypeUtils.ToUInt8(p.Zones[i].Generators[1].AmountInt16 & 0xFF); presetLoVel = TypeUtils.ToUInt8((p.Zones[i].Generators[1].AmountInt16 >> 8) & 0xFF); } } } else if (p.Zones[i].Generators[0].GeneratorType == GeneratorEnum.VelocityRange) { if (TypeUtils.IsLittleEndian) { presetLoVel = TypeUtils.ToUInt8(p.Zones[i].Generators[0].AmountInt16 & 0xFF); presetHiVel = TypeUtils.ToUInt8((p.Zones[i].Generators[0].AmountInt16 >> 8) & 0xFF); } else { presetHiVel = TypeUtils.ToUInt8(p.Zones[i].Generators[0].AmountInt16 & 0xFF); presetLoVel = TypeUtils.ToUInt8((p.Zones[i].Generators[0].AmountInt16 >> 8) & 0xFF); } } if (p.Zones[i].Generators[p.Zones[i].Generators.Length - 1].GeneratorType == GeneratorEnum.Instrument) { var insts = sfinsts[p.Zones[i].Generators[p.Zones[i].Generators.Length - 1].AmountInt16]; foreach (var inst in insts) { byte instLoKey; byte instHiKey; byte instLoVel; byte instHiVel; if (TypeUtils.IsLittleEndian) { instLoKey = TypeUtils.ToUInt8(inst.Generators[(int)GeneratorEnum.KeyRange] & 0xFF); instHiKey = TypeUtils.ToUInt8((inst.Generators[(int)GeneratorEnum.KeyRange] >> 8) & 0xFF); instLoVel = TypeUtils.ToUInt8(inst.Generators[(int)GeneratorEnum.VelocityRange] & 0xFF); instHiVel = TypeUtils.ToUInt8((inst.Generators[(int)GeneratorEnum.VelocityRange] >> 8) & 0xFF); } else { instHiKey = TypeUtils.ToUInt8(inst.Generators[(int)GeneratorEnum.KeyRange] & 0xFF); instLoKey = TypeUtils.ToUInt8((inst.Generators[(int)GeneratorEnum.KeyRange] >> 8) & 0xFF); instHiVel = TypeUtils.ToUInt8(inst.Generators[(int)GeneratorEnum.VelocityRange] & 0xFF); instLoVel = TypeUtils.ToUInt8((inst.Generators[(int)GeneratorEnum.VelocityRange] >> 8) & 0xFF); } if ((instLoKey <= presetHiKey && presetLoKey <= instHiKey) && (instLoVel <= presetHiVel && presetLoVel <= instHiVel)) { var r = new Sf2Region(); Std.ArrayCopy(inst.Generators, 0, r.Generators, 0, r.Generators.Length); ReadSf2Region(r, globalGens, p.Zones[i].Generators, true); regionList.Add(r); } } } i++; } var mp = new MultiPatch(p.Name); mp.LoadSf2(regionList.ToArray(), _assets); _assets.PatchAssets.Add(new PatchAsset(mp.Name, mp)); AssignPatchToBank(mp, p.BankNumber, p.PatchNumber, p.PatchNumber); } }
public static IGroupElement CreateRoadSurfaceFromPolygon(IFeature ifeature_0, IFeature3DProperties ifeature3DProperties_0, clsTextureGroup clsTextureGroup_0, ISurface isurface_0, string string_0, IPolygon ipolygon_0, bool bool_0) { IGroupElement groupElement = null; IGroupElement result; try { IEncode3DProperties encode3DProperties = new GeometryEnvironment() as IEncode3DProperties; IGroupElement groupElement2 = new GroupElement() as IGroupElement; if (modFacades.m_limitAngle == 0.0) { modFacades.m_limitAngle = 0.5235987666666666; } IGeometry geometry = null; if (ifeature_0 != null) { if (ifeature3DProperties_0 != null && bool_0) { ifeature3DProperties_0.ApplyFeatureProperties(ifeature_0, out geometry, false); modFacades.g_bFeaturePropertiesApplied = true; } else { geometry = ifeature_0.Shape; modFacades.g_bFeaturePropertiesApplied = false; } } else if (ipolygon_0 != null) { geometry = ipolygon_0; } if (geometry == null) { result = groupElement; return(result); } if (!(geometry is IMultiPatch)) { } IEnvelope envelope = geometry.Envelope; double num = envelope.ZMin; if (modFacades.IsNaN(num)) { num = 0.0; } double num2 = 0.0; I3DProperties i3DProperties = ifeature3DProperties_0 as I3DProperties; if (i3DProperties.OffsetExpressionString.Length > 0) { num2 = Convert.ToDouble(i3DProperties.OffsetExpressionString); } if (geometry is IPolygon) { num += num2; } IGeometryCollection geometryCollection = geometry as IGeometryCollection; int geometryCount = geometryCollection.GeometryCount; int num3; if (geometry is IMultiPatch) { geometryCount = geometryCollection.GeometryCount; num3 = geometryCollection.GeometryCount * 2 / 3; modFacades.m_extrusionHeight = geometry.Envelope.ZMax - geometry.Envelope.ZMin; } else { num3 = 0; geometryCount = geometryCollection.GeometryCount; } if (modFacades.m_extrusionHeight >= 1.0) { } for (int i = num3; i <= geometryCount - 1; i++) { IGeometry geometry2 = geometryCollection.get_Geometry(i); esriGeometryType geometryType = geometry2.GeometryType; if (geometryType == esriGeometryType.esriGeometryRing || geometryType == esriGeometryType.esriGeometryPolyline) { } IPointCollection pointCollection = geometry2 as IPointCollection; int pointCount = pointCollection.PointCount; if (pointCount >= 2) { } IVector3D vector3D = new Vector3D() as IVector3D; vector3D.XComponent = 0.0; vector3D.YComponent = 0.0; vector3D.ZComponent = 1.0; double m = 0.0; encode3DProperties.PackNormal(vector3D, out m); IPointCollection pointCollection2 = new Ring(); object value = Missing.Value; short num4 = 0; while ((int)num4 <= pointCount - 1) { IPoint point = pointCollection.get_Point((int)num4); point.Z = num; point.M = m; IClone clone = point as IClone; pointCollection2.AddPoint(clone.Clone() as IPoint, ref value, ref value); num4 += 1; } IRing ring = pointCollection2 as IRing; ring.Close(); IMultiPatch multiPatch = new MultiPatch() as IMultiPatch; IGeometryCollection geometryCollection2 = multiPatch as IGeometryCollection; IZAware iZAware = multiPatch as IZAware; iZAware.ZAware = true; IMAware iMAware = multiPatch as IMAware; iMAware.MAware = true; geometryCollection2.AddGeometry(pointCollection2 as IGeometry, ref value, ref value); multiPatch.PutRingType(pointCollection2 as IRing, esriMultiPatchRingType.esriMultiPatchOuterRing); IElement element = modFacades.CreateElement(multiPatch, clsTextureGroup_0.RoofSymbol, string_0 + ";ROOFCOLOR=" + clsTextureGroup_0.RoofColorRGB.ToString()); if (element != null) { groupElement2.AddElement(element); } } if (groupElement2 != null) { IElementProperties elementProperties = groupElement2 as IElementProperties; elementProperties.Name = string_0; } groupElement = groupElement2; result = groupElement; return(result); } catch { } result = groupElement; return(result); }
public static IGroupElement CreateFacadesFromPolygon(IFeature ifeature_0, IFeature3DProperties ifeature3DProperties_0, clsTextureGroup clsTextureGroup_0, ISurface isurface_0, string string_0, IPolygon ipolygon_0, bool bool_0) { IGroupElement groupElement = null; IGroupElement result; try { IEncode3DProperties encode3DProperties = new GeometryEnvironment() as IEncode3DProperties; IGroupElement groupElement2 = new GroupElement() as IGroupElement; if (modFacades.m_limitAngle == 0.0) { modFacades.m_limitAngle = 0.5235987666666666; } IGeometry geometry = null; if (ifeature_0 != null) { if (ifeature3DProperties_0 != null && bool_0) { ifeature3DProperties_0.ApplyFeatureProperties(ifeature_0, out geometry, false); } else { geometry = ifeature_0.Shape; } } else if (ipolygon_0 != null) { geometry = ipolygon_0; } if (geometry == null) { result = null; return(result); } if (!(geometry is IMultiPatch)) { } IEnvelope envelope = geometry.Envelope; double num = envelope.ZMin; ISpatialReference spatialReference = BuildingProperty.Scene.SpatialReference; geometry.Project(spatialReference); string a = num.ToString(); if (a.Equals("非数字")) { num = 0.0; } double num2 = 0.0; if (ifeature3DProperties_0 != null) { I3DProperties i3DProperties = ifeature3DProperties_0 as I3DProperties; if (i3DProperties.OffsetExpressionString.Length > 0) { try { num2 = Convert.ToDouble(i3DProperties.OffsetExpressionString); } catch { } } if (geometry is IPolygon) { num += num2; } } IGeometryCollection geometryCollection = geometry as IGeometryCollection; int geometryCount = geometryCollection.GeometryCount; int num3; if (geometry is IMultiPatch) { geometryCount = geometryCollection.GeometryCount; num3 = geometryCollection.GeometryCount * 2 / 3; modFacades.m_extrusionHeight = geometry.Envelope.ZMax - geometry.Envelope.ZMin; } else { num3 = 0; geometryCount = geometryCollection.GeometryCount; } if (modFacades.m_extrusionHeight < 1.0) { modFacades.m_extrusionHeight = 1.0; } IPoint point = null; double num4 = 0.0; double num5 = 0.0; double num6 = 0.0; object value = Missing.Value; for (int i = num3; i < geometryCount; i++) { IGeometry geometry2 = geometryCollection.get_Geometry(i); esriGeometryType geometryType = geometry2.GeometryType; if (geometryType == esriGeometryType.esriGeometryRing || geometryType == esriGeometryType.esriGeometryPolyline) { IPointCollection pointCollection = geometry2 as IPointCollection; int pointCount = pointCollection.PointCount; if (pointCount >= 2) { int num7 = 0; int num8 = 1; bool flag = false; IPointCollection pointCollection2; double m; IMultiPatch multiPatch; IGeometryCollection geometryCollection2; IZAware iZAware; IMAware iMAware; IElement element; while (!flag) { bool flag2 = false; while (num8 < pointCount && !flag2) { if (num8 - num7 == 1) { IPoint point2 = pointCollection.get_Point(num7); point = pointCollection.get_Point(num8); num5 = point.X - point2.X; num6 = point.Y - point2.Y; num4 = Math.Sqrt(num5 * num5 + num6 * num6); if (isurface_0 != null) { num = isurface_0.get_Z(point.X, point.Y); num += num2; } } else { IPoint point2 = point; double num9 = num5; double num10 = num6; point = pointCollection.get_Point(num8); if (isurface_0 != null) { num = isurface_0.get_Z(point.X, point.Y); num += num2; } num5 = point.X - point2.X; num6 = point.Y - point2.Y; double num11 = Math.Sqrt(num9 * num9 + num10 * num10); double num12 = Math.Sqrt(num5 * num5 + num6 * num6); double num13 = (num9 * num5 + num10 * num6) / (num11 * num12); if (num13 < Math.Cos(modFacades.m_limitAngle)) { flag2 = true; break; } num4 += num12; } num8++; } if (flag2) { num8--; } else { num8--; } pointCollection2 = new TriangleStrip(); double num14 = 0.0; for (int j = num7; j <= num8; j++) { if (j > 0) { IPoint point2 = point; point = pointCollection.get_Point(j); num5 = point.X - point2.Y; num6 = point.Y - point2.Y; num14 += Math.Sqrt(num5 * num5 + num6 * num6); } else { point = pointCollection.get_Point(j); } point.Z = num; m = 0.0; encode3DProperties.PackTexture2D(num14 / num4, 0.0, out m); point.M = m; IClone clone = point as IClone; pointCollection2.AddPoint(clone.Clone() as IPoint, ref value, ref value); point.Z = num + modFacades.m_extrusionHeight; m = 0.0; encode3DProperties.PackTexture2D(num14 / num4, -1.0, out m); point.M = m; pointCollection2.AddPoint(clone.Clone() as IPoint, ref value, ref value); } multiPatch = new MultiPatch() as IMultiPatch; geometryCollection2 = (multiPatch as IGeometryCollection); iZAware = (multiPatch as IZAware); iZAware.ZAware = true; iMAware = (multiPatch as IMAware); iMAware.MAware = true; geometryCollection2.AddGeometry(pointCollection2 as IGeometry, ref value, ref value); if (clsTextureGroup_0 != null) { int index = modFacades.FindTextureByAspect(clsTextureGroup_0, num4 / modFacades.m_extrusionHeight); element = modFacades.CreateElement(multiPatch, clsTextureGroup_0.Symbols[index], string_0); } else { element = modFacades.CreateElement(multiPatch, null, string_0); } if (element != null) { groupElement2.AddElement(element); } num7 = num8; num8 = num7 + 1; if (num7 >= pointCount - 1) { flag = true; } } IVector3D vector3D = new Vector3D() as IVector3D; vector3D.XComponent = 0.0; vector3D.YComponent = 0.0; vector3D.ZComponent = 1.0; m = 0.0; encode3DProperties.PackNormal(vector3D, out m); pointCollection2 = new Ring(); for (int j = 0; j <= pointCount - 1; j++) { IPoint point3 = pointCollection.get_Point(j); point3.Z = num + modFacades.m_extrusionHeight; point3.M = 0.0; IClone clone = point3 as IClone; pointCollection2.AddPoint(clone.Clone() as IPoint, ref value, ref value); } IRing ring = pointCollection2 as IRing; ring.Close(); multiPatch = new MultiPatch() as IMultiPatch; geometryCollection2 = (multiPatch as IGeometryCollection); iZAware = (multiPatch as IZAware); iZAware.ZAware = true; iMAware = (multiPatch as IMAware); iMAware.MAware = true; geometryCollection2.AddGeometry(pointCollection2 as IGeometry, ref value, ref value); multiPatch.PutRingType(pointCollection2 as IRing, esriMultiPatchRingType.esriMultiPatchOuterRing); if (clsTextureGroup_0 != null) { element = modFacades.CreateElement(multiPatch, clsTextureGroup_0.RoofSymbol, string_0 + ";ROOFCOLOR=" + clsTextureGroup_0.RoofColorRGB.ToString()); } else { element = modFacades.CreateElement(multiPatch, null, string_0 + ";ROOFCOLOR=1"); } if (element != null) { groupElement2.AddElement(element); } } } } if (groupElement2 != null) { IElementProperties elementProperties = groupElement2 as IElementProperties; elementProperties.Name = string_0; } groupElement = groupElement2; result = groupElement; return(result); } catch { } result = groupElement; return(result); }
public static IMultiPatch Cylinder(IPoint ipoint_0, double double_0, double double_1, double double_2, double double_3, double double_4, bool bool_0, bool bool_1) { double num = 36.0; object value = Missing.Value; double num2 = (double_2 - double_1) / num; double num3 = double_2 - double_1; IMultiPatch multiPatch = new MultiPatch() as IMultiPatch; IGeometryCollection geometryCollection = multiPatch as IGeometryCollection; IPointCollection pointCollection = new TriangleStrip(); IVector3D vector3D = new Vector3D() as IVector3D; IEncode3DProperties encode3DProperties = new GeometryEnvironment() as IEncode3DProperties; for (double num4 = double_2; num4 <= double_1; num4 += -num2) { double num5 = Utils3D.DegreesToRadians(num4); vector3D.PolarSet(-num5, 0.0, double_0); IPoint point = new Point(); point.X = ipoint_0.X + vector3D.XComponent; point.Y = ipoint_0.Y + vector3D.YComponent; point.Z = double_3; double num6 = (num4 - double_1) / num3; if (bool_0) { num6 = 1.0 + num6 * -1.0; } if (num6 <= 0.0) { num6 = 0.001; } else if (num6 >= 1.0) { num6 = 0.999; } double textureT; if (bool_1) { textureT = 0.0; } else { textureT = 1.0; } double m = 0.0; encode3DProperties.PackTexture2D(num6, textureT, out m); point.M = m; pointCollection.AddPoint(point, ref value, ref value); IClone clone = point as IClone; IPoint point2 = clone.Clone() as IPoint; point2.Z = double_4; if (bool_1) { textureT = 1.0; } else { textureT = 0.0; } m = 0.0; encode3DProperties.PackTexture2D(num6, textureT, out m); point2.M = m; pointCollection.AddPoint(point2, ref value, ref value); } IGeometry2 inGeometry = pointCollection as IGeometry2; geometryCollection.AddGeometry(inGeometry, ref value, ref value); IZAware iZAware = multiPatch as IZAware; iZAware.ZAware = true; IMAware iMAware = multiPatch as IMAware; iMAware.MAware = true; return(multiPatch); }