Class: AudioToolbox::MusicEventIterator

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

Instance Method Summary collapse

Constructor Details

#initializeObject



1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
# File 'ext/music_player/music_player.c', line 1097

static VALUE
iter_init (VALUE self, VALUE rb_track)
{
    MusicTrack *track;
    MusicEventIterator *iter;
    OSStatus err;
    Data_Get_Struct(rb_track, MusicTrack, track);
    Data_Get_Struct(self, MusicEventIterator, iter);
    require_noerr( err = NewMusicEventIterator(*track, iter), fail );
    return self;
    
    fail:
    RAISE_OSSTATUS(err, "NewMusicEventIterator()");
}

Instance Method Details

#current?Boolean

Returns:

  • (Boolean)


1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
# File 'ext/music_player/music_player.c', line 1156

static VALUE
iter_has_current (VALUE self)
{
    MusicEventIterator *iter;
    Boolean has_cur;
    OSStatus err;
    Data_Get_Struct(self, MusicEventIterator, iter);
    require_noerr( err = MusicEventIteratorHasCurrentEvent(*iter, &has_cur), fail );
    return has_cur ? Qtrue : Qfalse;
    
    fail:
    RAISE_OSSTATUS(err, "MusicEventIteratorHasCurrentEvent()");
}

#deleteObject



1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
# File 'ext/music_player/music_player.c', line 1286

static VALUE
iter_delete_event (VALUE self)
{
    MusicEventIterator *iter;
    OSStatus err;
    Data_Get_Struct(self, MusicEventIterator, iter);
    require_noerr( err = MusicEventIteratorDeleteEvent(*iter), fail );
    return Qnil;
    
    fail:
    RAISE_OSSTATUS(err, "MusicEventIteratorDeleteEvent()");
}

#eventObject



1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
# File 'ext/music_player/music_player.c', line 1226

static VALUE
iter_get_event (VALUE self)
{
    MusicEventIterator *iter;
    MusicEventType type;
    const void *data;
    OSStatus err;
    Data_Get_Struct(self, MusicEventIterator, iter);
    require_noerr( err = MusicEventIteratorGetEventInfo(*iter, NULL, &type, &data, NULL), fail );
    
    switch(type) {
    case kMusicEventType_NULL:
        return Qnil;
    case kMusicEventType_MIDINoteMessage:
        return midi_note_message_from_const((MIDINoteMessage*) data);
    case kMusicEventType_MIDIChannelMessage:
        return midi_channel_message_from_const((MIDIChannelMessage*) data);
    case kMusicEventType_ExtendedTempo:
        return tempo_from_const((ExtendedTempoEvent*) data);
    default:
        rb_raise(rb_eNotImpError, "Unsupported event type.");
        break;
    }
    
    fail:
    RAISE_OSSTATUS(err, "MusicEventIteratorGetEventInfo()");
}

#event=Object



1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
# File 'ext/music_player/music_player.c', line 1254

static VALUE
iter_set_event (VALUE self, VALUE rb_msg)
{
    MusicEventIterator *iter;
    MusicEventType type;
    const void *data;
    OSStatus err;
    
    Data_Get_Struct(self, MusicEventIterator, iter);
    
    if (THRQL(rb_cMIDINoteMessage, rb_msg)) {
        type = kMusicEventType_MIDINoteMessage;
        Data_Get_Struct(rb_msg, MIDINoteMessage, data);
    } else if (THRQL(rb_cMIDIChannelMessage, rb_msg)) {
        type = kMusicEventType_MIDIChannelMessage;
        Data_Get_Struct(rb_msg, MIDIChannelMessage, data);
    } else if (THRQL(rb_cExtendedTempoEvent, rb_msg)) {
        type = kMusicEventType_ExtendedTempo;
        ExtendedTempoEvent tmp;
        tmp.bpm = NUM2DBL(rb_funcall(rb_msg, rb_intern("bpm"), 0));
        data = &tmp;
    } else {
        rb_raise(rb_eTypeError, "Unrecognized event type");
    }
    
    require_noerr( err = MusicEventIteratorSetEventInfo(*iter, type, data), fail );
    return Qnil;
    
    fail:
    RAISE_OSSTATUS(err, "MusicEventIteratorSetEventInfo()");
}

#nextObject



1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
# File 'ext/music_player/music_player.c', line 1130

static VALUE
iter_next (VALUE self)
{
    MusicEventIterator *iter;
    OSStatus err;
    Data_Get_Struct(self, MusicEventIterator, iter);
    require_noerr( err = MusicEventIteratorNextEvent(*iter), fail );
    return Qnil;
    
    fail:
    RAISE_OSSTATUS(err, "MusicEventIteratorNextEvent()");
}

#next?Boolean

Returns:

  • (Boolean)


1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
# File 'ext/music_player/music_player.c', line 1184

static VALUE
iter_has_next (VALUE self)
{
    MusicEventIterator *iter;
    Boolean has_next;
    OSStatus err;
    Data_Get_Struct(self, MusicEventIterator, iter);
    require_noerr( err = MusicEventIteratorHasNextEvent(*iter, &has_next), fail );
    return has_next ? Qtrue : Qfalse;
    
    fail:
    RAISE_OSSTATUS(err, "MusicEventIteratorHasNextEvent()");
}

#prevObject



1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
# File 'ext/music_player/music_player.c', line 1143

static VALUE
iter_prev (VALUE self)
{
    MusicEventIterator *iter;
    OSStatus err;
    Data_Get_Struct(self, MusicEventIterator, iter);
    require_noerr( err = MusicEventIteratorPreviousEvent(*iter), fail );
    return Qnil;
    
    fail:
    RAISE_OSSTATUS(err, "MusicEventIteratorPreviousEvent()");
}

#prev?Boolean

Returns:

  • (Boolean)


1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
# File 'ext/music_player/music_player.c', line 1170

static VALUE
iter_has_prev (VALUE self)
{
    MusicEventIterator *iter;
    Boolean has_prev;
    OSStatus err;
    Data_Get_Struct(self, MusicEventIterator, iter);
    require_noerr( err = MusicEventIteratorHasPreviousEvent(*iter, &has_prev), fail );
    return has_prev ? Qtrue : Qfalse;
    
    fail:
    RAISE_OSSTATUS(err, "MusicEventIteratorHasPreviousEvent()");
}

#seekObject



1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
# File 'ext/music_player/music_player.c', line 1112

static VALUE
iter_seek (VALUE self, VALUE rb_time)
{
    MusicEventIterator *iter;
    MusicTimeStamp ts;
    OSStatus err;
    Data_Get_Struct(self, MusicEventIterator, iter);
    if (PRIM_NUM_P(rb_time))
        ts = NUM2DBL(rb_time);
    else
        rb_raise(rb_eArgError, "Expected first arg to be a number.");
    require_noerr( err = MusicEventIteratorSeek(*iter, ts), fail );
    return Qnil;

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

#timeObject



1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
# File 'ext/music_player/music_player.c', line 1198

static VALUE
iter_get_time (VALUE self)
{
    MusicEventIterator *iter;
    MusicTimeStamp ts;
    OSStatus err;
    Data_Get_Struct(self, MusicEventIterator, iter);
    require_noerr( err = MusicEventIteratorGetEventInfo(*iter, &ts, NULL, NULL, NULL), fail );
    return rb_float_new(ts);
    
    fail:
    RAISE_OSSTATUS(err, "MusicEventIteratorGetEventInfo()");
}

#time=Object



1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
# File 'ext/music_player/music_player.c', line 1212

static VALUE
iter_set_time (VALUE self, VALUE rb_time)
{
    MusicEventIterator *iter;
    MusicTimeStamp ts = NUM2DBL(rb_time);
    OSStatus err;
    Data_Get_Struct(self, MusicEventIterator, iter);
    require_noerr( err = MusicEventIteratorSetEventTime(*iter, ts), fail );
    return Qnil;
    
    fail:
    RAISE_OSSTATUS(err, "MusicEventIteratorSetEventTime()");
}