Python Forum
Extract data from large string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extract data from large string
#1
I'm building a project with Raspberry PI. Reading MIDI messages that come from a guitar pedal. The intent is to have the PI play a mp3 file when it receives a program change message on the appropriate MIDI chnl and Program Change number.

I am using the pygame module and I am recieving the messages.

The received message are large strings with various wrappers.

First, the entire messgae is wrapped in [ ]

Inside that ther can be several events. Each wrapped in <>

THen inside of that lives the data wrapped in ()

Here is an example,

[<Event(34-Unknown {'status': 194, 'data1': 0, 'data2': 0, 'data3': 0, 'timestamp': 4221, 'vice_id': 3})>, <Event(34-Unknown {'status': 178, 'data1': 80, 'data2': 0, 'data3': 0, 'timestamp': 4222, 'vice_id': 3})>, <Event(34-Unknown {'status': 178, 'data1': 81, 'data2': 0, 'data3': 0, 'timestamp': 4222, 'vice_id': 3})>]

THere are three events in this message.

I am interested in only messages with status 194 and then want to return the value of data1,

Status 194 is MIDI chnl 3 and data1 0 is Program change 1

So, I want to only act on events with status 194 and then set a variable "track" to the value of data1

I haven'y written any code for a decade or so and am happy to be at this point...

I'm guessing this is easy stuff for a Python veteran. Any and all help will be greatly appreciated.


Thank you,
Reply
#2
you should take a look at https://pypi.org/project/py-midi/
(can be installed with pip install py-midi)
many more packages to take a look at: https://pypi.org/search/?q=%27midi+message%27&o=
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Extract a string between 2 words from a text file OscarBoots 2 408 Nov-02-2021, 08:50 AM
Last Post: ibreeden
  Build a matrix by pressing buttons of an interface in Tkinter which extract data from juandiegopulla 1 439 Sep-13-2021, 07:28 PM
Last Post: deanhystad
  Python Pandas: How do I extract all the >1000 data from a certain column? JaneTan 0 548 Jul-17-2021, 09:09 AM
Last Post: JaneTan
  Need help on extract dynamic table data Dr_Strange 0 996 Apr-30-2021, 07:03 AM
Last Post: Dr_Strange
  How to extract specific key value pair from string? aditi06 0 1,020 Apr-15-2021, 06:26 PM
Last Post: aditi06
  Python modules to extract data from a graph? bigmit37 5 15,831 Apr-09-2021, 02:15 PM
Last Post: TysonL
Question How to extract multiple text from a string? chatguy 2 915 Feb-28-2021, 07:39 AM
Last Post: bowlofred
  Extract continuous numeric characters from a string in Python Robotguy 2 1,037 Jan-16-2021, 12:44 AM
Last Post: snippsat
  Pandas Extract data from two dataframe nio74maz 1 900 Dec-26-2020, 09:52 PM
Last Post: nio74maz
  Extract data from PDF page to Excel nathan_nz 1 810 Oct-29-2020, 08:04 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020