December 21, 2012 at 3:22 am #5234December 21, 2012 at 10:43 am #5235
myData is a MemoryBlock not a String you can’t just dump binary data to the console, there is no defined conversion operator for such an action.December 21, 2012 at 12:36 pm #5237
Also try to loose “Lua” try to use getData(), all those CtrlrLua and Lua prefixes etc. are deprecated.
Think of getData() or getByte() or getRange() as a way to fetch a piece of memory, and that piece is just a set of bits. No one knows but you how to put those bits in groups. 8bits is a byte, and that can represent a ASCII character or not, it might be 16bits 32bits or whatever, you need to know what does your memory represent.
The method toHexString() takes the bits, splits them up as bytes and prints the value of each byte in hexadecimal notation. Nothing else.December 21, 2012 at 7:51 pm #5247
thanks atom. The goal here is to write the contents of midiMessage:getLuaData():getRange(7,262) to a file.
I’m assuming that must start with:
myData = midiMessage:getLuaData():getRange(7,262)
myDataHexString = toHexString(myData)
I’m unclear what my next steps must be. I have the above lines on my midiMessageReceived script, I want the user to be able to press a button that allows them to dave the contents of “myData” to a filename/location they specify with a file type .data. I’m not sure how to go about coding the script for the save button that will save the contents of “myDataHexString” to a file
I seem to recall making this work somehow a while back on a test panel but now it seems things have changed so my old code doesn’t work at all.
any assistance would be greatly appreciated.December 21, 2012 at 9:51 pm #5250
Putting a block of data to a file should be as easy as
data = midiMessage:getLuaData() -- or getLuaData():getRange(0,24) etc. file = File("c:\\myfile.syx") file:replaceWithData(data)
that’s it the file c:\\myfile.syx should contain whatever is in the MemoryBlock (data)December 21, 2012 at 10:12 pm #5251December 21, 2012 at 10:19 pm #5252
file = File("c:\\myfile.syx")
file = utils.saveFileWindow ("Save data", File.getSpecialLocation(File.userHomeDirectory), "*.syx;*.dat", true)December 24, 2012 at 4:15 am #5266
I’m almost there… can write the block to a file but the file is just a bunch of gibberish when I open it..
Trying to get toHexString to work but I’m just getting
“attempt to call global ‘toHexString’ (a nil value).
Where’s the API? that’d help a lot. otherwise I’m just taking shots in the dark.
Right now, here’s what I’ve got on my getWCT script (along with all the other code that deals with each byte – all working well)
WCTData = midiMessage:getData():getRange(7,262)
Then on my “save Wavetable” button (saves the WCTdata) I’ve got:
saveWavetable = function(mod, value)
WCTDataHexString = toHexString(WCTData, 0)
file = utils.saveFileWindow ("Save data", File.getSpecialLocation(File.userHomeDirectory), "*.mwt", true)
If I change that last line to WCTData instead of WCTDataHexString I do get a file but it’s not how I want it – like you said I’m looking for each byte is 7 bits (00h – F7h) I want my .mwt file to contain hex values.. If I’m understanding you correctly “toHexString” should do that but I’m not getting it to work at all.December 24, 2012 at 9:16 am #5267
since you want to write a String not a MemoryBlock you should propablu use http://www.rawmaterialsoftware.com/juce/api/classFile.html#ab3476536a97b787f00b5988cdb326816 use the right method for the right data type. Like i wrote i’m copying the classes from JUCE 1:1 unless told otherwise. The classes File/MemoryBlock are the same (except the MemoryBlock void * arguments that can’t be void *, instead another MEmoryBlock is used as an argument)
- The forum ‘Programming’ is closed to new topics and replies.