File: mididevinfo.m

package info (click to toggle)
octave-audio 2.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,632 kB
  • sloc: sh: 2,869; cpp: 886; python: 438; makefile: 228; xml: 21
file content (110 lines) | stat: -rw-r--r-- 3,337 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
## Copyright (C) 2019-2021 John Donoghue <john.donoghue@ieee.org>
## 
## This program is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
## 
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
## 
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see
## <https://www.gnu.org/licenses/>.

## -*- texinfo -*- 
## @deftypefn {} {@var{devlist} =} mididevinfo ()
## @deftypefnx {} {} mididevinfo ()
## Retrieve the midi devices detected within the system.
##
## The list will be stored with variable @var{devlist} as either a input or output device.
## If no output variable is provided, the devices will be displayed.
##
## @subsubheading Inputs
## None
##
## @subsubheading Outputs
## @var{devlist} - a structure containing the midi device information
##
## @subsubheading Examples
## Display the known devices of the system.
## @example
## @command{>} mididevinfo
##
## MIDI devices available
## ID Direction Interface  Name
##  0 output    Alsa       Midi Through:Midi Through Port-0 14:0
##  1 output    Alsa       Ensoniq AudioPCI:ES1371 16:0
##  2 output    Alsa       SparkFun Pro Micro:SparkFun Pro Micro MIDI 1 20:0
##  3 input     Alsa       Midi Through:Midi Through Port-0 14:0
##  4 input     Alsa       Ensoniq AudioPCI:ES1371 16:0
##  5 input     Alsa       SparkFun Pro Micro:SparkFun Pro Micro MIDI 1 20:0 
## @end example
##
## Assign variable @var{mididevices} with the values from the known devices
## @example
## @command{>} mididevices = mididevinfo
##
## mididevices =
##  scalar structure containing the fields:
##    input =
##    @{
##      [1,1] =
##        scalar structure containing the fields:
##          Name = SparkFun Pro Micro:SparkFun Pro Micro MIDI 1 20:0
##          Interface = Alsa
##          ID =  0
##    @}
##    output =
##    @{
##      [1,1] =
##        scalar structure containing the fields:
##          Name = SparkFun Pro Micro:SparkFun Pro Micro MIDI 1 20:0
##          Interface = Alsa
##          ID =  1
##    @}
## @end example
##
## @seealso{mididevice}
## @end deftypefn

function out = mididevinfo ()
  # get dev list
  data = __mididevinfo__();

  # output variable to store to - so assign devices to it
  if nargout > 0
    out = {};
    out.input = {};
    out.output = {};

    for i=1:length(data)
      val = {};
      val.Name = data(i).Name;
      val.Interface = data(i).Interface;
      val.ID = data(i).ID;
      if strcmp (data(i).Direction, "input")
        out.input{end+1} = val;
      else
        out.output{end+1} = val;
      endif
    endfor
  # no output - just display the devices
  else
    printf ("MIDI devices available\n");
    printf ("ID Direction Interface  Name\n");

    for i=1:length(data)
      printf ("%2d %-9s %-10s %s\n", data(i).ID, data(i).Direction, data(i).Interface, data(i).Name);
    endfor
  endif

endfunction

%!xtest
%! a = mididevinfo;
%! assert(length(a) > 0);
%! x = a.input;
%! x = a.output;