    001
    002    package ibxm;
    003
    004    public class Instrument {
    005        public String name;
    006        public int vibrato_type, vibrato_sweep;
    007        public int vibrato_depth, vibrato_rate;
    008        public boolean volume_envelope_active, panning_envelope_active;
    009        public int volume_fade_out;
    010
    011        private Envelope volume_envelope, panning_envelope;
    012        private int[] key_to_sample;
    013        private Sample[] samples;
    014
    015        public Instrument() {
    016            name = "";
    017            set_volume_envelope( new Envelope() );
    018            set_panning_envelope( new Envelope() );
    019            key_to_sample = new int[ 96 ];
    020            set_num_samples( 1 );
    021        }
    022
    023        public Envelope get_volume_envelope() {
    024            return volume_envelope;
    025        }
    026
    027        public void set_volume_envelope( Envelope envelope ) {
    028            if( envelope != null ) {
    029                volume_envelope = envelope;
    030            }
    031        }
    032
    033        public Envelope get_panning_envelope() {
    034            return panning_envelope;
    035        }
    036
    037        public void set_panning_envelope( Envelope envelope ) {
    038            if( envelope != null ) {
    039                panning_envelope = envelope;
    040            }
    041        }
    042
    043        public Sample get_sample_from_key( int key ) {
    044            int sample_idx;
    045            sample_idx = 0;
    046            if( key > 0 && key <= key_to_sample.length ) {
    047                sample_idx = key_to_sample[ key - 1 ];
    048            }
    049            return get_sample( sample_idx );
    050        }
    051
    052        public void set_key_to_sample( int key, int sample ) {
    053            if( key > 0 && key <= key_to_sample.length ) {
    054                key_to_sample[ key - 1 ] = sample;
    055            }
    056        }
    057
    058        public int get_num_samples() {
    059            return samples.length;
    060        }
    061
    062        public void set_num_samples( int num_samples ) {
    063            if( num_samples < 1 ) {
    064                num_samples = 1;
    065            }
    066            samples = new Sample[ num_samples ];
    067            set_sample( 0, null );
    068        }
    069
    070        public Sample get_sample( int sample_index ) {
    071            Sample sample;
    072            sample = null;
    073            if( sample_index >= 0 && sample_index < samples.length ) {
    074                sample = samples[ sample_index ];
    075            }
    076            if( sample == null ) {
    077                sample = samples[ 0 ];
    078            }
    079            return sample;
    080        }
    081
    082        public void set_sample( int sample_index, Sample sample ) {
    083            if( sample_index >= 0 && sample_index < samples.length ) {
    084                samples[ sample_index ] = sample;
    085            }
    086            if( samples[ 0 ] == null ) {
    087                samples[ 0 ] = new Sample();
    088            }
    089        }
    090    }