Class: AudioToolbox::MusicPlayer

Inherits:
Object
  • Object
show all
Defined in:
ext/music_player/music_player.c

Instance Method Summary collapse

Constructor Details

#initializeObject



117
118
119
120
121
122
123
124
125
126
127
128
# File 'ext/music_player/music_player.c', line 117

static VALUE
player_init (VALUE self)
{
    MusicPlayer *player;
    OSStatus err;
    Data_Get_Struct(self, MusicPlayer, player);
    require_noerr( err = NewMusicPlayer(player), fail );
    return self;
    
    fail:
    RAISE_OSSTATUS(err, "NewMusicPlayer()");
}

Instance Method Details

#host_time_for_beatsObject



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'ext/music_player/music_player.c', line 265

static VALUE
player_host_time_for_beats (VALUE self, VALUE rb_beats)
{
  MusicTimeStamp beats = NUM2ULONG(rb_beats);
  
  MusicPlayer *player;
  Data_Get_Struct(self, MusicPlayer, player);

  UInt64 host_time = 0;
  OSStatus err;
  
  require_noerr( err = MusicPlayerGetHostTimeForBeats(*player, beats, &host_time), fail );
  return rb_float_new(host_time);
  
 fail:
  RAISE_OSSTATUS(err, "MusicPlayerGetHostTimeForBeats()");
}

#play_rate_scalarObject



231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'ext/music_player/music_player.c', line 231

static VALUE
player_get_play_rate_scalar (VALUE self)
{
    MusicPlayer *player;
    Float64 scalar;
    OSStatus err;
    
    Data_Get_Struct(self, MusicPlayer, player);
    require_noerr( err = MusicPlayerGetPlayRateScalar(*player, &scalar), fail );
    return rb_float_new(scalar);

    fail:
    RAISE_OSSTATUS(err, "MusicPlayerGetPlayRateScalar()");
}

#play_rate_scalar=Object



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'ext/music_player/music_player.c', line 246

static VALUE
player_set_play_rate_scalar (VALUE self, VALUE rb_scalar)
{
    if (!PRIM_NUM_P(rb_scalar))
        rb_raise(rb_eArgError, "Expected scalar to be a number.");
    
    MusicPlayer *player;
    Float64 scalar;
    OSStatus err;

    scalar = NUM2DBL(rb_scalar);
    Data_Get_Struct(self, MusicPlayer, player);
    require_noerr( err = MusicPlayerSetPlayRateScalar(*player, scalar), fail );
    return Qnil;
    
    fail:
    RAISE_OSSTATUS(err, "MusicPlayerSetPlayRateScalar()");
}

#playing?Boolean

Returns:

  • (Boolean)


130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'ext/music_player/music_player.c', line 130

static VALUE
player_is_playing (VALUE self)
{
    MusicPlayer *player;
    Boolean playing;
    OSStatus err;
    
    Data_Get_Struct(self, MusicPlayer, player);
    require_noerr( err = MusicPlayerIsPlaying(*player, &playing), fail );
    return playing ? Qtrue : Qfalse;
    
    fail:
    RAISE_OSSTATUS(err, "MusicPlayerIsPlaying()");
}

#sequenceObject



145
146
147
148
149
# File 'ext/music_player/music_player.c', line 145

static VALUE
player_get_sequence (VALUE self)
{
    return rb_iv_get(self, "@sequence");
}

#sequence=Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'ext/music_player/music_player.c', line 151

static VALUE
player_set_sequence (VALUE self, VALUE rb_seq)
{
    MusicPlayer *player;
    MusicSequence *seq;
    OSStatus err;
    
    Data_Get_Struct(self, MusicPlayer, player);
    Data_Get_Struct(rb_seq, MusicSequence, seq);
    rb_iv_set(self, "@sequence", rb_seq);
    
    require_noerr( err = MusicPlayerSetSequence(*player, *seq), fail );
    return rb_seq;
    
    fail:
    RAISE_OSSTATUS(err, "MusicPlayerSetSequence()");
}

#startObject



169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'ext/music_player/music_player.c', line 169

static VALUE
player_start (VALUE self)
{
    MusicPlayer *player;
    OSStatus err;
    
    Data_Get_Struct(self, MusicPlayer, player);
    require_noerr( err = MusicPlayerStart(*player), fail );
    return Qnil;
    
    fail:
    RAISE_OSSTATUS(err, "MusicPlayerStart()");
}

#stopObject



183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'ext/music_player/music_player.c', line 183

static VALUE
player_stop (VALUE self)
{
    MusicPlayer *player;
    OSStatus err;
    
    Data_Get_Struct(self, MusicPlayer, player);
    require_noerr( err = MusicPlayerStop(*player), fail );
    return Qnil;
    
    fail:
    RAISE_OSSTATUS(err, "MusicPlayerStop()");
}

#timeObject



197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'ext/music_player/music_player.c', line 197

static VALUE
player_get_time (VALUE self)
{
    MusicPlayer *player;
    MusicTimeStamp ts;
    OSStatus err;
    
    Data_Get_Struct(self, MusicPlayer, player);
    require_noerr( err = MusicPlayerGetTime(*player, &ts), fail );
    return rb_float_new((Float64) ts);
    
    fail:
    RAISE_OSSTATUS(err, "MusicPlayerGetTime()");
}

#time=Object



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'ext/music_player/music_player.c', line 212

static VALUE
player_set_time (VALUE self, VALUE rb_ts)
{
    if (!PRIM_NUM_P(rb_ts))
        rb_raise(rb_eArgError, "Expected argument to be a number.");
    
    MusicPlayer *player;
    MusicTimeStamp ts;
    OSStatus err;
    
    ts = rb_num2dbl(rb_ts);
    Data_Get_Struct(self, MusicPlayer, player);
    require_noerr( err = MusicPlayerSetTime(*player, ts), fail );
    return Qnil;
    
    fail:
    RAISE_OSSTATUS(err, "MusicPlayerSetTime()");
}