Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URGENT: check possible bug in utils.packDsiData() #30

Closed
dobo365 opened this issue Aug 11, 2016 · 2 comments
Closed

URGENT: check possible bug in utils.packDsiData() #30

dobo365 opened this issue Aug 11, 2016 · 2 comments

Comments

@dobo365
Copy link

dobo365 commented Aug 11, 2016

Hi atom,
I'm finalizing my Pro2 panel (was intended to be released next week - mid August) by doing a lot of tests. Among those tests, some classical loops of reading some data then saving without any change and checking you have the same...
I discovered some differences and investigated in details until I came to the point of suspecting a bug in utils.packDsiData() occuring at the end of producing the output (a bit strange in my opinion).

I join you different info below.
The 3 last bytes at end of original packed data are: 03 7F 7F
The 3 last bytes at end of produced packed data are: 64 00 20
Unpacked data is the same...

Can you please have a look?
Thanks in advance....Dominique (goodweather)

Sysex file to use as test (6 bytes + 1171 packed + 1 byte):
**
F7P1 - Sweet Cherry.zip
**

Method to test:

LoadAndSaveTest = function(--[[ CtrlrModulator --]] mod, --[[ number --]] value, --[[ number --]] source)

    -- No action while loading a program or if the panel is in bootstrap or program states
    if bLoadingProgram or not isPanelReady() then
        return
    end 

    -- Load a .syx file
    f = utils.openFileWindow ("Load Pro 2 packed program dump", File(""), "*.syx", true)
    if f:isValid() then -- A file has been selected and the user pressed Open
        if f:existsAsFile() then
            Pro2ProgramFileData = MemoryBlock()
            f:loadFileAsData(Pro2ProgramFileData)
            FileSize = Pro2ProgramFileData:getSize()

            if FileSize == 1178 or FileSize == 1176 then
                -- Unpack and load data in panel
                if FileSize == 1178 then
                    -- Program data dump
                    console("Packed Program data dump after reading Load")
                    console(Pro2ProgramFileData:getRange(6, 1171):toHexString(1))                   
                    LoadedProgramData = utils.unpackDsiData(Pro2ProgramFileData:getRange(6, 1171))
                else
                    -- Program buffer data dump
                    console("Packed Program buffer data dump after Load")
                    console(Pro2ProgramFileData:getRange(4, 1171):toHexString(1))                   
                    LoadedProgramData = utils.unpackDsiData(Pro2ProgramFileData:getRange(4, 1171))
                end
                FileSize = LoadedProgramData:getSize()
                if FileSize == 1024 then
                    console("Unpacked LoadedProgramData after Load")
                    console(LoadedProgramData:toHexString(1))
                end
            end
        end
    end

    -- Save to .syx file: always saving a 1176 program buffer dump to be bank and program independent
    --  f = utils.saveFileWindow ("Save Pro 2 program buffer dump sysex file", File(""), "*.syx", true)
    --  if f:isValid() then
    --      if f:existsAsFile()==false then
    --          f:create()
    --      end

    --      FileSize = LoadedProgramData:getSize()
    --      if FileSize == 1024 then
                console("Unpacked LoadedProgramData before Save")
                console(LoadedProgramData:toHexString(1))
                console("Packed Program buffer data dump before Save")
                console(utils.packDsiData(LoadedProgramData):toHexString(1))
    --      end
    --  end

end

Console output from attached .syx file:

LUA>> Packed Program data dump after reading Load

LUA>> 00 3c 3c 24 24 32 3c 32 00 32 3c 3c 3c 1d 05 05 00 04 1d 00 01 02 03 07 00 08 09 0a 04 05 06 07 00 36 40 40 40 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 00 00 00 1d 00 1d 1d 1d 00 00 00 00 00 01 01 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 01 02 02 00 00 00 00 00 03 00 00 05 00 0a 01 7f 00 00 00 17 01 24 10 00 75 08 00 00 40 00 7f 00 7f 00 78 70 00 50 4f 07 09 05 03 00 00 00 00 1e 00 00 00 22 00 00 00 00 00 7f 7f 7f 00 7f 00 00 00 00 00 00 00 00 00 40 40 40 40 00 20 00 00 00 15 28 04 3e 00 00 00 00 00 00 00 00 00 00 02 03 00 7f 05 0f 00 05 0b 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00 1f 7f 7f 01 4e 7f 34 00 00 00 00 00 00 00 00 00 00 05 00 00 31 67 00 51 39 00 35 00 00 50 7f 7f 7f 00 6a 00 00 5f 18 00 22 00 00 00 00 00 00 00 00 00 00 00 00 00 0f 10 11 11 0b 00 0b 18 11 06 18 14 14 30 00 00 00 00 07 61 57 67 27 37 38 7f 7f 11 3e 02 7f 2a 7f 7f 7f 7f 42 00 0e 18 0b 4b 57 21 00 00 09 21 01 0e 00 00 00 00 00 00 00 78 02 00 00 00 01 02 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 77 65 65 74 20 43 00 68 65 72 72 79 20 20 40 20 20 20 20 20 20 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 08 08 08 08 08 08 00 08 20 20 20 20 20 20 00 20 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 7e 00 30 3c 48 33 3f 4b 7f 2e 3a 35 46 33 48 32 07 30 54 54 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 3c 3c 3c 3c 00 3c 3c 3c 3c 3c 3c 3c 00 3c 3c 3c 3c 3c 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 2c 4c 00 51 61 01 6f 69 36 50 22 5f 6b 3a 41 12 30 29 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 64 64 64 64 64 64 64 00 64 64 64 64 64 64 64 00 64 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 7f 7f

LUA>> Unpacked LoadedProgramData after Load

LUA>> 3c 3c 24 24 32 3c 32 32 3c 3c 3c 1d 05 05 04 1d 00 01 02 03 07 08 09 0a 04 05 06 07 36 40 40 40 00 00 00 00 00 00 00 00 00 00 00 0a 00 00 00 00 1d 1d 1d 1d 00 00 00 00 01 01 01 01 00 00 00 00 00 00 00 00 00 00 00 00 02 01 02 02 00 00 00 00 03 00 00 05 0a 01 7f 00 00 00 17 a4 10 00 75 08 00 00 00 7f 00 7f 00 78 f0 50 4f 07 09 05 03 00 00 00 1e 00 00 00 22 00 00 00 00 7f 7f 7f 7f 00 00 00 00 00 00 00 00 40 40 40 40 00 00 00 00 15 28 84 3e 00 00 00 00 00 00 00 00 02 03 00 7f 05 0f 05 0b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 9f 7f 7f ce 7f 34 00 00 00 00 00 00 00 00 00 05 00 31 67 00 51 39 00 35 00 50 7f 7f 7f 00 6a 00 5f 18 00 22 00 00 00 00 00 00 00 00 00 00 00 0f 10 11 11 0b 0b 18 11 06 18 14 14 00 00 00 00 87 e1 57 a7 b7 b8 7f 7f 91 be 7f aa 7f 7f 7f 7f 42 0e 18 0b 4b 57 21 00 09 21 01 0e 00 00 00 00 00 00 78 02 00 00 01 02 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 77 65 65 74 20 43 68 65 72 72 79 20 20 20 20 20 20 20 20 8f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 08 08 08 08 08 08 08 20 20 20 20 20 20 20 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 b0 bc c8 b3 bf cb ae ba b5 c6 b3 c8 b2 b0 d4 d4 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 3c 3c 3c 3c 3c 3c 3c 3c 3c 3c 3c 3c 3c 3c 3c 3c 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 2c 4c 51 61 01 6f 69 36 50 5f eb 3a 41 12 b0 29 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff

LUA>> Unpacked LoadedProgramData before Save

LUA>> 3c 3c 24 24 32 3c 32 32 3c 3c 3c 1d 05 05 04 1d 00 01 02 03 07 08 09 0a 04 05 06 07 36 40 40 40 00 00 00 00 00 00 00 00 00 00 00 0a 00 00 00 00 1d 1d 1d 1d 00 00 00 00 01 01 01 01 00 00 00 00 00 00 00 00 00 00 00 00 02 01 02 02 00 00 00 00 03 00 00 05 0a 01 7f 00 00 00 17 a4 10 00 75 08 00 00 00 7f 00 7f 00 78 f0 50 4f 07 09 05 03 00 00 00 1e 00 00 00 22 00 00 00 00 7f 7f 7f 7f 00 00 00 00 00 00 00 00 40 40 40 40 00 00 00 00 15 28 84 3e 00 00 00 00 00 00 00 00 02 03 00 7f 05 0f 05 0b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 9f 7f 7f ce 7f 34 00 00 00 00 00 00 00 00 00 05 00 31 67 00 51 39 00 35 00 50 7f 7f 7f 00 6a 00 5f 18 00 22 00 00 00 00 00 00 00 00 00 00 00 0f 10 11 11 0b 0b 18 11 06 18 14 14 00 00 00 00 87 e1 57 a7 b7 b8 7f 7f 91 be 7f aa 7f 7f 7f 7f 42 0e 18 0b 4b 57 21 00 09 21 01 0e 00 00 00 00 00 00 78 02 00 00 01 02 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 77 65 65 74 20 43 68 65 72 72 79 20 20 20 20 20 20 20 20 8f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 08 08 08 08 08 08 08 20 20 20 20 20 20 20 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 b0 bc c8 b3 bf cb ae ba b5 c6 b3 c8 b2 b0 d4 d4 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 3c 3c 3c 3c 3c 3c 3c 3c 3c 3c 3c 3c 3c 3c 3c 3c 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 2c 4c 51 61 01 6f 69 36 50 5f eb 3a 41 12 b0 29 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff

LUA>> Packed Program buffer data dump before Save

LUA>> 00 3c 3c 24 24 32 3c 32 00 32 3c 3c 3c 1d 05 05 00 04 1d 00 01 02 03 07 00 08 09 0a 04 05 06 07 00 36 40 40 40 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 00 00 00 1d 00 1d 1d 1d 00 00 00 00 00 01 01 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 01 02 02 00 00 00 00 00 03 00 00 05 00 0a 01 7f 00 00 00 17 01 24 10 00 75 08 00 00 40 00 7f 00 7f 00 78 70 00 50 4f 07 09 05 03 00 00 00 00 1e 00 00 00 22 00 00 00 00 00 7f 7f 7f 00 7f 00 00 00 00 00 00 00 00 00 40 40 40 40 00 20 00 00 00 15 28 04 3e 00 00 00 00 00 00 00 00 00 00 02 03 00 7f 05 0f 00 05 0b 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00 1f 7f 7f 01 4e 7f 34 00 00 00 00 00 00 00 00 00 00 05 00 00 31 67 00 51 39 00 35 00 00 50 7f 7f 7f 00 6a 00 00 5f 18 00 22 00 00 00 00 00 00 00 00 00 00 00 00 00 0f 10 11 11 0b 00 0b 18 11 06 18 14 14 30 00 00 00 00 07 61 57 67 27 37 38 7f 7f 11 3e 02 7f 2a 7f 7f 7f 7f 42 00 0e 18 0b 4b 57 21 00 00 09 21 01 0e 00 00 00 00 00 00 00 78 02 00 00 00 01 02 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 77 65 65 74 20 43 00 68 65 72 72 79 20 20 40 20 20 20 20 20 20 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 08 08 08 08 08 08 00 08 20 20 20 20 20 20 00 20 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 7e 00 30 3c 48 33 3f 4b 7f 2e 3a 35 46 33 48 32 07 30 54 54 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 3c 3c 3c 3c 00 3c 3c 3c 3c 3c 3c 3c 00 3c 3c 3c 3c 3c 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 7f 7f 00 7f 7f 7f 7f 7f 2c 4c 00 51 61 01 6f 69 36 50 22 5f 6b 3a 41 12 30 29 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 64 64 64 64 64 64 64 00 64 64 64 64 64 64 64 00 64 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 64 00 20
@dobo365
Copy link
Author

dobo365 commented Aug 12, 2016

OK. I have now done simpler testing and also built an Excel file where I can see the desired output for any input (packed or unpacked in both directions).
I confirm there is something not correct in utils.packDsiData().
I will look at your code in CtrlrLuaUtils.cpp

Meanwhile, here are those simpler files for testing + some Lua method + Excel file (look at sheet2 - DSI)
BitsAndBytes.xlsx
Pack-Unpack test.zip

Best regards...Dominique

PackUnpackTest = function(--[[ CtrlrModulator --]] mod, --[[ number --]] value, --[[ number --]] source)

    -- No action while loading a program or if the panel is in bootstrap or program states
    if bLoadingProgram or not isPanelReady() then
        return
    end 

    bAnswer = utils.questionWindow("Pack/Unpack or Unpack/Pack tests", "Please select the type of input file...", "Packed", "Unpacked")

    if bAnswer then

        -- Load a packed .syx file
        f = utils.openFileWindow ("Load a file containing packed data", File(""), "*.syx", true)
        if f:isValid() then -- A file has been selected and the user pressed Open
            if f:existsAsFile() then
                mbPackedData = MemoryBlock()
                f:loadFileAsData(mbPackedData)
                FileSize = mbPackedData:getSize()
                console("Packed file size: "..tostring(FileSize))
                console("Packed data: "..mbPackedData:toHexString(1))
                mbUnpackedData = utils.unpackDsiData(mbPackedData)
                FileSize = mbUnpackedData:getSize()
                console("Unpacked file size: "..tostring(FileSize))
                console("Unpacked data: "..mbUnpackedData:toHexString(1))
            end
        end

    else

        -- Load an unpacked .syx file
        f = utils.openFileWindow ("Load a file containing unpacked data", File(""), "*.syx", true)
        if f:isValid() then -- A file has been selected and the user pressed Open
            if f:existsAsFile() then
                mbUnpackedData = MemoryBlock()
                f:loadFileAsData(mbUnpackedData)
                FileSize = mbUnpackedData:getSize()
                console("Unpacked file size: "..tostring(FileSize))
                console("Unpacked data: "..mbUnpackedData:toHexString(1))
                mbPackedData = utils.packDsiData(mbUnpackedData)
                FileSize = mbPackedData:getSize()
                console("Packed file size: "..tostring(FileSize))
                console("Packed data: "..mbPackedData:toHexString(1))
            end
        end

    end

end

Output in console:

LUA>> Packed file size: 8
LUA>> Packed data: 46 02 25 78 78 05 0c 3b
LUA>> Unpacked file size: 7
LUA>> Unpacked data: 02 a5 f8 78 05 0c bb
LUA>> Unpacked file size: 7
LUA>> Unpacked data: 02 a5 f8 78 05 0c bb
LUA>> Packed file size: 8
LUA>> Packed data: 00 00 00 00 00 00 00 00

@dobo365
Copy link
Author

dobo365 commented Aug 16, 2016

Hi atom,
i investigated further and built my own packing function.
I suspect that the issue with the utils.packDsiData() is coming from the fact that the input data must be a multiple of 7 to work (could be...).

Here is a working PackDsiData() function that is working fine but it is in Lua and not C++.
I will also publish it on the forum.
As I found a solution, this issue is now less urgent. It is now a bug to correct...
My very best regards...Dominique

--
--  A function to pack DSI data according to description at end of Pro 2 and P12 manuals
--  Written because internal utils.packDsiData() Ctrlr function doesn't work properly.
--
--  DSI Packed Data Format
--  Data is packed in 8 byte “packets”, with the MS bit stripped from 7 parameter bytes,
--  and packed into an eighth byte, which is sent at the start of the 8 byte packet.
--
--  Example:
--
--  Input Data                  Packed MIDI data
--  1 A7 A6 A5 A4 A3 A2 A1 A0   1 00 G7 F7 E7 D7 C7 B7 A7
--  2 B7 B6 B5 B4 B3 B2 B1 B0   2 00 A6 A5 A4 A3 A2 A1 A0
--  3 C7 C6 C5 C4 C3 C2 C1 C0   3 00 B6 B5 B4 B3 B2 B1 B0
--  4 D7 D6 D5 D4 D3 D2 D1 D0   4 00 C6 C5 C4 C3 C2 C1 C0
--  5 E7 E6 E5 E4 E3 E2 E1 E0   5 00 D6 D5 D4 D3 D2 D1 D0
--  6 F7 F6 F5 F4 F3 F2 F1 F0   6 00 E6 E5 E4 E3 E2 E1 E0
--  7 G7 G6 G5 G4 G3 G2 G1 G0   7 00 F6 F5 F4 F3 F2 F1 F0
--  8 00 G6 G5 G4 G3 G2 G1 G0
--
--  This explains why it takes 1171 MIDI bytes to transmit 1024 Program data bytes.
--
PackDsiData = function(mbUnpackedDsiData)

    console("*** PackDsiData function ***")

    -- Take a copy of mbUnpackedDsiData to avoid modifying it
    mbUnpacked = MemoryBlock(mbUnpackedDsiData)

    -- Check mbUnpacked size is a multiple of 7
    iSize = mbUnpacked:getSize()
    console("..Unpacked size="..tostring(iSize))
    iRemains = math.mod(iSize, 7)
    mbInit = MemoryBlock ({0x00})
    if iRemains ~= 0 then
        console("..Size to append="..tostring(7-iRemains))
        -- mbTemp=MemoryBlock(7-iRemains, true) Doesn't work!
        mbTemp = MemoryBlock()
        for i=1,7-iRemains do
            mbTemp:append (mbInit)
        end
        mbUnpacked:append (mbTemp)
        console("..Temporary unpacked data: "..mbUnpacked:toHexString(1))
        console("..Temporary unpacked size="..tostring(mbUnpacked:getSize()))
    end
    mbPacked = MemoryBlock()
    if iRemains == 0 then
        console("..Calculated packed size="..8*math.floor(iSize/7))
        for i=1,8*math.floor(iSize/7) do
            mbPacked:append (mbInit)
        end
    else
        console("..Calculated packed size="..8*math.floor(iSize/7)+iRemains+1)
        for i=1,8*math.floor(iSize/7)+iRemains+1 do
            mbPacked:append (mbInit)
        end
    end

    k = 0
    for i=0,iSize-1,7 do
        -- Build and write the first packed byte from the bit7 of the 7 unpacked bytes
        FirstByte = 0
        for j=0,6 do
            FirstByte = FirstByte + bit.rshift(mbUnpacked:getByte(i+j), 7) * 2^j
            -- console("..i="..i.." j="..j.." Bit="..tostring(bit.rshift(mbUnpacked:getByte(i+j), 7)))
        end
        mbPacked:setByte(k, FirstByte)
        -- Strip and write the 7 unpacked bytes
        for j=0,6 do
            k = k + 1
            mbPacked:setByte(k, bit.band(mbUnpacked:getByte(i+j), 0x7F))
        end
        k = k + 1
    end
    console("..Returned packed size="..tostring(mbPacked:getSize()))
    console("..Returned packed data: "..mbPacked:toHexString(1))

    return mbPacked

end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants