Home › Forums › General › Programming › Help needed with replaceWithData
- This topic has 11 replies, 3 voices, and was last updated 11 years, 1 month ago by atom.
-
AuthorPosts
-
March 25, 2013 at 5:19 pm #7523
I’m stuck with replaceWithData.
My code is:
savePatchToDisk = function(modulator, newValue)
if modulator:isRestoring() then return end
if utils == nil then return end
file_name = “”
file_name = getCurrentPatchNameFromPanel()
data = getDataForSaving()
hex_string_data = convertToHexString(data)
mb = CtrlrLuaMemoryBlock()
mb:loadFromHexString(hex_string_data)
console(mb:toHexString(1))
my_file = utils.saveFileWindow (“save JX8P sysex file”, File(file_name) , “*.syx”, true)
if my_file ~= nil then –and my_file:existsAsFile() then
my_file:replaceWithData(mb)
end
modulator:setValue(0,false)
end
Can someone rewrite this so it works?
March 25, 2013 at 8:51 pm #7531hello
i unfortunatly i have the same problem , can t find a saving sysex methode that works.
March 25, 2013 at 9:07 pm #7532can you be more specific, what’s not working. what error do you get ?
March 26, 2013 at 1:36 pm #7558I’ve solved the problem,
Had to change mb = CtrlrLuaMemoryBlock() to mb = MemoryBlock()
Now I have a problem with the file naming.
When I take the property of a label as file name it also copy spaces like (BASS .syx) and
Ctrlr seems to forget the last used directory.
How can I remove the spaces in LUA and when saving the last used directory is chosen?
—script—
savePatchToDisk = function(modulator, newValue)
if newValue == 1 then
b = panel:getModulatorByName(“PATCH NAME”)
c = b:getComponent()
file_name = c:getProperty(“uiLabelText”)
f = utils.saveFileWindow (“Save JX8P Patch”, File(“”), “*.syx”, true)
f:create()
if f:existsAsFile() then
data = getDataForSaving()
hex_string_data = convertToHexString(data)
mb = MemoryBlock()
mb:loadFromHexString(hex_string_data)
–console(mb:toHexString(1))
f:replaceWithData(mb)
end
modulator:setValue(0,false)
end
end
March 26, 2013 at 1:56 pm #7559First of all why remove the spaces, they are valid filename characters. Second i think that the file class has a special method for that:
static String createLegalFileName (const String &fileNameToFix)
I see i bound it incorrectly, but it’s there, i’ll post a fix today evening so that it works and i’ll post an example on how to use that, though it should be as simple as
file_name = File.createLegalFileName (c:getProperty(“uiLabelText”))
March 26, 2013 at 2:05 pm #7560Thank you Atom,
I’ve seen that one but didn’t get it working.
Do you also know why the save window doesn’t remember the last used directory when I use the
label text property as file name?
This works normal:
f = utils.saveFileWindow (“Save JX8P Patch”, File(“”), “*.syx”, true)
This doesn’t:
b = panel:getModulatorByName(“PATCH NAME”)
c = b:getComponent()
file_name = c:getProperty(“uiLabelText”)
f = utils.saveFileWindow (“Save JX8P Patch”, File(file_name), “*.syx”, true)March 26, 2013 at 2:19 pm #7561If you pass a file_name as the second paraamter, it’s just the file name, it contains no directory information, you’d need to pass the full absolute path in order for the dialog to show that directory initially.
March 26, 2013 at 2:24 pm #7562Can I get the last used directory with some code instead of a absolute path?
This would make it more easy for the user.
March 26, 2013 at 2:40 pm #7563You’d need to save it yourself in a variable, that’s the simplest way, and use that. Create a function wrapper for the save dialog window that stores the last browsed path in a variable (remember all variables in Lua are global) and uses that whenever it’s called.
March 26, 2013 at 2:58 pm #7564Haha I really don’t understand what you are writing 😉
March 26, 2013 at 3:10 pm #7565You’re lucky i’m bored at work for now, here is a function that will ask for a file to save, remember the last directory the file was saved in, it returns the file chosen by the user in the dialog.
function saveFile(suggestedFileName) -- Your method code here if lastBrowsedDir ~= nil then result = utils.saveFileWindow (suggestedFileName, lastBrowsedDir, "*.syx", true) else -- since the is no last save directory, let's default to the user's home directory result = utils.saveFileWindow (suggestedFileName, File.getSpecialLocation(File.userHomeDirectory), "*.syx", true) end -- save the last directory the user save the file into for later lastBrowsedDir = result:getParentDirectory() return (result) end
March 26, 2013 at 11:05 pm #7597you can now use the method mentioned, so you can create file names without spaces and only with allowed characters like this:
illegalFileName = "This is a illegal file name. Or is it?.txt" legalFileName = String(File.createLegalFileName(illegalFileName)):replace(" ", "_", false)
if you paste that in the Lua console you’ll get
>>> illegalFileName = "This is a illegal file name. Or is it?.txt" legalFileName = String(File.createLegalFileName(illegalFileName)):replace(" ", "_", false) console (legalFileName) This_is_a_illegal_file_name._Or_is_it.txt
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.