bool IMenuStripManagerHandler.ExecuteMenuItem(MenuStripManager menuStrip, ToolStripMenuItem menuItem) { if (menuItem == menuStrip.buildObjectToolStripMenuItem) { BuildThis(true /*force*/); return(true); } else if (menuItem == menuStrip.disassembleToolStripMenuItem) { DisassembleThis(); return(true); } else if (menuItem == menuStrip.openAsSampleToolStripMenuItem) { if (BuildThis(false /*force*/)) { NumBitsType numBits = NumBitsType.Max; float[] buffer = (float[])algoSampObject.SampleData.Buffer.Clone(); SampConv.QuantizeAndClampVector(buffer, numBits); // ensure target bit depth is honored SampleObjectRec sampleObject = new SampleObjectRec( mainWindow.Document, buffer, algoSampObject.SampleData.NumFrames, numBits, algoSampObject.NumChannels, algoSampObject.Origin, algoSampObject.LoopStart1, algoSampObject.LoopStart2, algoSampObject.LoopStart3, algoSampObject.LoopEnd1, algoSampObject.LoopEnd2, algoSampObject.LoopEnd3, algoSampObject.SamplingRate, algoSampObject.NaturalFrequency); sampleObject.Name = String.Format("Copy of {0}", algoSampObject.Name); mainWindow.Document.SampleList.Add(sampleObject); new SampleWindow(registration, sampleObject, mainWindow).Show(); } return(true); } else if (menuItem == menuStrip.deleteObjectToolStripMenuItem) { Close(); mainWindow.DeleteObject(algoSampObject, mainWindow.Document.AlgoSampList); return(true); } return(false); }
bool IMenuStripManagerHandler.ExecuteMenuItem(MenuStripManager menuStrip, ToolStripMenuItem menuItem) { if (menuItem == menuStrip.buildObjectToolStripMenuItem) { BuildThis(true /*force*/); return(true); } else if (menuItem == menuStrip.disassembleToolStripMenuItem) { DisassembleThis(); return(true); } else if (menuItem == menuStrip.openAsWaveTableToolStripMenuItem) { if (BuildThis(false /*force*/)) { float[] raw = algoWaveTableObject.WaveTableData.GetRawCopy(); SampConv.QuantizeAndClampVector(raw, algoWaveTableObject.WaveTableData.NumBits); // ensure target bit depth is honored WaveTableObjectRec waveTableObject = new WaveTableObjectRec( mainWindow.Document, new WaveTableStorageRec( algoWaveTableObject.WaveTableData.NumTables, algoWaveTableObject.WaveTableData.NumFrames, algoWaveTableObject.WaveTableData.NumBits, raw)); waveTableObject.Name = String.Format("Copy of {0}", algoWaveTableObject.Name); mainWindow.Document.WaveTableList.Add(waveTableObject); new WaveTableWindow(registration, waveTableObject, mainWindow).Show(); } return(true); } else if (menuItem == menuStrip.deleteObjectToolStripMenuItem) { Close(); mainWindow.DeleteObject(algoWaveTableObject, mainWindow.Document.AlgoWaveTableList); return(true); } return(false); }
public override int ReadPoints(float[] data, int offset, int count) { if (truncated && !allowTruncated) { throw new InvalidDataException(); } int frames = Math.Min(remainingFrames, count / PointsPerFrame); remainingFrames -= frames; int points = frames * PointsPerFrame; int bytesPerFrame = 0; switch (numBits) { default: Debug.Assert(false); throw new InvalidOperationException(); case NumBitsType.eSample8bit: bytesPerFrame = 1; break; case NumBitsType.eSample16bit: bytesPerFrame = 2; break; case NumBitsType.eSample24bit: bytesPerFrame = 3; break; } bytesPerFrame *= PointsPerFrame; if (buffer.Length < bytesPerFrame * frames) { buffer = new byte[bytesPerFrame * frames]; } int p = 0; int c; while ((c = stream.Read(buffer, p, bytesPerFrame * frames - p)) != 0) { p += c; } if (p != bytesPerFrame * frames) { truncated = true; if (!allowTruncated) { throw new AudioFileReaderException(AudioFileReaderErrors.Truncated); } Array.Clear(buffer, p, bytesPerFrame * frames - p); } using (Stream dataStream = new MemoryStream(buffer, 0, bytesPerFrame * frames)) { using (BinaryReader dataReader = new BinaryReader(dataStream)) { switch (numBits) { default: Debug.Assert(false); throw new InvalidOperationException(); case NumBitsType.eSample8bit: for (int i = 0; i < points; i++) { data[i + offset] = SampConv.SignedByteToFloat(dataReader.ReadByte()); } break; case NumBitsType.eSample16bit: for (int i = 0; i < points; i++) { data[i + offset] = SampConv.SignedShortToFloat(dataReader.ReadInt16()); } break; case NumBitsType.eSample24bit: for (int i = 0; i < points; i++) { data[i + offset] = SampConv.SignedTribyteToFloat(dataReader.ReadInt24()); } break; } } } return(points); }
private void Eval() { if (!mainWindow.MakeUpToDate()) { return; } int ErrorLineNumberCompilation; DataTypes ReturnType; PcodeRec FuncCode; Compiler.ASTExpression AST; CompileErrors CompileError = Compiler.CompileSpecialFunction( mainWindow.Document.CodeCenter, new FunctionParamRec[] { new FunctionParamRec("frames", DataTypes.eInteger), new FunctionParamRec("tables", DataTypes.eInteger), new FunctionParamRec("data", DataTypes.eArrayOfFloat), }, out ErrorLineNumberCompilation, out ReturnType, textBoxFormula.Text, false/*suppressCILEmission*/, out FuncCode, out AST); if (CompileError != CompileErrors.eCompileNoError) { textBoxFormula.Focus(); textBoxFormula.SetSelectionLine(ErrorLineNumberCompilation - 1); textBoxFormula.ScrollToSelection(); LiteralBuildErrorInfo errorInfo = new LiteralBuildErrorInfo(Compiler.GetCompileErrorString(CompileError), ErrorLineNumberCompilation); MessageBox.Show(errorInfo.CompositeErrorMessage, "Error", MessageBoxButtons.OK); return; } using (ParamStackRec ParamList = new ParamStackRec()) { int numFrames = waveTableObject.WaveTableData.NumFrames; int numTables = waveTableObject.WaveTableData.NumTables; float[] vector = new float[numFrames * numTables]; ArrayHandleFloat dataHandle = new ArrayHandleFloat(vector); int initialCapacity = 1/*frames*/ + 1/*tables*/ + 1/*data*/ + 1/*retaddr*/; ParamList.EmptyParamStackEnsureCapacity(initialCapacity); ParamList.AddIntegerToStack(numFrames); ParamList.AddIntegerToStack(numTables); ParamList.AddArrayToStack(dataHandle); ParamList.AddIntegerToStack(0); /* return address placeholder */ for (int i = 0; i < numTables; i++) { WaveTableStorageRec.Table table = waveTableObject.WaveTableData.ListOfTables[i]; for (int j = 0; j < numFrames; j++) { vector[i * numFrames + j] = table[j]; } } CodeCenterRec CodeCenter = mainWindow.Document.CodeCenter; EvalErrInfoRec ErrorInfo; EvalErrors EvaluationError = PcodeSystem.EvaluatePcodeThread.EvaluatePcode( ParamList, FuncCode, CodeCenter, out ErrorInfo, new PcodeExterns(mainWindow)); if (EvaluationError != EvalErrors.eEvalNoError) { PcodeEvaluationErrorInfo errorInfo = new PcodeEvaluationErrorInfo( EvaluationError, ErrorInfo, FuncCode, CodeCenter); MessageBox.Show(errorInfo.CompositeErrorMessage, "Error", MessageBoxButtons.OK); return; } Debug.Assert(ParamList.GetStackNumElements() == initialCapacity); // args - retaddr + return value #if DEBUG ParamList.Elements[2].AssertFloatArray(); #endif dataHandle = ParamList.Elements[2].reference.arrayHandleFloat; WaveTableStorageRec NewTable = new WaveTableStorageRec(numTables, numFrames, waveTableObject.WaveTableData.NumBits); float[] NewData = dataHandle.floats; if (NewData.Length != numTables * numFrames) { PcodeEvaluationErrorInfo errorInfo = new PcodeEvaluationErrorInfo( "<anonymous>", PcodeSystem.GetPcodeErrorMessage(EvalErrors.eEvalArrayWrongDimensions), 1); MessageBox.Show(errorInfo.CompositeErrorMessage, "Error", MessageBoxButtons.OK); return; } SampConv.QuantizeAndClampVector(NewData, NewTable.NumBits); for (int i = 0; i < numTables; i++) { WaveTableStorageRec.Table table = NewTable.ListOfTables[i]; for (int j = 0; j < numFrames; j++) { table[j] = NewData[i * numFrames + j]; } } undo.Push(waveTableObject.WaveTableData); redo.Clear(); waveTableObject.WaveTableData = NewTable; } }