Audio Render not working as expected
-
Messing around with the audio render snippet example in the snippet browser....works fine in the example...but when I bring it into my project...it doesn't render anything but dead space...and then the audio in HISE becomes completely disabled and I have to restart to get it back working....im trying to get it to render a preloaded midi file instead of the one that's created by the example...here's the code ive added in the attempt to make it work....
Content.makeFrontInterface(510, 160); const var DELETE_TEMP_FILE = false; const var SeqView = Content.addPanel("SeqView", 0, 90); SeqView.set("width", 210); const var AudioDragger = Content.addPanel("Dragger", 0, 32); AudioDragger.set("width", 210); AudioDragger.set("allowCallbacks", "Clicks & Hover"); const var MidiPlayer = Synth.getMidiPlayer("MIDI Player1"); AudioDragger.setMouseCallback(function(event) { this.data.hover = event.hover; this.repaint(); if (event.clicked) { if (isDefined(this.data.tempFile)) { var fToDelete = this.data.tempFile; this.startExternalFileDrag(this.data.tempFile, true, function [fToDelete]() { if (DELETE_TEMP_FILE) { Console.print("DELETE " + fToDelete.toString(0)); fToDelete.deleteFileOrDirectory(); } }); } else { Console.print("! You need to click on render first."); } } }); // Button to Begin Rendering const var Button1 = Content.addButton("Button1", 0, 0); Button1.set("text", "Render"); Button1.set("isMomentary", true); Button1.set("saveInPreset", false); Button1.set("width", 210); Button1.setControlCallback(onButton1Control); inline function onButton1Control(component, value) { if (value) { if (!MidiPlayer.isEmpty()) { Console.print("MIDI Player has a sequence loaded."); local eventList = MidiPlayer.getEventList(); Console.print("Event list size: " + eventList.length); if (eventList.length == 0) { Console.print("! Event list is empty. Cannot render."); return; } // Add a stop event at the end local timeSig = MidiPlayer.getTimeSignature(); local length = timeSig.NumBars * timeSig.Nominator * (timeSig.Denominator / 4.0) * timeSig.LoopEnd; local ts = Engine.getSamplesForQuarterBeats(length); local stopEvent = Engine.createMessageHolder(); stopEvent.setType(3); stopEvent.setChannel(1); stopEvent.setControllerNumber(1); stopEvent.setControllerValue(0); stopEvent.setTimestamp(ts); eventList.push(stopEvent); Console.print("Added stop event at timestamp: " + ts); // Render the audio Console.print("Rendering audio..."); Engine.renderAudio(eventList, COMPOSER_RenderAudioCallback); } else { Console.print("! No MIDI file is loaded in the MIDI Player."); } } } inline function COMPOSER_RenderAudioCallback(obj) { local isFinished = obj.finished; local progressPoint = obj.progress; if (isFinished) { Console.print("Rendering complete."); local bufferDataToWrite = obj.channels; local audioFilesDirectory = FileSystem.getFolder(FileSystem.Temp); local fileToExport = audioFilesDirectory.getChildFile("export_temp.wav"); if (!isDefined(bufferDataToWrite[0].length)) { fileToExport.writeAudioFile([bufferDataToWrite], Engine.getSampleRate(), 24); } else { fileToExport.writeAudioFile(bufferDataToWrite, Engine.getSampleRate(), 24); } Console.print("Audio file exported to: " + fileToExport.toString(0)); AudioDragger.data.tempFile = fileToExport; enableBroadcaster.sendAsyncMessage([true]); } else { Console.print("Progress: " + progressPoint); } } // Visualize MIDI Sequence SeqView.setPaintRoutine(function(g) { g.fillAll(0x11FFFFFF); var displayArea = this.getLocalBounds(0); var noteRectangleList = MidiPlayer.getNoteRectangleList(displayArea); g.setColour(Colours.white); for (noteRectangle in noteRectangleList) { g.fillRect(noteRectangle); } }); // Broadcaster definition const var enableBroadcaster = Engine.createBroadcaster({ "id": "enableBroadcaster", "args": ["shouldBeEnabled"], "tags": [] }); enableBroadcaster.addComponentPropertyListener(["Dragger"], ["enabled"], "set the enabled state for the dragger", function(index, shouldBeEnabled) { return shouldBeEnabled; }); enableBroadcaster.addComponentPropertyListener(["Dragger"], ["text"], "update the text", function(index, shouldBeEnabled) { return shouldBeEnabled ? "Drag to waveform or external target" : "Press render"; }); enableBroadcaster.addComponentRefreshListener(["Dragger"], "repaint", "repaint"); enableBroadcaster.sendAsyncMessage([false]); inline function drawDragPanel(g) { g.fillAll(0x22FFFFFF); g.setColour(this.data.hover ? Colours.white : 0xBBFFFFFF); if (!this.get("enabled")) g.setColour(0x44FFFFFF); g.setFont("Default", 14.0); g.drawAlignedText(this.get("text"), this.getLocalBounds(0), "centred"); } AudioDragger.setPaintRoutine(drawDragPanel);
-
-
@clevername27 any thoughts?
-
@johnmike Hi John, this is an excellent question - I'm on deadline for a massive project, and will get back with you later in the week with my code. Cheers.