Download progress bar
-
hey good folks...working on building a downloader following @d-healey's amazing tutorial...got it working but curious now as to how I can show a progress bar that simply shows the progress of the download, how much is left and when it's complete(what I see in the server controller minus the URL)
and secondly I'm just really learning how to work with the filesystem API...is there a way to allow the end user to choose what folder they want to save the file to once they click the "start" button?
want to make a simple downloader for an end user to add new samples to an existing samples folder
-
FileSystem.browseForDirectory(var startFolder, var callback)
https://docs.hise.audio/scripting/scripting-api/filesystem/index.html#browsefordirectory
-
You can check the download's progress in the download callback and use it to draw a progress bar in a panel's paint routine.
https://docs.hise.audio/scripting/scripting-api/server/index.html#downloadfile
https://docs.hise.audio/scripting/scripting-api/download/index.html
-
@Lindon said in Download progress bar:
FileSystem.browseForDirectory(var startFolder, var callback)
https://docs.hise.audio/scripting/scripting-api/filesystem/index.html#browsefordirectory
I get the console error "Found 'var' when expecting an expression"
-
@johnmike Post your code
-
const url = "https://www.dropbox.com/s/wldq9cxssx3cif7/Screen%20Shot%202022-11-17%20at%205.34.44%20PM.png?dl=1"; const downloadsFolder = FileSystem.browseForDirectory(var startFolder, var callback); reg pause = false; reg abort = false; reg download; Server.cleanFinishedDownloads(); // btnStart const btnStart = Content.getComponent("btnStart"); btnStart.setControlCallback(onbtnStartControl); inline function onbtnStartControl(component, value) { if (value) { startDownload(); } } // btnPause const btnPause = Content.getComponent("btnPause"); btnPause.setValue(0); btnPause.set("text", "Pause"); btnPause.setControlCallback(onbtnPauseControl); inline function onbtnPauseControl(component, value) { if (value) pauseDownloads(); else resumeDownloads(); value == 0 ? component.set("text", "Pause") : component.set("text", "Resume"); } // btnAbort const btnAbort = Content.getComponent("btnAbort"); btnAbort.setControlCallback(onbtnAbortControl); inline function onbtnAbortControl(component, value) { if (value) { abortDownloads(); } } // Functions inline function startDownload() { pause = false; abort = false; Server.setBaseURL("https://"); local f = downloadsFolder.getChildFile("test.png"); download = Server.downloadFile(url.replace("https://"), {}, f, downloadCallback); } function downloadCallback() { if (abort) this.abort(); else if (pause) this.stop(); if (this.data.finished && !pause) { Console.print(this.data.success ? "Done" : "Fail"); } } inline function pauseDownloads() { pause = true; } inline function resumeDownloads() { pause = false; download.resume(); } inline function abortDownloads() { pauseDownloads(); Engine.showYesNoWindow("Cancel Download", "Are you sure you want to cancel the download?", function(response) { if (response) { pause = false; abort = true; download.abort(); } else { resumeDownloads(); } }); } ``
-
@johnmike Ah ok, Lindon was just showing you which function is used to open a file browser https://docs.hise.audio/scripting/scripting-api/filesystem/index.html#browsefordirectory
There are many ways to implement it. Usually in a button callback.
-
@d-healey ok I can do a deeper dive when I have more time to experiment and wrap my head around the file system stuff... but here's a snippet of where im at now... I just want to connect this progress bar in the panel to the download progress...
HiseSnippet 1772.3ocsX0naaTDD9bZOfyPQfDO.KVpnKf6kytITfnRy+PDMAq31BnR.s4t01q55cM2tNIVUQhGMdD3Qg2.Xl890NmSQQfijysyO67MyNyb63dIpHlVqRbZ38rYSXNMdO29yjlQ6NhxkNGtGRXO0ERghFyRb1Y1DpVyhcZz3NeCJQCu65X+7WOYGpfJiXkjbbdghGwdJeL2TRs2VeGWHN.1tmwGWQ5025vHkbWkPMEPycbCclPidEcH6XJJ1JtNMdq8i4FUReC0vzNMt6Np3Y8GAnKU9Wv07yDLbQGm9vFkR9.kHFQLR0Y2QbQbubuV6.6RuxXvcRiAej6Q7XdA8xXwGXYPJ0nZ7nwJyCu6LG75TEdgUfWMPpQEHc2TH8gt8iR3SLkbP77ttGJMrjATHrWEJox5rxO9tt6p.IjlfwzWwNHAVTng+mGF1l.es5lMaBgdsgLMQPdLoUbhZxYpKChTiWSu1Eh3e6KitTqu7gQ7AOZMXyYL486FB9lA9G7W2GzoyC57HXAEorQvCWOX80gm5cTvD4vmDKdbmValYj3rzIs8fIAL3AbAq+LsgMNXHyjR1uBw7DPMhzD1PxD5TMCTb.UnYaZIQOSkXlmTtg.k5yRNmkDDIXT4AbIWOhEWrq931t1ZjyLR3rKwjgy7kvllGDAzsqZ7DkDV32JWfVf94OGnQQjlDkXWpPbFjB6qj4by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uHEEDtW97W12c4W1u5rHQoUyUDTIOTxMe+DlbYSn3j0B.d54GtG7h.bBgLZfbSXIFNBgF6wNGF2JcdAO28X5WAu4APZQeCmFuiwx88yllXmoFiR5vggFZ5le+SmKKGJauslUt33sv6+3z3scSkiqORMF1VZxrTryjTvmwQjdJiljMUlldN6PYOnNlYxm3oDPu0MCH6MwVFf9iet.Poxcyl5M361aPsLSsEqvTox8egu+1o.5d4i1QkLgEO2ysRyuJP52OoBj9SyVWfMvJ495sFYaYU5B+RFpuma9tsCMAFA+ZiWBC1phmJnl4m1EGwOiATUL2Hl3XjRM2Lq5OAv+Yi.+uEhenaOtIZT8XbkZvHT67+AFy9gCtm69CF.8bKA3ccO3G++4WIvI8kgCOhZR3PNh6wSG2GZBGw.qKgTIrqTiUv9GoqCw0XDnOSFaW72vmLlcv0MxX1ImoyXZTh5WiR6Eh+zDuikBfIo8Wkwy8HbMoiis+HnmaXPnyXnL3WihP2+APKs50o6sPmGdKzY8agNabKz4yuE57nagNewMpC1AZ6oF03zxAfPu8suznQi8ssnrYgN+C..EdSD
-
@johnmike You don't need to use a timer for this. In the download callback you can get the progress of the download (see the link I posted before) which returns a value between 0 and 1. Set this as your progress bar panel's value and trigger a repaint. In the panel's paint routine you can use this value as the multiplier for the width of the progress indicator.
-
@d-healey I know it's something obvious that im missing...im very much still wrapping my head around all this...plus im more of a Kinesthetic learner...ive gotten as far as I have watching your vids and learning from recipes and various snippets posted here....I subscribed to your Patreon so I've been digging around over there...plan on just getting your Hise masterclass soon...but the way my life is setup now I just don't have the time to really dig my heels in to make this work...I just need a simple progress bar added to this...Just want the end user to click start on the downloader and see the progress of the download and when it finishes...Im willing to pay you to do it(simple as it may be) Its a small part of a larger project im working on and I don't want to sink too much time getting stuck here trying to learn the panel paint routines...
HiseSnippet 1804.3ocsX0uaaTrEecZWtcMTDHwCvfkJZC3twNMkBD0ay2WhnIXEWJbUIflr6X6Qc7L9NyXmXEEIz8etuV7HviBuAbOmY+vqcVmVEUbk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qz0sv0XDnKSl3V7WvuLlsw00xX1Nmo2PZrV8qwoyfwuKx8bT.LIceRn.+iv0j1dt4xfd9shZ4MDZC903Xz8eHLJsZcV+VnyitE5rwsPmGeKz4KuE57jagNe0MpCNAZ6wV0vz1AfPm8curpVs8cinbUgd+emYA49.
-
If anyone could help I'd gladly buy your lunch tomorrow or a beer for the weekend he he! LBVS...
-
@johnmike said in Download progress bar:
I don't want to sink too much time getting stuck here trying to learn the panel paint routines...
You've already got the paint routine. You just need to use the download progress from the download callback as the panel's value instead of setting it in a timer.
It's almost identical to what you have already. In your download callback you use
this.getProgress()
which will give you a value between 0 and 1. You assign this as the panel's value, then you call repaint, just like you're doing in your timer.Then in the paint routine, instead of
v = this.getValue() / 10
you can just havev = this.getValue();
. -
@d-healey like so? ```
// pnlProgress Content.getComponent("pnlProgress"); pnlProgress.setValue(0); this.getProgress(); var x = this.getValue(); x = (x + 1) % 11; this.setValue(x); this.repaint(); pnlProgress.setPaintRoutine(function(g) { g.fillAll(Colours.black); var a = [this.getWidth() / 2 - 400 / 2, this.getHeight() / 2 - 20 / 2, 400, 20]; g.setColour(Colours.darkgrey); g.fillRoundedRectangle(a, 5); var v = this.getValue(); g.setColour(Colours.white); g.fillRoundedRectangle([a[0], a[1], a[2] * v, a[3]], 5); v > 0.52 ? g.setColour(Colours.black) : g.setColour(Colours.lightgrey); g.drawAlignedText(v * 100 + "%", a, "centred"); }); }
I'm still not seeing it do anything...where do I assign the panel's value? I appreciate you helping me...
-
@johnmike The first snippet you posted, did you write that code?
-
@d-healey yea but did so following your downloader tutorial and your panel timer tutorial on your Patreon just typing it in as you went...but my 40-year old brain isn't making the connection between the 2 yet ha ha
-
so I did both separate and then copied and pasted one into the other
-
@johnmike Ah copy and paste to create a Frankenstein code is always dangerous :)
The download callback is the part that starts with
function downloadCallback()
Inside the download callback you need to get the progress of the download and assign it as the panel's value. This is pretty much the same as you are doing in your timer callback, except there you are using
x
. Then you need to call the panel's repaint function.The paint routine is the part that starts with
pnlProgress.setPaintRoutine(function(g)
In the paint routine you just need to do what I said in my last post :)
I could do this for you, but then you will come back with more questions when you want to change something or you find a bug. You need to be in control of your own script.
-
Ok gonna try this and go back to the "drawing" board again!
I could do this for you, but then you will come back with more questions when you want to change something or you find a bug. You need to be in control of your own script.
Absolutely! I totally get it!I taught music for almost 15 years before I started my online business...this is like learning scales all over again lol! The student wants you to just jump and show them the sexy jazz chords and runs...but hasn't yet fully learned the theory and foundation behind those chords/runs...which would make them a better and more skilled Musician being able to create and imagine their own chords/runs...I get it lol
-
@johnmike Ok well you cant just copy and paste code out of the documentation and expect it to work...
FileSystem.browseForDirectory(var startFolder, var callback)
- you need to specify a value for startFolder, even an empty string will do
- you need to define a function for callback, that function will need a single param called result -this will be a file object, in this case a Directory - that you can manipulate and check in your function...
// get the folder WeDontUSeThis = FileSystem.browseForDirectory("", function(result){ MyDownloadFolderString = result.toString(FullPath); Console.print( MyDownloadFolderString); });