Helper Function Logic....Placement?
-
@d-healey Heres my exact use case...
I have a file drop panel that saves a copy of a midi files to the app data folder.
I just want the combobox to reflect the added items.I tried adding namespace.updateMidiFilesComboBox();
and
just .updateMidiFilesComboBox();
but both give the error that '.updateMidiFilesComboBox' expression is not a function (both ways)
hence me trying to figure out how to jump around namespaces rn...
I've tried calling this function FROM the end of the panel drop function but that gives the same error hence me trying a timer callback.// This is in a namespace const var appDataDir2 = FileSystem.getFolder(FileSystem.AppData); var midiFiles = FileSystem.findFiles(appDataDir2, "*.mid", false); cmbMidiFiles.set("items", ""); inline function updateMidiFilesComboBox() { for (i = 0; i < midiFiles.length; i++) { Console.print(midiFiles[i]); cmbMidiFiles.addItem(midiFiles[i].toString(Filename).replace("/Users/user/Library/Application Support/MANGO WORLD/KEYZIE V29/", "").replace(".mid")); } Console.print("PANEL MIDI MIDI" + trace(pnlMIDIFiles)); } updateMidiFilesComboBox();
//this is in onInit const var midiComboBoxTimer = Engine.createTimerObject(); midiComboBoxTimer.setTimerCallback(function(component, value) { updateMidiFilesComboBox(); }); midiComboBoxTimer.startTimer(200);
-
C Chazrox marked this topic as a question
-
@Chazrox what's the timer for? Show me where you're calling it after the file drop.
-
@d-healey
The timer is just a hacky attempt to see if I can get it to work.Im trying to get my combobox to update after a drop a new file. The combobox searches the appData folder for .mid files and populates the combobox items list.
I want it to happen here somewhere. Someplaces I drop it, it doesnt do anything...in another spot, it duplicates everything in the combobox like 3-4 times and if I keep going it just stacks up.
can you suggest where to put .updateMidiFilesComboBox(); ?
inline function onpnlMIDIFilesFileDrop_B(obj) { //Console.print(trace(obj) + "TRACE TRACE TRACE"); // HOVER STATE local prevHover = this.data.hover ? 1 : 0; this.data.hover = (obj.hover && !obj.drop) ? 1 : 0; if ((this.data.hover ? 1 : 0) != prevHover) { this.repaint(); } // HOVER CHECK if (obj.hover && !obj.drop) { this.data.text = "Drop to load!"; this.data.dropped = false; this.changed(); return; } if (!obj.drop || obj.fileName == undefined) { return; } // PARSE BASE NAME local full = obj.fileName; local slash = Math.max(full.lastIndexOf("/"), full.lastIndexOf("\\")); local dot = full.lastIndexOf("."); //============ Console.print("full contains:" + full); //============= if (dot < 0) { dot = full.length; } local base = full.substring(slash + 1, dot); this.data.filename = base; // paint() this.data.fileName = base; // sync Console.print("BASE__" + base); // HIDE RANGE SLIDER WHILE NO EVENTS RangeSlider.set("visible", 0); // LOAD MIDI PLAYER TRACK 1 MIDIPlayer1.setFile(full, true, true); if (MIDIPlayer1.setTrack != undefined) MIDIPlayer1.setTrack(1); // START POLLING EVENTS midiRangeTimer.stopTimer(); midiRangeTimer.startTimer(50); // ----------------------------------------------------------- // COPY DROPPED FILE INTO AppData // ----------------------------------------------------------- local original = FileSystem.fromAbsolutePath(full); //=========== Console.print("Original contains:" + original); Console.print("Original is defined ==:" + (original != undefined)); Console.print("Original is a file ==:" + (original != undefined)); //=========== local filename = full.substring(slash + 1 ); if (original != undefined) { Console.print(filename + "IS DEFINED"); Console.print("ORIGINAL__" + original); local appDataDir = FileSystem.getFolder(FileSystem.AppData); local newFile = appDataDir.getChildFile(base + ".mid"); original.copy(newFile); newFile.move(appDataDir); Console.print("NEWNEWNEW" + newFile); Console.print("Saved copy to AppData: " + base); } setAnalysisWindowFull(); disableAllChords(); disableAllChords(); // UI flags this.data.text = "Loaded"; this.data.dropped = true; this.data.hover = false; this.changed(); this.repaint(); knbSmartStrength.changed(); pnlCustomMidiPanel.sendRepaintMessage(); pnlCustomMidiRipView.sendRepaintMessage(); Console.print("DROP PANEL B WAS USED"); }
-
@Chazrox said in Helper Function Logic....Placement?:
this.data.filename = base; // paint()
this.data.fileName = base;What's going on here?
@Chazrox said in Helper Function Logic....Placement?:
disableAllChords();
disableAllChords();And here?
I think you need to start by breaking that massive function into smaller more manageable sub functions. It's too chaotic at the moment.
-
-
@d-healey said in Helper Function Logic....Placement?:
What's going on here?
setting panel data for other functions to read like my paint functions.
its a mess in here at the moment. but i'll def clean it up. i've been doing the most trying to fix this but im def making a mess.
-
@Chazrox Yeah clean it up, remove the duplication, then we'll work on the combo box
-
@d-healey I figured it out and it only took reading the entire script from top to bottom an back all the way up to the top to find this....
I changed the namespace name and now everything works fine. dang I hate when its something like this. Thanks for the help!
**This just raised a question as well.... if the name of the external file and the name of the namespace doesnt have to be the same, that would make a namespace just a holder of some sort?
and/or I just dont know enough about includes.
-
C Chazrox has marked this topic as solved
-
@Chazrox said in Helper Function Logic....Placement?:
This just raised a question as well.... if the name of the external file and the name of the namespace doesnt have to be the same, that would make a namespace just a holder of some sort?
The two are unrelated, you can have multiple namespaces in a single file if you wanted to.
-