Encode Expansions except MIDI Folder
-
Hi everyone, im building an instrument with a cool MIDI player but I want the chance to update and expand it with MIDI packs, with file based expansions is easy but with encoded expansions the plugin is reading only the embedded MIDI files even if I create the folder manually... Is there a way to encode the expansion without the MIDI folder or another solution to add MIDI packs in the future?
-
@Soundavid Can you load the MIDI files through the File/File System APIs?
-
@d-healey Thanks for answer, Im using the expansion.getMidiFileList(); to populate a viewport and loading the files to the MIDIplayer from here, how can I return the Midi List array from the File System?
-
@Soundavid Assuming the midi files are in the app data folder you can use
FileSystem.getFolder(FileSystem.AppData).getChildFile("My Midi Files");
Then you'll want to perform a search in that folder for the midi files usingfindFiles
-
@d-healey Thanks David! the midi Files are in the Expansion Folder, so the way to go is Expansion.getRootFolder(); instead AppData right? Im going to try returning the MIDI list with findFiles.
-
@Soundavid Yeah rootFolder would work. You can also get the expansions folder with FileSystem.Expansions - https://docs.hise.audio/scripting/scripting-api/filesystem/index.html
-
@d-healey Ok Im using this code but now there's nothing loading in the Viewport and get an error in the MIDIPlayer.setFile Function, all of this are in the Expansion Callback.
reg rootFolder = e.getRootFolder(); reg midiFolder = rootFolder.getChildFile("MidiFiles"); reg MIDIList = FileSystem.findFiles(midiFolder, ".mid", true); //reg MIDIList = e.getMidiFileList(); //Load Midi Files to Viewport MidiFileListViewPort.set("items", MIDIList.join("\n").replace(e.getWildcardReference("")).replace(".mid", ""));
-
@Soundavid Don't declare
reg
variables inside the expansion callback, usevar
. You're only providing the file extension as the wildcard, that means it will look for files called.mid
. You need to use*.mid
You should add some validation at each stage.
if (isDefined(e) { var rootFolder = e.getRootFolder(); if (isDefined(rootFolder) && rootFolder.isDirectory()) { var midiFolder = rootFolder.createDirectory("MidiFiles"); // Use createDirectory here and it will create the folder if it doesn't already exist. var files = FileSystem.findFiles(midiFolder, "*.mid", true); if (files.length > 0) { var list = []; for (x in files) { list.push(x.toString(x.FileName)); } MidiFileListViewPort.set("items", list.join("\n"); } } }
-
@d-healey Thanks David!! I was registering that variables because I needed the same MIDIList to load the Midi files into the Player, your method returns the whole path as String so I guess I need to use the .replace() function for the viewport items and think how can I load these in the MIDI Player, you definitely put me in the right direction for this
-
@Soundavid Declare the
list
variable as aconst
at the top of your namespace instead of thevar
, and uselist.clear()
before the loop that adds items to the list. Put your replace command in thelist.push
line.Also declare the
files
variable as areg
at the top of your namespace instead of thevar
. Then you'll have access to the files outside of this function.Another option entirely is to have two string arrays, one that contains the full paths and one that contains just the file names (for display). Then you can use the index of the name array to get the correct file path.
Lots of choices here!