Home › Forums › General › Programming › printing getLuaData() in console
- This topic has 8 replies, 2 voices, and was last updated 11 years, 3 months ago by atom.
-
AuthorPosts
-
December 21, 2012 at 3:22 am #5234
myData = midiMessage:getLuaData():getRange(7,262)
console(“my data looks like = “..myData) –doesn’t work!?
Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen
December 21, 2012 at 10:43 am #5235myData 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 #5237Also 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 #5247thanks 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 fileI 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.
Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen
December 21, 2012 at 9:51 pm #5250Putting 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 #5251very cool. thanks atom.
But how do I allow the user to pick the destination and file type instead of defaulting to C:\\myfile.syx?
Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen
December 21, 2012 at 10:19 pm #5252instead of
file = File("c:\\myfile.syx")
do
file = utils.saveFileWindow ("Save data", File.getSpecialLocation(File.userHomeDirectory), "*.syx;*.dat", true)
December 24, 2012 at 4:15 am #5266I’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)
file:replaceWithData(WCTDataHexString)end
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.
Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen
December 24, 2012 at 9:16 am #5267since 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)
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.