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
  Is it possible to extract 1 or 2 bits of data from MS project files? cubangt 8 937 Feb-16-2024, 12:02 AM
Last Post: deanhystad
  extract substring from a string before a word !! evilcode1 3 491 Nov-08-2023, 12:18 AM
Last Post: evilcode1
  Why can't it extract the data from .txt well? Melcu54 3 644 Aug-20-2023, 10:07 PM
Last Post: deanhystad
  python Extract sql data by combining below code. mg24 1 914 Oct-03-2022, 10:25 AM
Last Post: mg24
  SQL Alchemy help to extract sql data into csv files mg24 1 1,674 Sep-30-2022, 04:43 PM
Last Post: Larz60+
  How to extract specific data from .SRC (note pad file) Shinny_Shin 2 1,224 Jul-27-2022, 12:31 PM
Last Post: Larz60+
  Extract a string between 2 words from a text file OscarBoots 2 1,826 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 1,897 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 1,529 Jul-17-2021, 09:09 AM
Last Post: JaneTan
  Need help on extract dynamic table data Dr_Strange 0 2,446 Apr-30-2021, 07:03 AM
Last Post: Dr_Strange

Forum Jump:

User Panel Messages

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