changeset 19557:5802ea7037d4

style fixes for audioplayer and audiorecorder classes * @audioplayer/__get_properties__.m, @audioplayer/audioplayer.m, @audioplayer/display.m, @audioplayer/get.m, @audioplayer/isplaying.m, @audioplayer/pause.m, @audioplayer/play.m, @audioplayer/playblocking.m, @audioplayer/resume.m, @audioplayer/set.m, @audioplayer/stop.m, @audioplayer/subsasgn.m, @audioplayer/subsref.m, @audiorecorder/__get_properties__.m, @audiorecorder/audiorecorder.m, @audiorecorder/display.m, @audiorecorder/get.m, @audiorecorder/getaudiodata.m, @audiorecorder/getplayer.m, @audiorecorder/isrecording.m, @audiorecorder/pause.m, @audiorecorder/play.m, @audiorecorder/record.m, @audiorecorder/recordblocking.m, @audiorecorder/resume.m, @audiorecorder/set.m, @audiorecorder/stop.m, @audiorecorder/subsasgn.m, @audiorecorder/subsref.m: Style fixes. Do more basic argument checking. Use consistent style for error messages.
author John W. Eaton <jwe@octave.org>
date Fri, 02 Jan 2015 17:23:38 -0500
parents fc03d6e0d842
children ffc339cea115
files scripts/audio/@audioplayer/__get_properties__.m scripts/audio/@audioplayer/audioplayer.m scripts/audio/@audioplayer/display.m scripts/audio/@audioplayer/get.m scripts/audio/@audioplayer/isplaying.m scripts/audio/@audioplayer/pause.m scripts/audio/@audioplayer/play.m scripts/audio/@audioplayer/playblocking.m scripts/audio/@audioplayer/resume.m scripts/audio/@audioplayer/set.m scripts/audio/@audioplayer/stop.m scripts/audio/@audioplayer/subsasgn.m scripts/audio/@audioplayer/subsref.m scripts/audio/@audiorecorder/__get_properties__.m scripts/audio/@audiorecorder/audiorecorder.m scripts/audio/@audiorecorder/display.m scripts/audio/@audiorecorder/get.m scripts/audio/@audiorecorder/getaudiodata.m scripts/audio/@audiorecorder/getplayer.m scripts/audio/@audiorecorder/isrecording.m scripts/audio/@audiorecorder/pause.m scripts/audio/@audiorecorder/play.m scripts/audio/@audiorecorder/record.m scripts/audio/@audiorecorder/recordblocking.m scripts/audio/@audiorecorder/resume.m scripts/audio/@audiorecorder/set.m scripts/audio/@audiorecorder/stop.m scripts/audio/@audiorecorder/subsasgn.m scripts/audio/@audiorecorder/subsref.m
diffstat 29 files changed, 185 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/audio/@audioplayer/__get_properties__.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audioplayer/__get_properties__.m	Fri Jan 02 17:23:38 2015 -0500
@@ -23,6 +23,11 @@
 ## @end deftypefn
 
 function props = __get_properties__ (player)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
   if (__player_isplaying__ (struct (player).player))
     running = "on";
   else
--- a/scripts/audio/@audioplayer/audioplayer.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audioplayer/audioplayer.m	Fri Jan 02 17:23:38 2015 -0500
@@ -73,17 +73,17 @@
 ## @end example
 
 function player = audioplayer (varargin)
-  if (nargin < 1 || nargin > 4)
+
+  if (nargin < 1 || nargin > 4
+      || (nargin < 2 && (isa (varargin{1}, "function_handle")
+                         || ischar (varargin{1}))))
     print_usage ();
   endif
-  if ((isa (varargin{1}, "function_handle")
-       || ischar (varargin{1})) && nargin < 2)
-    print_usage ();
-  endif
-  if isa (varargin{1}, "audiorecorder")
-    if nargin == 1
+
+  if (isa (varargin{1}, "audiorecorder"))
+    if (nargin == 1)
       player = getplayer (varargin{1});
-    elseif nargin == 2
+    elseif (nargin == 2)
       recorder = varargin{1};
       data = getaudiodata (recorder);
       player = audioplayer (data, get (recorder, "SampleRate"),
@@ -98,6 +98,7 @@
     player.player = __player_audioplayer__ (varargin{:});
     player = class (player, "audioplayer");
   endif
+
 endfunction
 
 %!test
--- a/scripts/audio/@audioplayer/display.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audioplayer/display.m	Fri Jan 02 17:23:38 2015 -0500
@@ -22,5 +22,11 @@
 ## @end deftypefn
 
 function display (player)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
   disp (__get_properties__ (player));
+
 endfunction
--- a/scripts/audio/@audioplayer/get.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audioplayer/get.m	Fri Jan 02 17:23:38 2015 -0500
@@ -27,23 +27,28 @@
 ## correspond to property names.
 ## @end deftypefn
 
-function result = get (varargin)
-  player = varargin{1};
-  properties = __get_properties__ (player);
+function retval = get (varargin)
+
+  if (nargin < 1 || nargin > 2)
+    print_usage ();
+  endif
+
+  properties = __get_properties__ (varargin{1});
+
   if (nargin == 1)
-    result = properties;
+    retval = properties;
   elseif (nargin == 2)
-    if (ischar (varargin{2}))
-      result = getfield (properties, varargin{2});
+    pnames = varargin{2};
+    if (ischar (pnames))
+      retval = getfield (properties, pnames);
+    elseif (iscellstr (pnames))
+      retval = cell (size (pnames));
+      for i = 1:numel (pnames)
+        retval{i} = getfield (properties, pnames{i});
+      endfor
     else
-      result = {};
-      index = 1;
-      for property = varargin{2}
-        result{index} = getfield (properties, char (property));
-        index = index + 1;
-      endfor
+      error ("@audioplayer/get: invalid name argument");
     endif
-  else
-    error ("audioplayer: wrong number of arguments to the get method");
   endif
+
 endfunction
--- a/scripts/audio/@audioplayer/isplaying.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audioplayer/isplaying.m	Fri Jan 02 17:23:38 2015 -0500
@@ -23,5 +23,11 @@
 ## @end deftypefn
 
 function result = isplaying (player)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
   result = __player_isplaying__ (struct (player).player);
+
 endfunction
--- a/scripts/audio/@audioplayer/pause.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audioplayer/pause.m	Fri Jan 02 17:23:38 2015 -0500
@@ -22,5 +22,11 @@
 ## @end deftypefn
 
 function pause (player)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
   __player_pause__ (struct (player).player);
+
 endfunction
--- a/scripts/audio/@audioplayer/play.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audioplayer/play.m	Fri Jan 02 17:23:38 2015 -0500
@@ -28,8 +28,11 @@
 ## @end deftypefn
 
 function play (varargin)
+
   if (nargin < 1 || nargin > 2)
     print_usage ();
   endif
+
   __player_play__ (struct (varargin{1}).player, varargin{2:end});
+
 endfunction
--- a/scripts/audio/@audioplayer/playblocking.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audioplayer/playblocking.m	Fri Jan 02 17:23:38 2015 -0500
@@ -28,8 +28,11 @@
 ## @end deftypefn
 
 function playblocking (varargin)
+
   if (nargin < 1 || nargin > 2)
     print_usage ();
   endif
+
   __player_playblocking__ (struct (varargin{1}).player, varargin{2:end});
+
 endfunction
--- a/scripts/audio/@audioplayer/resume.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audioplayer/resume.m	Fri Jan 02 17:23:38 2015 -0500
@@ -22,5 +22,11 @@
 ## @end deftypefn
 
 function resume (player)
+
+  if (nargin == 1)
+    print_usage ();
+  endif
+
   __player_resume__ (struct (player).player);
+
 endfunction
--- a/scripts/audio/@audioplayer/set.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audioplayer/set.m	Fri Jan 02 17:23:38 2015 -0500
@@ -29,10 +29,13 @@
 ## @end deftypefn
 
 function settable = set (varargin)
+
   if (nargin < 1 || nargin > 3)
     print_usage ();
   endif
+
   player = struct (varargin{1}).player;
+
   if (nargin == 1)
     settable.SampleRate = {};
     settable.Tag = {};
@@ -52,8 +55,9 @@
       setproperty (player, varargin{2}, varargin{3});
     endif
   else
-    error ("audioplayer: wrong number of arguments to the set method");
+    error ("@audioplayer/set: wrong number of arguments to the set method");
   endif
+
 endfunction
 
 function setproperty (player, property, value)
--- a/scripts/audio/@audioplayer/stop.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audioplayer/stop.m	Fri Jan 02 17:23:38 2015 -0500
@@ -23,5 +23,11 @@
 ## @end deftypefn
 
 function stop (player)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
   __player_stop__ (struct (player).player);
+
 endfunction
--- a/scripts/audio/@audioplayer/subsasgn.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audioplayer/subsasgn.m	Fri Jan 02 17:23:38 2015 -0500
@@ -23,14 +23,17 @@
 ## @end deftypefn
 
 function value = subsasgn (player, idx, rhs)
+
   if (isempty (idx))
     error ("audioplayer: missing index");
   endif
+
   if (strcmp (idx(1).type, "."))
     field = idx.subs;
     set (player, field, rhs);
     value = player;
   else
-    error ("audioplayer: invalid subscript type");
+    error ("@audioplayer/subsasgn: invalid subscript type");
   endif
+
 endfunction
--- a/scripts/audio/@audioplayer/subsref.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audioplayer/subsref.m	Fri Jan 02 17:23:38 2015 -0500
@@ -23,13 +23,19 @@
 ## @end deftypefn
 
 function value = subsref (player, idx)
+  if (nargin != 2)
+    print_usage ();
+  endif
+
   if (isempty (idx))
-    error ("audioplayer: missing index");
+    error ("@audioplayer/subsref: missing index");
   endif
+
   if (strcmp (idx(1).type, "."))
     field = idx.subs;
     value = get (player, field);
   else
-    error ("audioplayer: invalid subscript file")
+    error ("@audioplayer/subsref: invalid subscript type")
   endif
+
 endfunction
--- a/scripts/audio/@audiorecorder/__get_properties__.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audiorecorder/__get_properties__.m	Fri Jan 02 17:23:38 2015 -0500
@@ -23,6 +23,11 @@
 ## @end deftypefn
 
 function props = __get_properties__ (recorder)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
   if (__recorder_isrecording__ (struct (recorder).recorder))
     running = "on";
   else
--- a/scripts/audio/@audiorecorder/audiorecorder.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audiorecorder/audiorecorder.m	Fri Jan 02 17:23:38 2015 -0500
@@ -30,14 +30,18 @@
 ## @end deftypefn
 
 function recorder = audiorecorder (varargin)
+
   if (nargin > 5)
     print_usage ();
   endif
+
   if (nargin > 0 && ischar (varargin{1}))
     varargin{1} = str2func (varargin{1});
   endif
+
   recorder.recorder = __recorder_audiorecorder__ (varargin{:});
   recorder = class (recorder, "audiorecorder");
+
 endfunction
 
 %!test
--- a/scripts/audio/@audiorecorder/display.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audiorecorder/display.m	Fri Jan 02 17:23:38 2015 -0500
@@ -22,5 +22,11 @@
 ## @end deftypefn
 
 function display (recorder)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
   disp (__get_properties__ (recorder));
+
 endfunction
--- a/scripts/audio/@audiorecorder/get.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audiorecorder/get.m	Fri Jan 02 17:23:38 2015 -0500
@@ -27,23 +27,28 @@
 ## correspond to property names.
 ## @end deftypefn
 
-function result = get (varargin)
-  recorder = varargin{1};
-  properties = __get_properties__ (recorder);
+function retval = get (varargin)
+
+  if (nargin < 1 || nargin > 2)
+    print_usage ();
+  endif
+
+  properties = __get_properties__ (varargin{1});
+
   if (nargin == 1)
-    result = properties;
+    retval = properties;
   elseif (nargin == 2)
-    if (ischar (varargin{2}))
-      result = getfield (properties, varargin{2});
+    pnames = varargin{2};
+    if (ischar (pnames))
+      retval = getfield (properties, pnames);
+    elseif (iscellstr (pnames))
+      retval = cell (size (pnames));
+      for i = 1:numel (pnames)
+        retval{i} = getfield (properties, pnames{i});
+      endfor
     else
-      result = {};
-      index = 1;
-      for property = varargin{2}
-        result{index} = getfield (properties, char (property));
-        index = index + 1;
-      endfor
+      error ("@audiorecorder/get: invalid name argument");
     endif
-  else
-    error ("audiorecorder: wrong number of arguments to the get method");
   endif
+
 endfunction
--- a/scripts/audio/@audiorecorder/getaudiodata.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audiorecorder/getaudiodata.m	Fri Jan 02 17:23:38 2015 -0500
@@ -27,10 +27,13 @@
 ## @end deftypefn
 
 function data = getaudiodata (varargin)
+
   if (nargin < 1 || nargin > 2)
     print_usage ();
   endif
+
   recorder = varargin{1};
+
   if (nargin == 1)
     data = __recorder_getaudiodata__ (struct (recorder).recorder);
   else
@@ -45,9 +48,11 @@
         data = uint8 ((data + 1.0) * 0.5 * (2.0 ^ 8 - 1));
     endswitch
   endif
+
   if (get (recorder, "NumberOfChannels") == 2)
     data = data';
   else
     data = data(1,:)';
   endif
+
 endfunction
--- a/scripts/audio/@audiorecorder/getplayer.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audiorecorder/getplayer.m	Fri Jan 02 17:23:38 2015 -0500
@@ -23,11 +23,14 @@
 ## @end deftypefn
 
 function player = getplayer (varargin)
+
   if (nargin < 1 || nargin > 2)
     print_usage ();
   endif
+
   recorder = varargin{1};
   data = getaudiodata (recorder);
   player = audioplayer (data, get (recorder, "SampleRate"),
                         get (recorder, "BitsPerSample"));
+
 endfunction
--- a/scripts/audio/@audiorecorder/isrecording.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audiorecorder/isrecording.m	Fri Jan 02 17:23:38 2015 -0500
@@ -23,5 +23,11 @@
 ## @end deftypefn
 
 function result = isrecording (recorder)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
   result = __recorder_isrecording__ (struct (recorder).recorder);
+
 endfunction
--- a/scripts/audio/@audiorecorder/pause.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audiorecorder/pause.m	Fri Jan 02 17:23:38 2015 -0500
@@ -22,5 +22,11 @@
 ## @end deftypefn
 
 function pause (recorder)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
   __recorder_pause__ (struct (recorder).recorder);
+
 endfunction
--- a/scripts/audio/@audiorecorder/play.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audiorecorder/play.m	Fri Jan 02 17:23:38 2015 -0500
@@ -28,9 +28,11 @@
 ## @end deftypefn
 
 function player = play (varargin)
+
   if (nargin < 1 || nargin > 2)
     print_usage ();
   endif
+
   recorder = varargin{1};
   data = getaudiodata (recorder);
   player = audioplayer (data, get (recorder, "SampleRate"),
@@ -40,4 +42,5 @@
   else
     play (player, varargin{2});
   endif
+
 endfunction
--- a/scripts/audio/@audiorecorder/record.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audiorecorder/record.m	Fri Jan 02 17:23:38 2015 -0500
@@ -26,8 +26,11 @@
 ## @end deftypefn
 
 function record (varargin)
+
   if (nargin < 1 || nargin > 2)
     print_usage ();
   endif
+
   __recorder_record__ (struct (varargin{1}).recorder, varargin{2:end});
+
 endfunction
--- a/scripts/audio/@audiorecorder/recordblocking.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audiorecorder/recordblocking.m	Fri Jan 02 17:23:38 2015 -0500
@@ -23,8 +23,11 @@
 ## @end deftypefn
 
 function recordblocking (varargin)
+
   if (nargin != 2)
     print_usage ();
   endif
+
   __recorder_recordblocking__ (struct (varargin{1}).recorder, varargin{2});
+
 endfunction
--- a/scripts/audio/@audiorecorder/resume.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audiorecorder/resume.m	Fri Jan 02 17:23:38 2015 -0500
@@ -22,5 +22,11 @@
 ## @end deftypefn
 
 function resume (recorder)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
   __recorder_resume__ (struct (recorder).recorder);
+
 endfunction
--- a/scripts/audio/@audiorecorder/set.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audiorecorder/set.m	Fri Jan 02 17:23:38 2015 -0500
@@ -30,10 +30,13 @@
 ## @end deftypefn
 
 function settable = set (varargin)
+
   if (nargin < 1 || nargin > 3)
     print_usage ();
   endif
+
   recorder = struct (varargin{1}).recorder;
+
   if (nargin == 1)
     settable.SampleRate = {};
     settable.Tag = {};
@@ -52,12 +55,12 @@
     else
       setproperty (recorder, varargin{2}, varargin{3});
     endif
-  else
-    error ("audiorecorder: wrong number of arguments to the set method");
   endif
+
 endfunction
 
 function setproperty (recorder, property, value)
+
   switch (property)
     case "SampleRate"
       __recorder_set_fs__ (recorder, value);
@@ -66,6 +69,7 @@
     case "UserData"
       __recorder_set_userdata__ (recorder, value);
     otherwise
-      error ("audiorecorder: no such property or the property specified is read-only");
+      error ("@audiorecorder/set: no such property or the property specified is read-only");
   endswitch
+
 endfunction
--- a/scripts/audio/@audiorecorder/stop.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audiorecorder/stop.m	Fri Jan 02 17:23:38 2015 -0500
@@ -23,5 +23,11 @@
 ## @end deftypefn
 
 function stop (recorder)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
   __recorder_stop__ (struct (recorder).recorder);
+
 endfunction
--- a/scripts/audio/@audiorecorder/subsasgn.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audiorecorder/subsasgn.m	Fri Jan 02 17:23:38 2015 -0500
@@ -23,14 +23,20 @@
 ## @end deftypefn
 
 function value = subsasgn (recorder, idx, rhs)
+  if (nargin != 3)
+    print_usage ();
+  endif
+
   if (isempty (idx))
-    error ("audiorecorder: missing index");
+    error ("@audiorecorder/subsasgn: missing index");
   endif
+
   if (strcmp (idx(1).type, "."))
     field = idx.subs;
     set (recorder, field, rhs);
     value = recorder;
   else
-    error ("audiorecorder: invalid subscript type");
+    error ("@audiorecorder/subsasgn: invalid subscript type");
   endif
+
 endfunction
--- a/scripts/audio/@audiorecorder/subsref.m	Fri Jan 02 16:54:34 2015 -0500
+++ b/scripts/audio/@audiorecorder/subsref.m	Fri Jan 02 17:23:38 2015 -0500
@@ -23,13 +23,20 @@
 ## @end deftypefn
 
 function value = subsref (recorder, idx)
+
+  if (nargin != 2)
+    print_usage ();
+  endif
+
   if (isempty (idx))
-    error ("audiorecorder: missing index");
+    error ("@audiorecorder/subsref: missing index");
   endif
+
   if (strcmp (idx(1).type, "."))
     field = idx.subs;
     value = get (recorder, field);
   else
-    error ("audiorecorder: invalid subscript file")
+    error ("@audiorecorder/subsref: invalid subscript type")
   endif
+
 endfunction