Class: AudioToolbox::MIDINoteMessage

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

Direct Known Subclasses

MIDINoteOffMessage, MIDINoteOnMessage

Instance Method Summary collapse

Constructor Details

#initializeObject



990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
# File 'ext/music_player/midiosx.c', line 990

static VALUE
midi_note_message_init (VALUE self, VALUE rb_opts)
{
    Check_Type(rb_opts, T_HASH);
    MIDINoteMessage *msg;
    VALUE rb_chn, rb_note, rb_vel, rb_rel_vel, rb_dur;

    Data_Get_Struct(self, MIDINoteMessage, msg);

    rb_chn = rb_hash_aref(rb_opts, rb_sChannel);
    msg->channel = FIXNUM_P(rb_chn) ? FIX2UINT(rb_chn) : 1;
    
    rb_note = rb_hash_aref(rb_opts, rb_sNote);
    if (FIXNUM_P(rb_note))
        msg->note = FIX2UINT(rb_note);
    else
        rb_raise(rb_eArgError, ":note is required.");
    
    rb_vel = rb_hash_aref(rb_opts, rb_sVelocity);
    msg->velocity = FIXNUM_P(rb_vel) ? FIX2UINT(rb_vel) : 64;
    
    rb_rel_vel = rb_hash_aref(rb_opts, rb_sReleaseVelocity);
    msg->releaseVelocity = FIXNUM_P(rb_rel_vel) ? FIX2UINT(rb_rel_vel) : 0;
    
    rb_dur = rb_hash_aref(rb_opts, rb_sDuration);
    msg->duration = (MusicTimeStamp) (PRIM_NUM_P(rb_dur)) ? NUM2DBL(rb_dur) : 1.0;
    
    return self;
}

Instance Method Details

#==(msg) ⇒ Object



106
107
108
109
110
111
112
113
# File 'lib/midiosx.rb', line 106

def ==(msg)
  self.class       == msg.class &&
  channel          == msg.channel &&
  note             == msg.note &&
  velocity         == msg.velocity &&
  release_velocity == msg.release_velocity &&
  duration         == msg.duration
end

#add(time, track) ⇒ Object



115
116
117
# File 'lib/midiosx.rb', line 115

def add(time, track)
  track.add_midi_note_message(time, self)
end

#channelObject



1020
1021
1022
1023
1024
1025
1026
# File 'ext/music_player/midiosx.c', line 1020

static VALUE
midi_note_message_channel (VALUE self)
{
    MIDINoteMessage *msg;
    Data_Get_Struct(self, MIDINoteMessage, msg);
    return UINT2NUM(msg->channel);
}

#data1Object



1080
1081
1082
1083
1084
# File 'ext/music_player/midiosx.c', line 1080

static VALUE
midi_note_message_data1(VALUE self)
{
    return midi_note_message_note(self);
}

#data2Object



1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
# File 'ext/music_player/midiosx.c', line 1086

static VALUE
midi_note_message_data2(VALUE self)
{
    VALUE vel;
    
    if ( rb_obj_is_instance_of(self, rb_cMIDINoteOnMessage) == Qtrue ) {
        vel = midi_note_message_velocity(self);
    }
    else {
        vel = midi_note_message_release_velocity(self);
    }
    return vel;
}

#durationObject



1052
1053
1054
1055
1056
1057
1058
# File 'ext/music_player/midiosx.c', line 1052

static VALUE
midi_note_message_duration (VALUE self)
{
    MIDINoteMessage *msg;
    Data_Get_Struct(self, MIDINoteMessage, msg);
    return UINT2NUM(msg->duration);
}

#noteObject



1028
1029
1030
1031
1032
1033
1034
# File 'ext/music_player/midiosx.c', line 1028

static VALUE
midi_note_message_note (VALUE self)
{
    MIDINoteMessage *msg;
    Data_Get_Struct(self, MIDINoteMessage, msg);
    return UINT2NUM(msg->note);
}

#release_velocityObject



1044
1045
1046
1047
1048
1049
1050
# File 'ext/music_player/midiosx.c', line 1044

static VALUE
midi_note_message_release_velocity (VALUE self)
{
    MIDINoteMessage *msg;
    Data_Get_Struct(self, MIDINoteMessage, msg);
    return UINT2NUM(msg->releaseVelocity);
}

#statusObject



1073
1074
1075
1076
1077
1078
# File 'ext/music_player/midiosx.c', line 1073

static VALUE
midi_note_message_status(VALUE self)
{
    VALUE cmd = ( rb_obj_is_instance_of(self, rb_cMIDINoteOnMessage) == Qtrue ) ? 0x90: 0x80;
    return (UINT2NUM(cmd) | midi_note_message_channel(self));
}

#velocityObject



1036
1037
1038
1039
1040
1041
1042
# File 'ext/music_player/midiosx.c', line 1036

static VALUE
midi_note_message_velocity (VALUE self)
{
    MIDINoteMessage *msg;
    Data_Get_Struct(self, MIDINoteMessage, msg);
    return UINT2NUM(msg->velocity);
}