Exemplo n.º 1
0
void CPSong::make_instruments_from_samples() {
	
	for (int i=0;i<MAX_SAMPLES;i++) {
		
		CPInstrument *ins=get_instrument( i );
		
		if (!ins)
			continue;
		
		ins->reset();
		
		CPSample *s=get_sample( i );
		
		if (!s)
			continue;
		
		ins->set_name( s->get_name() );
		
		if (s->get_sample_data().is_null())
			continue;
		
		
		
		
		for(int j=0;j<CPNote::NOTES;j++) 
			ins->set_sample_number( j, i );
		
		
		
	}
}
Exemplo n.º 2
0
static char *get_unique_parameter_name(MskContainer *parent)
{
    MskInstrument *instrument = get_instrument(parent);
    char *unique_name;
    GList *item;
    int i;

    for ( i = 1; ; i++ )
    {
        unique_name = g_strdup_printf("parameter #%d", i);

        /* Check if it exists already. */
        for ( item = instrument->parameter_list; item; item = item->next )
        {
            MskModule *mod = item->data;
            const char *name;

            name = msk_module_get_property_buffer(mod, "name");
            if ( !strcmp(name, unique_name) )
                break;
        }

        if ( !item )
            return unique_name;

        /* If one already exists, try again. */
        g_free(unique_name);
    }
}
Exemplo n.º 3
0
void CPSong::make_instrument_from_sample(int p_sample) {
	
	if (!has_instruments())
		return;
	CP_ERR_COND(!get_sample( p_sample ));
	
	for (int i=0;i<MAX_INSTRUMENTS;i++) {
		
		
		CPInstrument *ins=get_instrument(i);
		
		bool empty_slot=true;
		for (int n=0;n<CPNote::NOTES;n++) {
			
			if (ins->get_sample_number(n)<MAX_SAMPLES) {
				
				empty_slot=false;
				break;
			}
		}
		
		if (!empty_slot)
			continue;
		
		for (int n=0;n<CPNote::NOTES;n++) {
			
			ins->set_sample_number(n,p_sample);
			ins->set_note_number(n,n);
		}
		
		ins->set_name( get_sample( p_sample )->get_name() );
		break;
	}
	
}
Exemplo n.º 4
0
int CPSong::get_instrument_in_use_count() {

	int instrument_count=0;
	
	for (int i=(CPSong::MAX_INSTRUMENTS-1);i>=0;i--) {

		CPInstrument *ins = get_instrument(i);
		bool in_use=false;
		
		for (int s = 0 ; s < CPNote::NOTES ; s++ ) {
		
			int smp_idx = ins->get_sample_number(s);
			if (smp_idx<0 || smp_idx>=CPSong::MAX_SAMPLES)
				continue;
				
			if (!get_sample(smp_idx)->get_sample_data().is_null()) {
				in_use=true;
				break;
			}
				
		}
		
		if (in_use) {
			instrument_count=i+1;
			break;
		}
	}

	return instrument_count;
}
Exemplo n.º 5
0
static void msk_channelpressure_process(MskModule *self, int start, int frames, void *state)
{
    float * const out = msk_module_get_output_buffer(self, "value");
    MskInstrument *instrument = get_instrument(self->parent);

    *out = (float)instrument->channel_pressure / 127.0;
}
Exemplo n.º 6
0
static void msk_pitchbend_process(MskModule *self, int start, int frames, void *state)
{
    float * const out = msk_module_get_output_buffer(self, "value");
    MskInstrument *instrument = get_instrument(self->parent);

    *out = (float)instrument->pitch_bend / (8192.0 / 2.0);
}
Exemplo n.º 7
0
void CPSong::clear_all_default_vol(){
	
	for (int i=0;i<MAX_SAMPLES;i++)
		get_sample(i)->set_default_volume( 64 ); //die!
	for (int i=0;i<MAX_INSTRUMENTS;i++)
		get_instrument(i)->set_volume_global_amount( CPInstrument::MAX_VOLUME );
	
}
Exemplo n.º 8
0
void CPSong::reset(bool p_clear_patterns,bool p_clear_samples,bool p_clear_instruments,bool p_clear_variables) {
	
	if (p_clear_variables) {
		variables.name[0]=0;
		variables.message[0]=0;
		variables.row_highlight_major=16;
		variables.row_highlight_minor=4;
		variables.mixing_volume=48;
		variables.old_effects=false;
		if (p_clear_instruments) //should not be cleared, if not clearing instruments!!
			variables.use_instruments=false;
		variables.stereo_separation=128;
		variables.use_linear_slides=true;
		variables.use_stereo=true;
		
		initial_variables.global_volume=128;
		initial_variables.speed=6;
		initial_variables.tempo=125;
		
		for (int i=0;i<CPPattern::WIDTH;i++) {
			
			initial_variables.channel[i].pan=32;
			initial_variables.channel[i].volume=CHANNEL_MAX_VOLUME;
			initial_variables.channel[i].mute=false;
			initial_variables.channel[i].surround=false;
			initial_variables.channel[i].chorus=0;
			initial_variables.channel[i].reverb=0;
			
		}
		
		effects.chorus.delay_ms=6;
		effects.chorus.separation_ms=3;
		effects.chorus.depth_ms10=6,
		effects.chorus.speed_hz10=5;
		effects.reverb_mode=REVERB_MODE_ROOM;
	}
	
	if (p_clear_samples) {
		for (int i=0;i<MAX_SAMPLES;i++)
			get_sample(i)->reset();
	}
		
	if (p_clear_instruments) {
		for (int i=0;i<MAX_INSTRUMENTS;i++)
			get_instrument(i)->reset();
	}
	
	if (p_clear_patterns) {
		for (int i=0;i<MAX_PATTERNS;i++)
			get_pattern(i)->clear();
	
		for (int i=0;i<MAX_ORDERS;i++)
			set_order( i, CP_ORDER_NONE );
	}
	
			
}
Exemplo n.º 9
0
void CPSong::clear_all_default_pan() {
	
	for (int i=0;i<MAX_INSTRUMENTS;i++)
		get_instrument(i)->set_pan_default_enabled( false ); //die!
	
	for (int i=0;i<MAX_SAMPLES;i++)
		get_sample(i)->set_pan_enabled( false ); //die!
	
}
void ext_model::activate()
{
    if (!get_instrument() && !was_activated_)
    {
        ani::navigation_ptr navi = ani_ ? ani_->navigation_info() : ani::navigation_ptr();
        fms::plan_t plan =  fms::create_instruments_plan(get_state(), get_instruments_env()) ;

        set_plan(plan);
        was_activated_ = true;
    }
}
Exemplo n.º 11
0
void msk_voicepitch_process(MskModule *self, int start, int frames, void *state)
{
    float * const out = msk_module_get_output_buffer(self, "pitch");
    MskInstrument *instrument = get_instrument(self->parent);
    int voice, value;

    voice = instrument->container->current_voice;
    value = instrument->voice_note[voice];

    *out = value;
}
Exemplo n.º 12
0
void msk_voicevelocity_process(MskModule *self, int start, int frames, void *state)
{
    float * const out = msk_module_get_output_buffer(self, "velocity");
    MskInstrument *instrument = get_instrument(self->parent);
    int voice;
    float value;

    voice = instrument->container->current_voice;
    value = (float)instrument->voice_velocity[voice] / 127;

    *out = value;
}
Exemplo n.º 13
0
void Note::save_to( XMLNode* node )
{
	node->write_int( "position", __position );
	node->write_float( "leadlag", __lead_lag );
	node->write_float( "velocity", __velocity );
	node->write_float( "pan_L", __pan_l );
	node->write_float( "pan_R", __pan_r );
	node->write_float( "pitch", __pitch );
	node->write_string( "key", key_to_string() );
	node->write_int( "length", __length );
	node->write_int( "instrument", get_instrument()->get_id() );
	node->write_bool( "note_off", __note_off );
}
Exemplo n.º 14
0
void CPSong::cleanup_unused_samples(){
	
	if (!has_instruments())
		return;
	
	bool sample_found[MAX_SAMPLES];
	for (int i=0;i<MAX_INSTRUMENTS;i++)
		sample_found[i]=false;
	
	for (int i=0;i<MAX_PATTERNS;i++) {
		
		if (get_pattern(i)->is_empty())
			continue;
		
		
		for (int row=0;row<get_pattern(i)->get_length();row++) {
			
			
			for (int col=0;col<CPPattern::WIDTH;col++) {
			
				CPNote n;
				n=get_pattern(i)->get_note( col,row );
				
				if (n.instrument>=MAX_SAMPLES)
					continue;
				
				if (has_instruments()) {
							
					for (int nt=0;nt<CPNote::NOTES;nt++) {
						
						int smp=get_instrument(n.instrument)->get_sample_number(nt);
						if (smp<MAX_SAMPLES)
							sample_found[smp]=true;
					}
					
				} else {
					if (n.instrument<MAX_SAMPLES)
						sample_found[n.instrument]=true;
				}
			
			}
			
		}
		
	}
	
	for (int i=0;i<MAX_SAMPLES;i++)
		if (!sample_found[i])
			get_sample(i)->reset();
	
}
Exemplo n.º 15
0
static void reset_envelopes(struct context_data *ctx, struct channel_data *xc)
{
	struct xmp_instrument *xxi;

	xxi = get_instrument(ctx, xc->ins);

	/* Reset envelope positions */
	if (~xxi->aei.flg & XMP_ENVELOPE_CARRY) {
		xc->v_idx = 0;
	}
	if (~xxi->pei.flg & XMP_ENVELOPE_CARRY) {
		xc->p_idx = 0;
	}
	if (~xxi->fei.flg & XMP_ENVELOPE_CARRY) {
		xc->f_idx = 0;
	}
}
Exemplo n.º 16
0
void CPSong::clear_instrument_with_samples(int p_instrument) {
	
	CPInstrument *ins = get_instrument( p_instrument );
	if (!ins)
		return;
	
	for (int i=0;i<CPNote::NOTES;i++) {
		
		CPSample *s=get_sample( ins->get_sample_number( i ) );
		
		if (!s)
			continue;
		
		if (s->get_sample_data().is_null())
			continue;
		
		s->reset();
	}
	ins->reset();
}
Exemplo n.º 17
0
void CPSong::cleanup_unused_instruments(){
	
	if (!has_instruments())
		return;
	
	bool instr_found[MAX_INSTRUMENTS];
	for (int i=0;i<MAX_INSTRUMENTS;i++)
		instr_found[i]=false;
	
	for (int i=0;i<MAX_PATTERNS;i++) {
		
		if (get_pattern(i)->is_empty())
			continue;
		
		for (int row=0;row<get_pattern(i)->get_length();row++) {
			
			
			for (int col=0;col<CPPattern::WIDTH;col++) {
			
				CPNote n;
				n=get_pattern(i)->get_note( col,row );
				
				if (n.instrument<MAX_INSTRUMENTS)
					instr_found[n.instrument]=true;
			
			}
			
		}
		
	}
	
	for (int i=0;i<MAX_INSTRUMENTS;i++)
		if (!instr_found[i])
			get_instrument(i)->reset();
	
	
}
Exemplo n.º 18
0
void CPSong::separate_in_one_sample_instruments(int p_instrument) {

	CP_ERR_COND( !variables.use_instruments );
	CP_FAIL_INDEX( p_instrument, MAX_INSTRUMENTS );

	int remapped_count=0;
	
	signed char remap[MAX_SAMPLES];
	
	for (int i=0;i<MAX_SAMPLES;i++) {
	
		remap[i]=-1;
	}
	
	/* Find remaps */
	CPInstrument *ins=get_instrument(p_instrument);
	for (int i=0;i<CPNote::NOTES;i++) {
	
		int sn = ins->get_sample_number(i);
		
		// check for unusable sample
		if (sn<0 || sn>=MAX_SAMPLES || get_sample(sn)->get_sample_data().is_null())
			continue;
		printf("sample %i\n",sn);	
		if ( remap[sn] !=-1 ) {
			printf("already mapped to %i\n",remap[sn]);	
			continue;
		}
			
		printf("isn't remapped\n");	
			
		// find remap
		
		for (int j=0;j<MAX_INSTRUMENTS;j++) {
	
			if (!get_instrument(j)->is_empty()) 
				continue;
			
			printf("map to %i\n",j);	
			
			//copy
			*get_instrument(j)=*ins;
			
			// assign samples
			for (int k=0;k<CPNote::NOTES;k++) {
			
				get_instrument(j)->set_note_number(k,k);
				get_instrument(j)->set_sample_number(k,sn);
			}					
			remap[sn]=j;
			remapped_count++;
			break;
		}
		
		CP_ERR_COND(remap[sn]==-1); // no more free instruments
	}
	
	printf("remapped %i\n",remapped_count);	
	
	if (remapped_count<2) {
		//undo if only one is remapped
		for (int i=0;i<MAX_SAMPLES;i++) {
		
			if (remap[i]!=-1) {
			
				get_instrument(remap[i])->reset();
			}
		}
		return;
	}
	
	/* remap all song */
	
	for (int p=0;p<CPSong::MAX_PATTERNS;p++) {
	
		CPPattern *pat = get_pattern(p);
		if (pat->is_empty())
			continue;
		
		
		for (int c=0;c<CPPattern::WIDTH;c++) {
		
			for (int r=0;r<pat->get_length();r++) {
			
				CPNote n = pat->get_note(c,r);
				if (n.note<CPNote::NOTES && n.instrument==p_instrument) {
				
					int sn = ins->get_sample_number(n.note);
					if (remap[sn]==-1)
						pat->set_note(c,r,CPNote());
					else {
					
						n.instrument=remap[sn];
						pat->set_note(c,r,n);
					}
				}
			}
		}
	}
	
	ins->reset();
	
}
Exemplo n.º 19
0
static void add_parameter_to_instrument(MskModule *module)
{
    MskInstrument *instrument = get_instrument(module->parent);

    instrument->parameter_list = g_list_append(instrument->parameter_list, module);
}