patchGNU Octave - Patches: patch #9868, midi functions

 
 

patch #9868: midi functions

Submitter:  John Donoghue <lostbard>
Submitted:  Mon 04 Nov 2019 01:24:58 AM UTC
   
 
Category:  Forge : new feature Priority:  5 - Normal
Status:  Done Privacy:  Public
Assigned to:  lostbard Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 31 Dec 2019 10:29:33 PM UTC, comment #14: 

A version, that is close to what I wil end up releasing as an initial version.



(file #48151)

John Donoghue <lostbard>
Group Member
Sun 15 Dec 2019 02:31:44 PM UTC, comment #13: 

Merged into the audio repo, so closing this ticket

https://sourceforge.net/p/octave/audio/ci/default/tree/


John Donoghue <lostbard>
Group Member
Fri 06 Dec 2019 02:02:38 AM UTC, comment #12: 

Initial import of midi functions to audio package as an example of what it would currently look like


(file #48013)

John Donoghue <lostbard>
Group Member
Fri 29 Nov 2019 12:53:58 PM UTC, comment #11: 

Added midiid, midicontrols, midiread and midisync functions

Adde generation of a basic manual

added nummidibytes and channel properties to midimsg

(file #47947)

John Donoghue <lostbard>
Group Member
Wed 27 Nov 2019 08:59:09 PM UTC, comment #10: 

msg.type only shows type of the first message
this change to subsref line 336 ff should fix it


      case "type"
            if length(p.data) == 0
              val = "<none>"
            else
              data = p.data{1};
              val = p.type_str(data(1), data(2));
              if length(p.data) > 1
                for i = 2:length(p.data)
                  data = p.data{i};
                  val = {val, p.type_str(data(1), data(2))};
                endfor
              endif
            endif


Lars Kindermann <larskindermann>
Tue 26 Nov 2019 01:38:41 PM UTC, comment #9: 

Fixed send

According to teh matlab docs, the data should be available using msgbytes property so msg.msgbytes

(file #47935)

John Donoghue <lostbard>
Group Member
Tue 26 Nov 2019 04:52:26 AM UTC, comment #8: 

Under ALSA on Linux the names of devices tend to change after restarting programs because the "name" is a concatenation of the immutable device name and an assigned alsa id:


>> mididevinfo
MIDI devices available
ID Direction Interface  Name
0       output       Alsa Midi Through 14:0
1       output       Alsa VMPK Input 129:0
2       output       Alsa FLUID Synth (10094) 130:0
3       output       Alsa RtMidi Input Client 132:0
4        input       Alsa Midi Through 14:0
5        input       Alsa VMPK Output 128:0


after closing and restarting vmpk and qsynth changes to


>> mididevinfo
MIDI devices available
ID Direction Interface  Name
 0       output       Alsa Midi Through 14:0
 1       output       Alsa VMPK Input 136:0
 2       output       Alsa FLUID Synth (10866) 130:0
 3       output       Alsa RtMidi Input Client 132:0
 4        input       Alsa Midi Through 14:0
 5        input       Alsa VMPK Output 135:0


This makes it difficult to address devices in an octave script permanently without the need to check for the current ID every time.

I suggest to change


function t = match_name_and_type(x, name, type)
  t = (strcmpi(x.Name, name) && strcmpi(x.Direction,type));
endfunction


to


function t = match_name_and_type(x, name, type)
  t = (strncmpi(x.Name, name, length(name)) && strcmpi(x.Direction,type));
endfunction


so this will work


>> devin  = mididevice ('input' ,'VMPK Output')
devin =

  mididevice connected to
    input: 'VMPK Output 128:0' (6)


>> devout = mididevice ('output','FLUID Synth')
devout =

  mididevice connected to
    output: 'FLUID Synth (10866) 130:0' (2)


Lars Kindermann <larskindermann>
Tue 26 Nov 2019 03:50:30 AM UTC, comment #7: 

Sending generated midi messages works ok now,
but re-transmitting received messages still fails:


pkg load midi

mididevinfo
devin  = mididevice ('input' ,'VMPK Output 128:0')
devout = mididevice ('output','FLUID Synth (10094) 130:0')

msg = midimsg("note", 0, 60, 127, 1.2)
midisend(devout, msg)

while 1
 msg = midireceive(devin);
 if length(msg)
  msg
  midisend(devout,msg)
 end
endwhile



>> miditest

MIDI devices available
ID Direction Interface  Name
 0       output       Alsa Midi Through 14:0
 1       output       Alsa VMPK Input 129:0
 2       output       Alsa FLUID Synth (10094) 130:0
 3       output       Alsa RtMidi Input Client 132:0
 4        input       Alsa Midi Through 14:0
 5        input       Alsa VMPK Output 128:0
 6        input       Alsa RtMidi Output Client 133:0
devin =

  mididevice connected to
    input: 'VMPK Output 128:0' (5)


devout =

  mididevice connected to
    output: 'FLUID Synth (10094) 130:0' (2)


MIDI message:
 NoteOn     Channel:  0 Note:  60 Velocity: 127 Timestamp: 0.000000 [ 0x90 0x3C 0x7F ]
 NoteOn     Channel:  0 Note:  60 Velocity:   0 Timestamp: 1.200000 [ 0x90 0x3C 0x00 ]
ans = 04:27:58.173
MIDI message:
 NoteOn     Channel:  0 Note:  55 Velocity:  70 Timestamp: 0.000000 [ 0x90 0x37 0x46 ]
error: scalar cannot be indexed with {
error: called from
    midisend at line 55 column 9
    miditest at line 17 column 3
>>


And how do I access the data?


>> msg.type
ans = NoteOn

>> msg.timestamp
ans = 0

>> msg.data
error: unimplemented midimsg.subsref property
error: called from
    subsref at line 344 column 13
>>


Lars Kindermann <larskindermann>
Tue 26 Nov 2019 12:54:20 AM UTC, comment #6: 

Some updates

(file #47930)

John Donoghue <lostbard>
Group Member
Wed 06 Nov 2019 11:35:26 AM UTC, comment #5: 

Yeah - not much I can do about that warning - its a known bug in the octave help system with classdef files:

https://savannah.gnu.org/bugs/?53874

It doesnt stop the code working its just it doesnt show the help for that classdef/functions.


Current limitations in the functions implmented as the moment are:

  • not all of midimsg constructor options are done yet.


  • timestamp doesnt quite behave the same as matlabs documentation yet.


  • I dont think timestamp is set correctly in the midirecv


  • midimsg properties need to be implmentated


  • the midifile functions are very rudimentary, doesnt store all message types, and doesnt align trasck times correctly. They arent part of thematlab midi functionality anyway, but would be good to get relativly robust anway.


  • missing functions for midi control surfaces.


 
There are probaly other issues, but they are the ones I can think of offhand, that I would to get done before making a first release.



John Donoghue <lostbard>
Group Member
Wed 06 Nov 2019 03:37:20 AM UTC, comment #4: 

Installation works with librtmidi 2.1.0 now.

Only one warning left:


>> pkg install Downloads/midi-0.0.1.tar.gz
warning: doc_cache_create: unusable help text found in file 'midimsg'
warning: called from
    doc_cache_create>handle_function at line 91 column 5
    doc_cache_create>create_cache at line 111 column 36
    gen_doc_cache_in_dir>@<anonymous> at line 143 column 16
    doc_cache_create>gen_doc_cache_in_dir at line 144 column 9
    doc_cache_create at line 55 column 12
    install>generate_lookfor_cache at line 800 column 5
    install at line 229 column 7
    pkg at line 476 column 9


Lars Kindermann <larskindermann>
Tue 05 Nov 2019 11:15:07 AM UTC, comment #3: 

Some updates that may make it compile ok



(file #47808)

John Donoghue <lostbard>
Group Member
Mon 04 Nov 2019 10:10:48 PM UTC, comment #2: 

In windows v4.0.0
Im not sure what version I used on my fedora box now - I will have to verify, however I would imagine  its a lot newer than the 2.1.0 version.

On a ubunu 18 box I have just tried, its version 3.0.0, and I see the warnings for err.getMessage() so will change them for starters to err.getMessage().c_str() if it doesn't break for newer versions


It shouldn't be too hard to make work with an older version though.


John Donoghue <lostbard>
Group Member
Mon 04 Nov 2019 09:52:54 PM UTC, comment #1: 

I'm very interested in this package and possibly could contribute.

But install fails under Ubuntu 16.04 / Octave current dev (6.0).
My librtmidi is version 2.1.0

Which rtmidi version do you use to build?


>> pkg install Downloads/midi-0.0.1.tar.gz
midi.cc: In function ‘bool send_midi(midi_device*, const unsigned char*, int)’:
midi.cc:109:37: error: no matching function for call to ‘RtMidiOut::sendMessage(const unsigned char*&, int&)’
       dev->out->sendMessage(data, sz);
                                     ^
In file included from midi.h:23:0,
                 from midi.cc:16:
/usr/include/RtMidi.h:569:13: note: candidate: void RtMidiOut::sendMessage(std::vector<unsigned char>*)
 inline void RtMidiOut :: sendMessage( std::vector<unsigned char> *message ) { ((MidiOutApi *)rtapi_)->sendMessage( messag
             ^
/usr/include/RtMidi.h:569:13: note:   candidate expects 1 argument, 2 provided
midi.cc:113:63: warning: format ‘%s’ expects argument of type ‘char*’, but argument 2 has type ‘const string* {aka const std::__cxx11::basic_string<char>*}’ [-Wformat=]
       error ("Error getting midi info: '%s'", err.getMessage());
                                                               ^
midi.cc: In function ‘int recv_midi(midi_device*, double*, unsigned char*, int)’:
midi.cc:136:58: warning: format ‘%s’ expects argument of type ‘char*’, but argument 2 has type ‘const string* {aka const std::__cxx11::basic_string<char>*}’ [-Wformat=]
       error ("Error reading midi: '%s'", err.getMessage());
                                                          ^
midi.cc: In function ‘bool get_midi_devices(midi_device_list&)’:
midi.cc:184:63: warning: format ‘%s’ expects argument of type ‘char*’, but argument 2 has type ‘const string* {aka const std::__cxx11::basic_string<char>*}’ [-Wformat=]
       error ("Error getting midi info: '%s'", err.getMessage());
                                                               ^
make: *** [midi.o] Fehler 1
make: *** Auf noch nicht beendete Prozesse wird gewartet …
make: Verzeichnis „/tmp/oct-A5uS4z/midi-0.0.1/src“ wird betreten
/usr/local/bin/mkoctfile-6.0.0 -c mididevinfo.cc -g -O2 -D__UNIX_JACK__ -D__LINUX_ALSA__ -DHAVE_CONFIG_H
/usr/local/bin/mkoctfile-6.0.0 -c mididevice.cc -g -O2 -D__UNIX_JACK__ -D__LINUX_ALSA__ -DHAVE_CONFIG_H
/usr/local/bin/mkoctfile-6.0.0 -c midi.cc -g -O2 -D__UNIX_JACK__ -D__LINUX_ALSA__ -DHAVE_CONFIG_H
/usr/local/bin/mkoctfile-6.0.0 -c midi_object.cc -g -O2 -D__UNIX_JACK__ -D__LINUX_ALSA__ -DHAVE_CONFIG_H
Makefile:13: die Regel für Ziel „midi.o“ scheiterte
make: Verzeichnis „/tmp/oct-A5uS4z/midi-0.0.1/src“ wird verlassen

error: pkg: error running 'make' for the midi package.
error: called from
    configure_make at line 99 column 9
    install at line 190 column 7
    pkg at line 476 column 9
>>


Lars Kindermann <larskindermann>
Mon 04 Nov 2019 01:24:58 AM UTC, original submission:  

The start of a package to include midi functions similar to the fuiunctions provided by matlab

John Donoghue <lostbard>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #48151:  audio-2.0.0.tar.gz added by lostbard (336KiB - application/gzip)
file #48013:  audio-2.0.0.tar.gz added by lostbard (333KiB - application/gzip)
file #47950:  midi-0.0.1.tar.gz added by lostbard (289KiB - application/gzip)
file #47947:  midi-0.0.1.tar.gz added by lostbard (288KiB - application/gzip)
file #47935:  midi-0.0.1.tar.gz added by lostbard (78KiB - application/x-gzip)
file #47930:  midi-0.0.1.tar.gz added by lostbard (64KiB - application/gzip)
file #47811:  midi-0.0.1.tar.gz added by lostbard (64KiB - application/gzip)
file #47808:  midi-0.0.1.tar.gz added by lostbard (64KiB - application/gzip)
file #47798:  midi-0.0.1.tar.gz added by lostbard (64KiB - application/gzip)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by larskindermann (Posted a comment)
  • -email is unavailable- added by lostbard (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 12 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-12-31 lostbard Attached File- Added audio-2.0.0.tar.gz, #48151
    2019-12-15 lostbard StatusNone Done
        Assigned toNone lostbard
        Open/ClosedOpen Closed
    2019-12-06 lostbard Attached File- Added audio-2.0.0.tar.gz, #48013
    2019-11-29 lostbard Attached File- Added midi-0.0.1.tar.gz, #47950
    2019-11-29 lostbard Attached File- Added midi-0.0.1.tar.gz, #47947
    2019-11-26 lostbard Attached File- Added midi-0.0.1.tar.gz, #47935
    2019-11-26 lostbard Attached File- Added midi-0.0.1.tar.gz, #47930
    2019-11-07 lostbard Attached File- Added midi-0.0.1.tar.gz, #47811
    2019-11-05 lostbard Attached File- Added midi-0.0.1.tar.gz, #47808
    2019-11-04 lostbard Attached File- Added midi-0.0.1.tar.gz, #47798

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code