Class: AudioToolbox::MusicTrackCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/music_player.rb,
ext/music_player/music_player.c

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sequence) ⇒ MusicTrackCollection

Returns a new instance of MusicTrackCollection.



21
22
23
24
25
# File 'lib/music_player.rb', line 21

def initialize(sequence)
  @sequence = sequence
  @tracks   = []
  @lock     = Mutex.new
end

Instance Attribute Details

#lockObject (readonly)

:nodoc:



19
20
21
# File 'lib/music_player.rb', line 19

def lock
  @lock
end

Instance Method Details

#[](index) ⇒ Object



39
40
41
42
43
# File 'lib/music_player.rb', line 39

def [](index)
  @lock.synchronize do
    @tracks[index] ||= ind_internal(index)
  end
end

#delete(track) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/music_player.rb', line 45

def delete(track)
  @lock.synchronize do
    delete_internal(track)
    @tracks.delete(track)
    track.freeze
  end
  nil
end

#eachObject



27
28
29
# File 'lib/music_player.rb', line 27

def each
  0.upto(size-1) { |i| yield self[i] }
end

#indexObject



827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
# File 'ext/music_player/music_player.c', line 827

static VALUE
tracks_index (VALUE self, VALUE rb_track)
{
    if (rb_cMusicTrack != rb_class_of(rb_track))
        rb_raise(rb_eArgError, "Expected arg to be a MusicTrack.");
    
    MusicSequence *seq = tracks_get_seq(self);
    MusicTrack *track;
    UInt32 i;
    OSStatus err;
    
    Data_Get_Struct(rb_track, MusicTrack, track);
    require_noerr( err = MusicSequenceGetTrackIndex(*seq, *track, &i), fail );
    return UINT2NUM(i);
    
    fail:
    RAISE_OSSTATUS(err, "MusicSequenceGetTrackIndex()");
}

#new(options = nil) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/music_player.rb', line 31

def new(options=nil)
  @lock.synchronize do
    track = MusicTrack.send(:new, @sequence, options)
    @tracks << track
    track
  end
end

#sizeObject



793
794
795
796
797
798
799
800
801
802
803
804
805
# File 'ext/music_player/music_player.c', line 793

static VALUE
tracks_size (VALUE self)
{
    MusicSequence *seq = tracks_get_seq(self);
    UInt32 track_count;
    OSStatus err;
    
    require_noerr( err = MusicSequenceGetTrackCount(*seq, &track_count), fail );
    return UINT2NUM(track_count);
    
    fail:
    RAISE_OSSTATUS(err, "MusicSequenceGetTrackCount()");
}

#tempoObject



54
55
56
# File 'lib/music_player.rb', line 54

def tempo
  @tempo ||= tempo_internal
end