Mercurial > octave
annotate scripts/audio/@audioplayer/set.m @ 31549:ed7b17c7ddf3 stable
maint: Strip trailing spaces and add missing EOL to all files.
* README, NEWS.6.md, RELEASE_CHECKLIST.md, README.md, besselj.cc, Array.h,
LSODE.cc, set.m, audiorecorder.m, play.m, set.m, patch.m:
Strip trailing spaces.
* command-widget.cc, led-indicator.cc, led-indicator.h:
Add missing EOL to files.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 25 Nov 2022 21:38:22 -0800 |
parents | 6d96538052b9 |
children | 597f3ee61a48 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
3 ## Copyright (C) 2013-2022 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
19500
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19496
diff
changeset
|
7 ## |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19496
diff
changeset
|
8 ## This file is part of Octave. |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19496
diff
changeset
|
9 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
19500
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19496
diff
changeset
|
11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## (at your option) any later version. |
19500
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19496
diff
changeset
|
14 ## |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19496
diff
changeset
|
15 ## Octave is distributed in the hope that it will be useful, but |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19496
diff
changeset
|
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
19500
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19496
diff
changeset
|
19 ## |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19496
diff
changeset
|
20 ## You should have received a copy of the GNU General Public License |
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19496
diff
changeset
|
21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
19500
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19496
diff
changeset
|
25 |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
26 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
27 ## @deftypefn {} {} set (@var{player}, @var{name}, @var{value}) |
30568
82b685157e2b
doc: Update documentation in audio/ directory.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
28 ## @deftypefnx {} {} set (@var{player}, @var{name_cell}, @var{value_cell}) |
82b685157e2b
doc: Update documentation in audio/ directory.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
29 ## @deftypefnx {} {} set (@var{player}, @var{properties_struct}) |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
30 ## @deftypefnx {} {@var{properties} =} set (@var{player}) |
19505
ce02743b6f2a
Fix texinfo docstring syntax for all audio functions
Mike Miller <mtmiller@ieee.org>
parents:
19503
diff
changeset
|
31 ## Set the value of property specified by @var{name} to a given @var{value}. |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
32 ## |
19506
fdb8a62ef17a
fix docstring style in .m files
John W. Eaton <jwe@octave.org>
parents:
19505
diff
changeset
|
33 ## If @var{name} and @var{value} are cell arrays, set each property to the |
30568
82b685157e2b
doc: Update documentation in audio/ directory.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
34 ## corresponding value. Given a structure of properties with fields |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
35 ## corresponding to property names, set the value of those properties to the |
30568
82b685157e2b
doc: Update documentation in audio/ directory.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
36 ## corresponding field values. Given only an audioplayer object, return a |
82b685157e2b
doc: Update documentation in audio/ directory.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
37 ## structure of configurable properties (i.e., writeable properties). |
82b685157e2b
doc: Update documentation in audio/ directory.
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
38 ## @seealso{@audioplayer/get, @audioplayer/audioplayer} |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
39 ## @end deftypefn |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
40 |
30572 | 41 function properties = set (player, varargin) |
19523
5802ea7037d4
style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents:
19507
diff
changeset
|
42 |
30572 | 43 if (nargin > 3) |
19503
36a26a131209
Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents:
19500
diff
changeset
|
44 print_usage (); |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
45 endif |
19523
5802ea7037d4
style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents:
19507
diff
changeset
|
46 |
30572 | 47 hplayer = struct (player).player; |
19523
5802ea7037d4
style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents:
19507
diff
changeset
|
48 |
19507
dac3191a5301
style fixes for audioplayer and audiorecorder .m files
John W. Eaton <jwe@octave.org>
parents:
19506
diff
changeset
|
49 if (nargin == 1) |
30572 | 50 properties = struct ("SampleRate", {{}}, "Tag", {{}}, "UserData", {{}}); |
19507
dac3191a5301
style fixes for audioplayer and audiorecorder .m files
John W. Eaton <jwe@octave.org>
parents:
19506
diff
changeset
|
51 elseif (nargin == 2) |
30572 | 52 for [value, property] = varargin{1} |
53 setproperty (hplayer, property, value); | |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
54 endfor |
19507
dac3191a5301
style fixes for audioplayer and audiorecorder .m files
John W. Eaton <jwe@octave.org>
parents:
19506
diff
changeset
|
55 elseif (nargin == 3) |
30572 | 56 if (iscell (varargin{1})) |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
57 index = 1; |
30572 | 58 for property = varargin{1} |
59 setproperty (hplayer, char (property), varargin{2}{index}); | |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
60 index += 1; |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
61 endfor |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
62 else |
30572 | 63 setproperty (hplayer, varargin{1}, varargin{2}); |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
64 endif |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
65 endif |
19523
5802ea7037d4
style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents:
19507
diff
changeset
|
66 |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
67 endfunction |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
68 |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
69 function setproperty (player, property, value) |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
70 |
30572 | 71 switch (lower (property)) |
72 case "samplerate" | |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
73 __player_set_fs__ (player, value); |
30572 | 74 case "tag" |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
75 __player_set_tag__ (player, value); |
30572 | 76 case "userdata" |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
77 __player_set_userdata__ (player, value); |
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
78 otherwise |
30572 | 79 error ('@audioplayer/set: "%s" is not a valid property name or is read-only', property); |
19476
e1f98e402a7e
New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff
changeset
|
80 endswitch |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
81 |
19500
8bb399569393
Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents:
19496
diff
changeset
|
82 endfunction |
30572 | 83 |
84 | |
85 %!testif HAVE_PORTAUDIO; audiodevinfo (0) > 0 | |
86 %! player = audioplayer ([-1, 1], 44100, 8); | |
87 %! set (player, "SampleRate", 8800); | |
88 %! set (player, "Tag", "mytag"); | |
89 %! ## Also test case insensitivity | |
90 %! set (player, "USERdata", [1, 2; 3, 4]); | |
91 %! assert (player.SampleRate, 8800); | |
92 %! assert (player.Tag, "mytag"); | |
93 %! assert (player.UserData, [1, 2; 3, 4]); | |
94 | |
95 %!testif HAVE_PORTAUDIO; audiodevinfo (0) > 0 | |
96 %! player = audioplayer ([-1, 1], 44100, 8); | |
97 %! set (player, {"SampleRate", "Tag", "UserData"}, | |
98 %! {8800, "mytag", [1, 2; 3, 4]}); | |
99 %! assert (player.SampleRate, 8800); | |
100 %! assert (player.Tag, "mytag"); | |
101 %! assert (player.UserData, [1, 2; 3, 4]); | |
102 | |
103 %!testif HAVE_PORTAUDIO; audiodevinfo (0) > 0 | |
104 %! player = audioplayer ([-1, 1], 44100, 8); | |
105 %! props = set (player); | |
106 %! props.SampleRate = 8800; | |
107 %! props.Tag = "mytag"; | |
108 %! props.UserData = [1, 2; 3, 4]; | |
109 %! set (player, props); | |
110 %! assert (player.SampleRate, 8800); | |
111 %! assert (player.Tag, "mytag"); | |
112 %! assert (player.UserData, [1, 2; 3, 4]); | |
113 | |
114 ## Test input validation | |
115 %!testif HAVE_PORTAUDIO; audiodevinfo (0) > 0 | |
116 %! player = audioplayer ([-1, 1], 44100, 8); | |
31549
ed7b17c7ddf3
maint: Strip trailing spaces and add missing EOL to all files.
Rik <rik@octave.org>
parents:
30572
diff
changeset
|
117 %! fail ('set (player, "foobar", 1)', "not a valid property name"); |
ed7b17c7ddf3
maint: Strip trailing spaces and add missing EOL to all files.
Rik <rik@octave.org>
parents:
30572
diff
changeset
|
118 %! fail ('set (player, "Running", 1)', "is read-only"); |