View Single Post
Old 03-30-2018, 09:06 AM   #276
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,389
Default

Sysex support for reaper.StuffMIDIMessage...and some way to receive sysex data.

I would like to store Kemper Profiling Amp rigs (sysex data) to tracks by using reaper.SetProjExtState.
(and later, when needed, send the data back to Kemper)


Ctrlr can send/receive sysex messages
Github: https://github.com/RomanKubiak/ctrlr...c7/Source/Core

Ctrlr example - this code reads a "kipr" -file (Kemper rig) and sends it to MIDI out -> to Kemper MIDI in
Code:
readFileAsData = function(mod, value)
	if panel:getBootstrapState() then
		return
	end

	fileToRead = utils.openFileWindow(
		"Open file to read as data",
		File.getSpecialLocation(File.userHomeDirectory),
		"*.kipr",
		true
	)

	if fileToRead:existsAsFile() then

		-- Update the file path
		panel:getLabelComponent("lastFileReadPathL"):setText ("> "..fileToRead:getFullPathName())

		if fileToRead:getSize() > 8192 then
				utils.warnWindow(
					"File too big", 
					"Labels are not designed to show too much data, please choose a file that's smaller then 8kb.\
The file you chose is "..fileToRead:getSize().." bytes"
				)
			return
		end

		-- We need a memory block to load our file into, this can be created at some other point in time
		-- if we expect the files to be big and the amount of memory we need is higher, it will pre-allocate
		-- that memory at the moment that MemoryBlock() is called
		-- here we will allocate the amount of memory that is equalt to the size of the file

		fileData = MemoryBlock(fileToRead:getSize())

		-- This method does not return a new memory block, it operates on the one provided by us

		fileToRead:loadFileAsData (fileData)

		--panel:getLabelComponent("dataContentL"):setText(
			--fileData:toHexString(1)
	--	)
		size = fileToRead:getSize()-0x17
		-- skip header part
		datablock = MemoryBlock(fileToRead:getSize()-0x17)
		datablock = fileData:getRange(0x17,size)
		sysexdata= MemoryBlock()

	
		for i=0,size,1 do
		
			if (datablock:getByte(i)== 240) then
				--console(datablock:getByte(i):toHexString(1))
				sysexdata:append(datablock:getRange(i,1))

				local m= datablock:getByte(i+1)
				sysexdata:append(datablock:getRange(i+2,m))
				console(sysexdata:toHexString(1))
				local midimessage = CtrlrMidiMessage(sysexdata:toHexString(1))
	    		--panel:sendMidiMessageNow(midimessage)
				sysexdata= MemoryBlock()
			end
		end
	end
end
spk77 is offline   Reply With Quote