beeps 0.1.40 → 0.1.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 958deb93498bd6162e818812483f40d24a777ca63e55e14b662d08685bc95e72
4
- data.tar.gz: 44c17780aad9c76d9b69e1a52b4adf2f6b95bb62e1e62d0653b7514a66a17f20
3
+ metadata.gz: 3208db0b54212d8a78bae1faf4ea83e9dd866532d2348fc95ee39160df814111
4
+ data.tar.gz: 296f31a3dd5eb00da5e58b7e37f6d7684588e77f03bea198511506403e419cf2
5
5
  SHA512:
6
- metadata.gz: 76aaff1b3aa7d871b637b79808088832d7ba161d8dd24234b2f8bc7b0171b8c2b465bb007a496c3530e512be6aed57d5fb8cc2b03460ae96203e096d0e76bf5f
7
- data.tar.gz: ab615290855d8b923f8de24d1eabd3ad6ec39bde2a3834ca2131b7cd7660becdae6224bfee707b12123a0e7b66a5bf7077248f99dc1b9347dadbdc9ef0328f27
6
+ metadata.gz: 9f84af845319c5bee3caee397685560dce92e7cb711ecd2119cf632c2a9614cc7ddb85c11eb6df888f240866fd83847d9c603d48c7489fcf62ea9cb01c1ba96d
7
+ data.tar.gz: 39b3a5f1e602a4e26a563bcef1db69eebc05a1fdbfa919cc255925875108fa445d983d17212c82f08ccf706f8826c29cde9fc69580777092c65717b92857df9c
@@ -66,11 +66,12 @@ Init_beeps_oscillator ()
66
66
  rb_define_method(cOscillator, "type", RUBY_METHOD_FUNC(get_type), 0);
67
67
  rb_define_method(cOscillator, "frequency=", RUBY_METHOD_FUNC(set_frequency), 1);
68
68
  rb_define_method(cOscillator, "frequency", RUBY_METHOD_FUNC(get_frequency), 0);
69
- cOscillator.define_const("NONE", Beeps::Oscillator::NONE);
70
- cOscillator.define_const("SINE", Beeps::Oscillator::SINE);
71
- cOscillator.define_const("TRIANGLE", Beeps::Oscillator::TRIANGLE);
72
- cOscillator.define_const("SQUARE", Beeps::Oscillator::SQUARE);
73
- cOscillator.define_const("SAWTOOTH", Beeps::Oscillator::SAWTOOTH);
69
+
70
+ cOscillator.define_const("TYPE_NONE", Beeps::Oscillator::TYPE_NONE);
71
+ cOscillator.define_const("SINE", Beeps::Oscillator::SINE);
72
+ cOscillator.define_const("TRIANGLE", Beeps::Oscillator::TRIANGLE);
73
+ cOscillator.define_const("SQUARE", Beeps::Oscillator::SQUARE);
74
+ cOscillator.define_const("SAWTOOTH", Beeps::Oscillator::SAWTOOTH);
74
75
  }
75
76
 
76
77
 
@@ -54,27 +54,11 @@ VALUE stop(VALUE self)
54
54
  }
55
55
 
56
56
  static
57
- VALUE is_playing(VALUE self)
57
+ VALUE get_state(VALUE self)
58
58
  {
59
59
  CHECK;
60
60
 
61
- return value(THIS->is_playing());
62
- }
63
-
64
- static
65
- VALUE is_paused(VALUE self)
66
- {
67
- CHECK;
68
-
69
- return value(THIS->is_paused());
70
- }
71
-
72
- static
73
- VALUE is_stopped(VALUE self)
74
- {
75
- CHECK;
76
-
77
- return value(THIS->is_stopped());
61
+ return value(THIS->state());
78
62
  }
79
63
 
80
64
  static
@@ -131,14 +115,17 @@ Init_beeps_sound_player ()
131
115
  rb_define_method(cSoundPlayer, "pause", RUBY_METHOD_FUNC(pause), 0);
132
116
  rb_define_method(cSoundPlayer, "rewind", RUBY_METHOD_FUNC(rewind), 0);
133
117
  rb_define_method(cSoundPlayer, "stop", RUBY_METHOD_FUNC(stop), 0);
134
- cSoundPlayer.define_method("playing?", is_playing);
135
- cSoundPlayer.define_method("paused?", is_paused);
136
- cSoundPlayer.define_method("stopped?", is_stopped);
118
+ rb_define_method(cSoundPlayer, "state", RUBY_METHOD_FUNC(get_state), 0);
137
119
  rb_define_method(cSoundPlayer, "gain=", RUBY_METHOD_FUNC(set_gain), 1);
138
120
  rb_define_method(cSoundPlayer, "gain", RUBY_METHOD_FUNC(get_gain), 0);
139
121
  rb_define_method(cSoundPlayer, "loop=", RUBY_METHOD_FUNC(set_loop), 1);
140
122
  rb_define_method(cSoundPlayer, "loop", RUBY_METHOD_FUNC(get_loop), 0);
141
123
  rb_define_singleton_method(cSoundPlayer, "stop_all", RUBY_METHOD_FUNC(stop_all), 0);
124
+
125
+ cSoundPlayer.define_const("STATE_UNKNOWN", Beeps::SoundPlayer::STATE_UNKNOWN);
126
+ cSoundPlayer.define_const("PLAYING", Beeps::SoundPlayer::PLAYING);
127
+ cSoundPlayer.define_const("PAUSED", Beeps::SoundPlayer::PAUSED);
128
+ cSoundPlayer.define_const("STOPPED", Beeps::SoundPlayer::STOPPED);
142
129
  }
143
130
 
144
131
 
data/ChangeLog.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # beeps ChangeLog
2
2
 
3
3
 
4
+ ## [v0.1.41] - 2023-06-27
5
+
6
+ - Add SoundPlayer#state()
7
+ - Delete SoundPlayer#is_playing(), is_paused(), and is_stopped()
8
+ - NONE -> TYPE_NONE
9
+
10
+
4
11
  ## [v0.1.40] - 2023-05-29
5
12
 
6
13
  - Update dependencies
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.40
1
+ 0.1.41
@@ -71,11 +71,12 @@ Init_beeps_oscillator ()
71
71
  cOscillator.define_method("type", get_type);
72
72
  cOscillator.define_method("frequency=", set_frequency);
73
73
  cOscillator.define_method("frequency", get_frequency);
74
- cOscillator.define_const("NONE", Beeps::Oscillator::NONE);
75
- cOscillator.define_const("SINE", Beeps::Oscillator::SINE);
76
- cOscillator.define_const("TRIANGLE", Beeps::Oscillator::TRIANGLE);
77
- cOscillator.define_const("SQUARE", Beeps::Oscillator::SQUARE);
78
- cOscillator.define_const("SAWTOOTH", Beeps::Oscillator::SAWTOOTH);
74
+
75
+ cOscillator.define_const("TYPE_NONE", Beeps::Oscillator::TYPE_NONE);
76
+ cOscillator.define_const("SINE", Beeps::Oscillator::SINE);
77
+ cOscillator.define_const("TRIANGLE", Beeps::Oscillator::TRIANGLE);
78
+ cOscillator.define_const("SQUARE", Beeps::Oscillator::SQUARE);
79
+ cOscillator.define_const("SAWTOOTH", Beeps::Oscillator::SAWTOOTH);
79
80
  }
80
81
 
81
82
 
@@ -59,29 +59,11 @@ RUCY_DEF0(stop)
59
59
  RUCY_END
60
60
 
61
61
  static
62
- RUCY_DEF0(is_playing)
62
+ RUCY_DEF0(get_state)
63
63
  {
64
64
  CHECK;
65
65
 
66
- return value(THIS->is_playing());
67
- }
68
- RUCY_END
69
-
70
- static
71
- RUCY_DEF0(is_paused)
72
- {
73
- CHECK;
74
-
75
- return value(THIS->is_paused());
76
- }
77
- RUCY_END
78
-
79
- static
80
- RUCY_DEF0(is_stopped)
81
- {
82
- CHECK;
83
-
84
- return value(THIS->is_stopped());
66
+ return value(THIS->state());
85
67
  }
86
68
  RUCY_END
87
69
 
@@ -144,14 +126,17 @@ Init_beeps_sound_player ()
144
126
  cSoundPlayer.define_method("pause", pause);
145
127
  cSoundPlayer.define_method("rewind", rewind);
146
128
  cSoundPlayer.define_method("stop", stop);
147
- cSoundPlayer.define_method("playing?", is_playing);
148
- cSoundPlayer.define_method("paused?", is_paused);
149
- cSoundPlayer.define_method("stopped?", is_stopped);
129
+ cSoundPlayer.define_method("state", get_state);
150
130
  cSoundPlayer.define_method("gain=", set_gain);
151
131
  cSoundPlayer.define_method("gain", get_gain);
152
132
  cSoundPlayer.define_method("loop=", set_loop);
153
133
  cSoundPlayer.define_method("loop", get_loop);
154
134
  cSoundPlayer.define_singleton_method("stop_all", stop_all);
135
+
136
+ cSoundPlayer.define_const("STATE_UNKNOWN", Beeps::SoundPlayer::STATE_UNKNOWN);
137
+ cSoundPlayer.define_const("PLAYING", Beeps::SoundPlayer::PLAYING);
138
+ cSoundPlayer.define_const("PAUSED", Beeps::SoundPlayer::PAUSED);
139
+ cSoundPlayer.define_const("STOPPED", Beeps::SoundPlayer::STOPPED);
155
140
  }
156
141
 
157
142
 
@@ -18,7 +18,7 @@ namespace Beeps
18
18
 
19
19
  public:
20
20
 
21
- enum Type {NONE = 0, SINE, TRIANGLE, SQUARE, SAWTOOTH};
21
+ enum Type {TYPE_NONE = 0, SINE, TRIANGLE, SQUARE, SAWTOOTH};
22
22
 
23
23
  Oscillator (Type type = SINE);
24
24
 
@@ -20,6 +20,19 @@ namespace Beeps
20
20
 
21
21
  public:
22
22
 
23
+ enum State
24
+ {
25
+
26
+ STATE_UNKNOWN = 0,
27
+
28
+ PLAYING,
29
+
30
+ PAUSED,
31
+
32
+ STOPPED
33
+
34
+ };// State
35
+
23
36
  SoundPlayer ();
24
37
 
25
38
  ~SoundPlayer ();
@@ -32,11 +45,7 @@ namespace Beeps
32
45
 
33
46
  void stop ();
34
47
 
35
- bool is_playing () const;
36
-
37
- bool is_paused () const;
38
-
39
- bool is_stopped () const;
48
+ State state () const;
40
49
 
41
50
  void set_gain (float gain);
42
51
 
@@ -36,7 +36,7 @@ module Beeps
36
36
  class Oscillator
37
37
 
38
38
  const_symbol_accessor :type, **{
39
- none: NONE,
39
+ none: TYPE_NONE,
40
40
  sine: SINE,
41
41
  triangle: TRIANGLE,
42
42
  square: SQUARE,
data/lib/beeps/sound.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'xot/setter'
2
+ require 'xot/const_symbol_accessor'
2
3
  require 'xot/universal_accessor'
3
4
  require 'xot/block_util'
4
5
  require 'beeps/ext'
@@ -35,6 +36,25 @@ module Beeps
35
36
 
36
37
  include Xot::Setter
37
38
 
39
+ const_symbol_reader :state, **{
40
+ unknown: STATE_UNKNOWN,
41
+ playing: PLAYING,
42
+ paused: PAUSED,
43
+ stopped: STOPPED
44
+ }
45
+
46
+ def playing?()
47
+ state == :playing
48
+ end
49
+
50
+ def paused?()
51
+ state == :paused
52
+ end
53
+
54
+ def stopped?()
55
+ state == :stopped
56
+ end
57
+
38
58
  universal_accessor :gain, :loop
39
59
 
40
60
  end# SoundPlayer
data/src/oscillator.cpp CHANGED
@@ -15,7 +15,7 @@ namespace Beeps
15
15
  struct Oscillator::Data
16
16
  {
17
17
 
18
- Type type = NONE;
18
+ Type type = TYPE_NONE;
19
19
 
20
20
  float frequency = 440;
21
21
 
@@ -137,7 +137,7 @@ namespace Beeps
137
137
  {
138
138
  if (!Super::operator bool()) return false;
139
139
  return
140
- self->type != NONE && self->frequency > 0 &&
140
+ self->type != TYPE_NONE && self->frequency > 0 &&
141
141
  (self->sine || self->square || self->saw);
142
142
  }
143
143
 
data/src/sound.cpp CHANGED
@@ -249,37 +249,21 @@ namespace Beeps
249
249
  }
250
250
  }
251
251
 
252
- bool is_playing () const
252
+ SoundPlayer::State state () const
253
253
  {
254
- if (!*this) return false;
255
-
256
- ALint state = 0;
257
- alGetSourcei(self->id, AL_SOURCE_STATE, &state);
258
- OpenAL_check_error(__FILE__, __LINE__);
259
-
260
- return state == AL_PLAYING;
261
- }
262
-
263
- bool is_paused () const
264
- {
265
- if (!*this) return false;
266
-
267
- ALint state = 0;
268
- alGetSourcei(self->id, AL_SOURCE_STATE, &state);
269
- OpenAL_check_error(__FILE__, __LINE__);
270
-
271
- return state == AL_PAUSED;
272
- }
273
-
274
- bool is_stopped () const
275
- {
276
- if (!*this) return true;
254
+ if (!*this) return SoundPlayer::STATE_UNKNOWN;
277
255
 
278
256
  ALint state = 0;
279
257
  alGetSourcei(self->id, AL_SOURCE_STATE, &state);
280
258
  OpenAL_check_error(__FILE__, __LINE__);
281
259
 
282
- return state == AL_STOPPED;
260
+ switch (state)
261
+ {
262
+ case AL_PLAYING: return SoundPlayer::PLAYING;
263
+ case AL_PAUSED: return SoundPlayer::PAUSED;
264
+ case AL_STOPPED: return SoundPlayer::STOPPED;
265
+ default: return SoundPlayer::STATE_UNKNOWN;
266
+ }
283
267
  }
284
268
 
285
269
  void set_gain (float gain)
@@ -433,7 +417,7 @@ namespace Beeps
433
417
  return;
434
418
 
435
419
  source.queue(buffer);
436
- if (source.is_stopped()) source.play();
420
+ if (source.state() == STOPPED) source.play();
437
421
  }
438
422
  }
439
423
 
@@ -476,10 +460,10 @@ namespace Beeps
476
460
  {
477
461
  auto it = std::remove_if(
478
462
  global::players.begin(), global::players.end(),
479
- [](auto& player) {return !player || player.is_stopped();});
480
-
481
- for (auto jt = it; jt != global::players.end(); ++jt)
482
- jt->self->clear();
463
+ [](auto& player)
464
+ {
465
+ return !player || player.state() == SoundPlayer::STOPPED;
466
+ });
483
467
 
484
468
  global::players.erase(it, global::players.end());
485
469
  }
@@ -488,7 +472,6 @@ namespace Beeps
488
472
  get_next_player ()
489
473
  {
490
474
  SoundPlayer player = create_player();
491
-
492
475
  if (player)
493
476
  LOG("new player");
494
477
 
@@ -496,7 +479,7 @@ namespace Beeps
496
479
  {
497
480
  for (auto& p : global::players)
498
481
  {
499
- if (p && p.is_stopped())
482
+ if (p && p.state() == SoundPlayer::STOPPED)
500
483
  {
501
484
  player = reuse_player(&p);
502
485
  LOG("reuse stopped player");
@@ -578,24 +561,13 @@ namespace Beeps
578
561
  self->source.stop();
579
562
  }
580
563
 
581
- bool
582
- SoundPlayer::is_playing () const
583
- {
584
- return
585
- self->source.is_playing() ||
586
- (self->is_streaming() && self->source.is_stopped());
587
- }
588
-
589
- bool
590
- SoundPlayer::is_paused () const
591
- {
592
- return self->source.is_paused();
593
- }
594
-
595
- bool
596
- SoundPlayer::is_stopped () const
564
+ SoundPlayer::State
565
+ SoundPlayer::state () const
597
566
  {
598
- return self->source.is_stopped() && !self->is_streaming();
567
+ State s = self->source.state();
568
+ if (s == STOPPED && self->is_streaming())
569
+ return PLAYING;
570
+ return s;
599
571
  }
600
572
 
601
573
  void
@@ -833,7 +805,7 @@ namespace Beeps
833
805
  #if 0
834
806
  std::string ox = "";
835
807
  for (auto& player : global::players)
836
- ox += player.is_playing() ? 'o' : 'x';
808
+ ox += player.state() == SoundPlayer::PLAYING ? 'o' : 'x';
837
809
  LOG("%d players. (%s)", global::players.size(), ox.c_str());
838
810
  #endif
839
811
 
@@ -31,26 +31,26 @@ class TestSoundPlayer < Test::Unit::TestCase
31
31
 
32
32
  def test_pause()
33
33
  p = sound.play
34
- assert_equal [true, false, false], [p.playing?, p.paused?, p.stopped?]
34
+ assert_equal :playing, p.state
35
35
  p.pause
36
- assert_equal [false, true, false], [p.playing?, p.paused?, p.stopped?]
36
+ assert_equal :paused, p.state
37
37
 
38
38
  p = stream_sound.play
39
- assert_equal [true, false, false], [p.playing?, p.paused?, p.stopped?]
39
+ assert_equal :playing, p.state
40
40
  p.pause
41
- assert_equal [false, true, false], [p.playing?, p.paused?, p.stopped?]
41
+ assert_equal :paused, p.state
42
42
  end
43
43
 
44
44
  def test_stop()
45
45
  p = sound.play
46
- assert_equal [true, false, false], [p.playing?, p.paused?, p.stopped?]
46
+ assert_equal :playing, p.state
47
47
  p.stop
48
- assert_equal [false, false, true], [p.playing?, p.paused?, p.stopped?]
48
+ assert_equal :stopped, p.state
49
49
 
50
50
  p = stream_sound.play
51
- assert_equal [true, false, false], [p.playing?, p.paused?, p.stopped?]
51
+ assert_equal :playing, p.state
52
52
  p.stop
53
- assert_equal [false, false, true], [p.playing?, p.paused?, p.stopped?]
53
+ assert_equal :stopped, p.state
54
54
  end
55
55
 
56
56
  def test_play_end_then_stop()
@@ -58,42 +58,68 @@ class TestSoundPlayer < Test::Unit::TestCase
58
58
  sec = s.seconds
59
59
 
60
60
  p = s.play
61
- assert_equal [true, false, false], [p.playing?, p.paused?, p.stopped?]
61
+ assert_equal :playing, p.state
62
62
  sleep sec * 2
63
- assert_equal [false, false, true], [p.playing?, p.paused?, p.stopped?]
63
+ assert_equal :stopped, p.state
64
64
 
65
65
  s = stream_sound
66
66
  p = s.play
67
- assert_equal [true, false, false], [p.playing?, p.paused?, p.stopped?]
67
+ assert_equal :playing, p.state
68
68
  sleep sec * 2
69
- assert_equal [false, false, true], [p.playing?, p.paused?, p.stopped?]
69
+ assert_equal :stopped, p.state
70
70
  end
71
71
 
72
72
  def test_play_after_pause()
73
73
  p = sound.play
74
74
  p.pause
75
- assert_equal [false, true, false], [p.playing?, p.paused?, p.stopped?]
75
+ assert_equal :paused, p.state
76
76
  p.play
77
- assert_equal [true, false, false], [p.playing?, p.paused?, p.stopped?]
77
+ assert_equal :playing, p.state
78
78
 
79
79
  p = stream_sound.play
80
80
  p.pause
81
- assert_equal [false, true, false], [p.playing?, p.paused?, p.stopped?]
81
+ assert_equal :paused, p.state
82
82
  p.play
83
- assert_equal [true, false, false], [p.playing?, p.paused?, p.stopped?]
83
+ assert_equal :playing, p.state
84
84
  end
85
85
 
86
86
  def test_stop_after_pause()
87
87
  p = sound.play
88
88
  p.pause
89
+ assert_equal :paused, p.state
90
+ p.stop
91
+ assert_equal :stopped, p.state
92
+
93
+ p = stream_sound.play
94
+ p.pause
95
+ assert_equal :paused, p.state
96
+ p.stop
97
+ assert_equal :stopped, p.state
98
+ end
99
+
100
+ def test_state()
101
+ p = sound.play
102
+ assert_equal :playing, p.state
103
+ assert_equal [true, false, false], [p.playing?, p.paused?, p.stopped?]
104
+
105
+ p.pause
106
+ assert_equal :paused, p.state
89
107
  assert_equal [false, true, false], [p.playing?, p.paused?, p.stopped?]
108
+
90
109
  p.stop
110
+ assert_equal :stopped, p.state
91
111
  assert_equal [false, false, true], [p.playing?, p.paused?, p.stopped?]
92
112
 
93
113
  p = stream_sound.play
114
+ assert_equal :playing, p.state
115
+ assert_equal [true, false, false], [p.playing?, p.paused?, p.stopped?]
116
+
94
117
  p.pause
118
+ assert_equal :paused, p.state
95
119
  assert_equal [false, true, false], [p.playing?, p.paused?, p.stopped?]
120
+
96
121
  p.stop
122
+ assert_equal :stopped, p.state
97
123
  assert_equal [false, false, true], [p.playing?, p.paused?, p.stopped?]
98
124
  end
99
125
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beeps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.40
4
+ version: 0.1.41
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-11 00:00:00.000000000 Z
11
+ date: 2023-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xot