Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8042487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:35:45+00:00 2026-06-05T04:35:45+00:00

My python program receives MIDI data from a C library. Sometimes the data will

  • 0

My python program receives MIDI data from a C library. Sometimes the data will look like this:

[[[[240,0,1,116]]],[[[3,100,8,1]]],[[[107,247,0,0]]]]

and sometimes it will include timestamps like this:

[[[[240,0,1,116],26738]],[[[3,100,8,1],26738]],[[[107,247,0,0],26738]]]

I need the data in an array of bytes, with the timestamp values discarded. The code I wrote to do this is:

        def convertMidiSysex(data):    
            while isinstance(data[0][0], list):
                out = []
                for index, value in enumerate(data):
                    out = out+value
                data = out

            out = array.array('B')
            for i in range(len(data)):
                if isinstance(data[i], list):
                    for j in range(len(data[i])):
                        out.append(data[i][j])
                        if out[-1] == 247:  # 0xF7 is marker to end sysex message
                            return out

I can’t help feeling that I’m doing this the hard way. Is there a better approach to this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:35:46+00:00Added an answer on June 5, 2026 at 4:35 am

    A slightly cleaner way to get what you have now:

    # the entry below mixes timestamped and non-timestamped inputs
    entry = [[[[240,0,1,116]]],    [[[3,100,8,1]]],
             [[[107,247,0,0]]],    [[[240,0,1,116],26738]],
             [[[3,100,8,1],26738]],[[[107,247,0,0],26738]]]
    
    data = array.array('B')
    for sublist in entry:
        for item in sublist[0][0]:
            data.append(item)
            if item == 247:
                break
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Python program receives JSON data, and I need to get bits of information
Consider this python program: import sys lc = 0 for line in open(sys.argv[1]): lc
I have a simple python program that I'd like to daemonize. Since the point
I'd like to prevent multiple instances of the same long-running python command-line script from
I am 100% new to Python I am bumping into this weird issue regarding
In Python one can say this: python script.py from the command line and receive
My Python program is receiving ICMP destination unreachable messages from a raw socket. The
I'm running a python program compiled on windows which receives files as input but
I'm making a program that retrieves decently large amounts of data through a python
I am making an application in Python which collects data from a serial port

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.