annotate scripts/audio/@audioplayer/subsasgn.m @ 30572:6d96538052b9

Overhaul @audioplayer class. Eliminate unnecessary input validation that one argument is supplied to class methods as interpreter guarantees the first argument is an @audioplayer object. Accept case-insensitive property names for get()/set() functions. Add BIST tests on a per function basis rather than only in @audioplayer constructor. * @audioplayer/__get_properties__.m: Eliminate nargin checking. Use intermediate variable hplayer to clarify code. Use ifelse() to simplify 5-line if/else/endif tree. * @audioplayer/audioplayer.m: Add input validation to prevent use of callback functions (not currently supported). Add FIXME note and comment out rudimentary support for callback functions. Remove tests of @audioplayer functionality to the methods files. Add input validation BIST tests for callback function validation. * @audioplayer/disp.m: Eliminate nargin checking. Mark file as tested for BIST. * @audioplayer/get.m: Rename "retval" to "value" in function prototype. Use input parameters with names matching documentation rather than varargin. Use new function getproperty() to do actual property retrieval rather than getfield(). Add BIST tests. * @audioplayer/get.m (getproperty): New function. Function checks property names without regard to case sensitivity and also issues a meaningful error message if the property name does not exist. * @audioplayer/isplaying.m: Eliminate nargin checking. Add BIST tests. * @audioplayer/pause.m: Eliminate nargin checking. Mark file as tested for BIST. * @audioplayer/play.m: Eliminate nargin checking. Use input parameters with names matching documentation rather than varargin. Use intermediate variable hplayer to clarify code. Mark file as tested for BIST. * @audioplayer/playblocking.m: Use input parameters with names matching documentation rather than varargin. Mark file as tested for BIST. * @audioplayer/resume.m: Eliminate nargin checking. Mark file as tested for BIST. * @audioplayer/set.m: Eliminate nargin checking of first argument. Use input parameter "player" for first argument rather than varargin. Use intermediate variable hplayer to clarify code. Add BIST tests. * @audioplayer/set.m (setproperty): Use lower() to implement case insensitive matching of property names. Rewrite error() message to be clearer and report the incorrect name. * @audioplayer/stop.m: Eliminate nargin checking. Mark file as tested for BIST. * @audioplayer/subsasgn.m: Change output variable name to "player" for clarity. Add BIST tests. * @audioplayer/subsref.m: Add BIST tests.
author Rik <rik@octave.org>
date Thu, 30 Dec 2021 16:11:55 -0800
parents 82b685157e2b
children 597f3ee61a48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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: 19488
diff changeset
7 ##
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19488
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: 19488
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: 19488
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: 19488
diff changeset
14 ##
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19488
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: 19488
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: 19488
diff changeset
19 ##
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19488
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: 19488
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: 19488
diff changeset
25
19504
d7b55fc1b37d Add missing texinfo docstrings to all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19503
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
27 ## @deftypefn {} {@var{value} =} subsasgn (@var{player}, @var{idx}, @var{rhs})
19504
d7b55fc1b37d Add missing texinfo docstrings to all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19503
diff changeset
28 ## Perform subscripted assignment on the audio player object @var{player}.
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
29 ##
19504
d7b55fc1b37d Add missing texinfo docstrings to all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19503
diff changeset
30 ## Assign the value of @var{rhs} to the player property named by @var{idx}.
30568
82b685157e2b doc: Update documentation in audio/ directory.
Rik <rik@octave.org>
parents: 30564
diff changeset
31 ## @seealso{@audioplayer/audioplayer}
19504
d7b55fc1b37d Add missing texinfo docstrings to all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19503
diff changeset
32 ## @end deftypefn
d7b55fc1b37d Add missing texinfo docstrings to all audio functions
Mike Miller <mtmiller@ieee.org>
parents: 19503
diff changeset
33
19503
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19500
diff changeset
34 function value = subsasgn (player, idx, rhs)
19523
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19504
diff changeset
35
30572
6d96538052b9 Overhaul @audioplayer class.
Rik <rik@octave.org>
parents: 30568
diff changeset
36 if (nargin != 3)
6d96538052b9 Overhaul @audioplayer class.
Rik <rik@octave.org>
parents: 30568
diff changeset
37 print_usage ();
6d96538052b9 Overhaul @audioplayer class.
Rik <rik@octave.org>
parents: 30568
diff changeset
38 endif
6d96538052b9 Overhaul @audioplayer class.
Rik <rik@octave.org>
parents: 30568
diff changeset
39
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
40 if (isempty (idx))
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
41 error ("audioplayer: missing index");
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
42 endif
19523
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19504
diff changeset
43
19503
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19500
diff changeset
44 if (strcmp (idx(1).type, "."))
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
45 field = idx.subs;
19503
36a26a131209 Apply Octave coding style to audio project additions
Mike Miller <mtmiller@ieee.org>
parents: 19500
diff changeset
46 set (player, field, rhs);
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
47 value = player;
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
48 else
19523
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19504
diff changeset
49 error ("@audioplayer/subsasgn: invalid subscript type");
19476
e1f98e402a7e New files - @audiorecorder and @audioplayer classes
Vytautas Jančauskas <unaudio@gmail.com>
parents:
diff changeset
50 endif
19523
5802ea7037d4 style fixes for audioplayer and audiorecorder classes
John W. Eaton <jwe@octave.org>
parents: 19504
diff changeset
51
19500
8bb399569393 Add Octave copyright header block to audio project files
Mike Miller <mtmiller@ieee.org>
parents: 19488
diff changeset
52 endfunction
30572
6d96538052b9 Overhaul @audioplayer class.
Rik <rik@octave.org>
parents: 30568
diff changeset
53
6d96538052b9 Overhaul @audioplayer class.
Rik <rik@octave.org>
parents: 30568
diff changeset
54
6d96538052b9 Overhaul @audioplayer class.
Rik <rik@octave.org>
parents: 30568
diff changeset
55 %!testif HAVE_PORTAUDIO; audiodevinfo (0) > 0
6d96538052b9 Overhaul @audioplayer class.
Rik <rik@octave.org>
parents: 30568
diff changeset
56 %! player = audioplayer ([-1, 1], 44100, 8);
6d96538052b9 Overhaul @audioplayer class.
Rik <rik@octave.org>
parents: 30568
diff changeset
57 %! player.Tag = "mytag";
6d96538052b9 Overhaul @audioplayer class.
Rik <rik@octave.org>
parents: 30568
diff changeset
58 %! assert (get (player, "Tag"), "mytag");
6d96538052b9 Overhaul @audioplayer class.
Rik <rik@octave.org>
parents: 30568
diff changeset
59
6d96538052b9 Overhaul @audioplayer class.
Rik <rik@octave.org>
parents: 30568
diff changeset
60 ## Test input validation
6d96538052b9 Overhaul @audioplayer class.
Rik <rik@octave.org>
parents: 30568
diff changeset
61 %!testif HAVE_PORTAUDIO; audiodevinfo (0) > 0
6d96538052b9 Overhaul @audioplayer class.
Rik <rik@octave.org>
parents: 30568
diff changeset
62 %! player = audioplayer ([-1, 1], 44100, 8);
6d96538052b9 Overhaul @audioplayer class.
Rik <rik@octave.org>
parents: 30568
diff changeset
63 %! fail ("player(1).Tag = 5", "invalid subscript type");
6d96538052b9 Overhaul @audioplayer class.
Rik <rik@octave.org>
parents: 30568
diff changeset
64 %! fail ("player{1}.Tag = 5", "invalid subscript type");