필터 지우기
필터 지우기

How to extract MIDI data from mxarray in simulink ?

조회 수: 3 (최근 30일)
Guillaume
Guillaume 2023년 3월 2일
답변: Swaraj 2023년 3월 9일
Hello,
For a project, I need to use a MIDI controller that sends MIDI files for the keys pressed (so the MIDI message is a 'NoteOn' or 'NoteOff'). To do so, I chose to use a matlab function block and inside it, i wrote a code using midireceive('MidiInput') function (In order to do that, i used coder.extrinsic('midireceive'). Unfortunately, the results from that is that I got the data from my MIDI controller in a mxarray and I don't know how to extract the data correctly (I juste have to know when a key is pressed and which one it is).

채택된 답변

Swaraj
Swaraj 2023년 3월 9일
To extract the MIDI data correctly from the “mxarray” received by the “midireceive()” function in Simulink, you can use the following steps:
  1. Add a MATLAB Function block to your Simulink model.
  2. Inside the MATLAB Function block, use the “coder.extrinsic()” function to declare the “midireceive()” function as an extrinsic function.
  3. To receive MIDI data from the MIDI controller, use the “midireceive()” function.
  4. Use the “cell()” function to transform the “mxarray” into a cell array.
  5. Loop over the elements of the cell array and extract the MIDI message using the “midimsg()” function.
  6. To detect whether a MIDI message is a "NoteOn" or "NoteOff" message, look at the message's status byte.
  7. Similarly you can extract other details like “channel”, “note”,” velocity” etc.
For more details you can go through the following Documentations.
Documentation for “midireceive”.
Documentation for “mxArrays”.
Documentation for Cell Arrays.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Musical Instrument Digital Interface (MIDI)에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by