Пример #1
0
snd_seq_t *
create_sequencer (const char* client_name, bool isinput)
{
	snd_seq_t * seq;
	int err;
	
	if ((err = snd_seq_open (&seq, "default", SND_SEQ_OPEN_DUPLEX, 0)) != 0) {
		fst_error ("Could not open ALSA sequencer, aborting\n\n%s\n\n"
			   "Make sure you have configure ALSA properly and that\n"
			   "/proc/asound/seq/clients exists and contains relevant\n"
			   "devices (%s).", 
			   snd_strerror (err));
		return NULL;
	}
	
	snd_seq_set_client_name (seq, client_name);
	
	if ((err = snd_seq_create_simple_port (seq, isinput? "Input" : "Output",
					       (isinput? SND_SEQ_PORT_CAP_WRITE: SND_SEQ_PORT_CAP_READ)| SND_SEQ_PORT_CAP_DUPLEX |
					       SND_SEQ_PORT_CAP_SUBS_READ|SND_SEQ_PORT_CAP_SUBS_WRITE,
					       SND_SEQ_PORT_TYPE_APPLICATION|SND_SEQ_PORT_TYPE_SPECIFIC)) != 0) {
		fst_error ("Could not create ALSA port: %s", snd_strerror (err));
		snd_seq_close(seq);
		return NULL;
	}
	
	return seq;
}
Пример #2
0
void stop_midireceiver (JackVST *jvst)
{
	int err; 
	snd_seq_event_t event;
	snd_seq_t *seq2 = create_sequencer ("jfstquit", true);
	
	jvst->midiquit = 1;
	
	snd_seq_connect_to (seq2, 0, snd_seq_client_id (jvst->seq),0);
	snd_seq_ev_clear      (&event);
	snd_seq_ev_set_direct (&event);
	snd_seq_ev_set_subs   (&event);
	snd_seq_ev_set_source (&event, 0);
	snd_seq_ev_set_controller (&event,1,0x80,50);
	
	if ((err = snd_seq_event_output (seq2, &event)) < 0) {
		fst_error ("cannot send stop event to midi thread: %s\n",
			   snd_strerror (err));
	}

	snd_seq_drain_output (seq2);
	snd_seq_close (seq2);
	pthread_join (jvst->midi_thread,NULL);
	snd_seq_close (jvst->seq);
}
IDXTYPE Data_Splitter<INTERVALCONTAINER,IDXTYPE>::get_n(const unsigned int _clsidx) const
{
	assert(_clsidx<csplit.size());
	try {
		return csplit[_clsidx]->n;
	} catch(...) {
		throw fst_error("Data_Splitter::get_n() out-of-index? error.");
	}
}
void Data_Splitter<INTERVALCONTAINER,IDXTYPE>::set_n(const unsigned int _clsidx, const IDXTYPE _n)
{
	assert(_n>0); 
	assert(_clsidx>=0);
	try {	
		while(csplit.size()<=_clsidx) {PClassSplitter pcs(new TClassSplitter); csplit.push_back(pcs);}
		csplit[_clsidx]->n=_n;
	} catch(...) {
		throw fst_error("Data_Splitter::assign() out-of-index? error.");
	}
}
Пример #5
0
static FSTInfo *fst_info_from_plugin( FST *fst ) {
    FSTInfo *info = (FSTInfo *) malloc( sizeof( FSTInfo ) );
    struct AEffect *plugin;
    int i;
    char creator[65];

    if( ! fst ) {
	fst_error( "fst is NULL\n" );
	return NULL;
    }

    if( ! info ) return NULL;
    
    plugin = fst->plugin;
    

    info->name = strdup(fst->handle->name ); 
    plugin->dispatcher (plugin, 47 /* effGetVendorString */, 0, 0, creator, 0);
    if (strlen (creator) == 0) {
      info->creator = strdup ("Unknown");
    } else {
      info->creator = strdup (creator);
    }

#ifdef VESTIGE_HEADER
    info->UniqueID = *((int32_t *) &plugin->unused_id);
#else
    info->UniqueID = plugin->uniqueID;
#endif

    info->Category = strdup( "None" );          // FIXME:  
    info->numInputs = plugin->numInputs;
    info->numOutputs = plugin->numOutputs;
    info->numParams = plugin->numParams;
    info->wantMidi = fst_can_midi( fst ); 
    info->hasEditor = plugin->flags & effFlagsHasEditor ? TRUE : FALSE;
    info->canProcessReplacing = plugin->flags & effFlagsCanReplacing ? TRUE : FALSE;

    info->ParamNames = (char **) malloc( sizeof( char * ) * info->numParams );
    info->ParamLabels = (char **) malloc( sizeof( char * ) * info->numParams );
    for( i=0; i<info->numParams; i++ ) {
	char name[20];
	char label[9];
	plugin->dispatcher (plugin,
			    effGetParamName,
			    i, 0, name, 0);
	info->ParamNames[i] = strdup( name );
	plugin->dispatcher (plugin,
			    6 /* effGetParamLabel */,
			    i, 0, label, 0);
	info->ParamLabels[i] = strdup( label );
    }
    return info;
}
Пример #6
0
static int save_fst_info_file( FSTInfo *info, char *filename ) {

    FILE *fp;
    int i;


    if( info == NULL ) {
	fst_error( "info is NULL\n" );
	return TRUE;
    }

    fp = fopen( filename, "w" );
    
    if( fp == NULL ) {
	fst_error( "Cant write info file %s\n", filename );
	return TRUE;
    }

    fprintf( fp, "%s\n", info->name );
    fprintf( fp, "%s\n", info->creator );
    fprintf( fp, "%d\n", info->UniqueID );
    fprintf( fp, "%s\n", info->Category );
    fprintf( fp, "%d\n", info->numInputs );
    fprintf( fp, "%d\n", info->numOutputs );
    fprintf( fp, "%d\n", info->numParams );
    fprintf( fp, "%d\n", info->wantMidi );
    fprintf( fp, "%d\n", info->hasEditor );
    fprintf( fp, "%d\n", info->canProcessReplacing );

    for( i=0; i<info->numParams; i++ ) {
	fprintf( fp, "%s\n", info->ParamNames[i] );
    }
    for( i=0; i<info->numParams; i++ ) {
	fprintf( fp, "%s\n", info->ParamLabels[i] );
    }
	

    fclose( fp );

    return FALSE;
}
Пример #7
0
FSTInfo *fst_get_info( char *dllpath ) {

    if( fst_info_file_is_valid( dllpath ) ) {
	FSTInfo *info;
	char *fstpath = fst_dllpath_to_infopath( dllpath );

	info = load_fst_info_file( fstpath );
	free( fstpath );
	return info;

    } else {

	FSTHandle *h;
	FST *fst;
	FSTInfo *info;
	char *fstpath;

	if( !(h = fst_load( dllpath )) ) {
		return NULL;
	}
	if( !(fst = fst_instantiate( h, simple_master_callback, NULL )) ) {
	    fst_unload( h );
	    fst_error( "instantiate failed\n" );
	    return NULL;
	}
	fstpath = fst_dllpath_to_infopath( dllpath );
	if( !fstpath ) {
	    fst_close( fst );
	    fst_unload( h );
	    fst_error( "get fst filename failed\n" );
	    return NULL;
	}
	info = fst_info_from_plugin( fst );
	save_fst_info_file( info, fstpath );

	free( fstpath );
	fst_close( fst );
	fst_unload( h );
	return info;
    }
}
void Search_Monte_Carlo_Threaded<RETURNTYPE,DIMTYPE,SUBSET,CRITERION,max_threads>::evaluator_thread(unsigned int idx)
{
	assert(idx>=0 && idx<max_threads);
	assert(tlocal[idx].bestsub);
	const DIMTYPE n=tlocal[idx].bestsub->get_n();
	assert(n>0);
	assert(tlocal[idx].crit);
	ThreadLocal &tl=tlocal[idx];
	std::ostream& os=*(tlocal[idx].os);
	
	assert(_target_d>=0 && _target_d<n);
	assert(_trials_limit!=0 || _time_limit!=0);
	assert(_time_limit_check_freq>0);

	srand((RAND_MAX/max_threads)*(unsigned int)idx); // on some systems rand() yields equal value sequence in each thread

	PSubset tmp_sub(new SUBSET(n));
	unsigned long _time=0;
	unsigned long _global_trials=next_trial();
	unsigned long _local_trials=0;
	DIMTYPE _d_from_tmp=_d_from, _d_to_tmp=_d_to;
	if(_d_to_tmp<1 || _d_to_tmp>n) _d_to_tmp=n;
	if(_d_from_tmp<1 || _d_from_tmp>_d_to_tmp) _d_from_tmp=_d_to_tmp;
	assert(_d_from_tmp>=1 && _d_from_tmp<=_d_to_tmp && _d_to_tmp<=n);
	
	if(parent::output_detailed()) {std::ostringstream sos; sos << "Thread " << idx << " started." << std::endl << std::endl << std::flush; syncout::print(os,sos);}
	RETURNTYPE val;
	while( (_trials_limit==0 || _global_trials<_trials_limit) && (_time_limit==0 || _time<_time_limit) )
	{
		if(_target_d==0) {
			if(_d_prob>0.0) do {tmp_sub->make_random_subset(_d_prob);} while(tmp_sub->get_d()==0);
			else tmp_sub->make_random_subset(_d_from_tmp,_d_to_tmp);
		} else tmp_sub->make_random_subset(_target_d);

		if(!tl.crit->evaluate(val,tmp_sub)) throw fst_error("Search_Monte_Carlo_Threaded::evaluate_candidate() criterion evaluation failure.");
		if(tl.tracker) tl.tracker->add(val,tmp_sub);
		if(!tl.bestval_available || val>tl.bestval || (val==tl.bestval && tmp_sub->get_d()<tl.bestsub->get_d())) {
			tl.bestval=val;
			tl.bestsub->stateless_copy(*tmp_sub);
			tl.bestval_available=true;
			if(parent::output_normal()) {std::ostringstream sos; sos << "THREAD " << idx << " new MAXCRIT="<<val<<", iter=" << _global_trials << ", " << *tmp_sub << std::endl << *swatch << std::endl << std::endl << std::flush; syncout::print(os,sos);}
		} else
			if(parent::output_detailed()) {std::ostringstream sos; sos << "THREAD " << idx << " crit="<<val<<", iter=" << _global_trials << ", " << *tmp_sub << std::endl << *swatch << std::endl << std::endl << std::flush; syncout::print(os,sos);}

		_local_trials++;
		_global_trials=next_trial();
		if(_local_trials%_time_limit_check_freq==0) _time=(unsigned long)swatch->time_elapsed();
		if(parent::output_detailed()) {std::ostringstream sos; sos << " iter=" << _global_trials << " _time="<<_time<<", _time_limit=" << _time_limit << std::endl << std::endl << std::flush; syncout::print(os,sos);}
	}
	if(parent::output_detailed()) {std::ostringstream sos; sos << "Thread " << idx << " finished." << std::endl << std::endl << std::flush; syncout::print(os,sos);}
	assert(tl.bestval_available);
}
void Data_Splitter<INTERVALCONTAINER,IDXTYPE>::assign(const unsigned int _clsidx, const PIntervaller _train, const PIntervaller _test)
{
	assert(_clsidx>=0);
	assert(_train); 
	assert(_test);
	try {	
		while(csplit.size()<=_clsidx) {PClassSplitter pcs(new TClassSplitter); csplit.push_back(pcs);}
		csplit[_clsidx]->train=_train; 
		csplit[_clsidx]->test=_test;
	} catch(...) {
		throw fst_error("Data_Splitter::assign() out-of-index? error.");
	}
}
void Candidate_Evaluator_Threaded<RETURNTYPE,DIMTYPE,SUBSET,CRITERION,max_threads>::evaluator_thread(unsigned int tidx)
{
	assert(tidx>=0 && tidx<max_threads);
	ThreadLocal &tl=tlocal[tidx];
	assert(tl.crit);

	DIMTYPE idx;

	while(get_candidate(idx))
	{
		CandidateResult &cr=cres[idx];
		if(!tl.crit->evaluate(cr.result,cr.sub)) throw fst_error("Candidate_Evaluator_Threaded::crit->evaluate(cr.result,cr.sub) criterion evaluation failure.");
	}
}
bool Data_Splitter_RandomRandom<INTERVALCONTAINER,IDXTYPE,BINTYPE>::makeFirstSplit()
{
	TCC::assert_csplit();
	try {
		if(_randomize) srand( (unsigned int)time(NULL) );
		for(typename TCC::ClassIterator c=TCC::csplit.begin();c!=TCC::csplit.end();c++) {
			makeRandomSplit((*c)->n,(*c)->train,(*c)->test);
		}
		current_split=1;
	} catch(...) {
		throw fst_error("Data_Splitter_RandomRandom::makeFirstSplit() error.");
	}
	return true;
}
bool Data_Splitter_Resub<INTERVALCONTAINER,IDXTYPE>::makeFirstSplit()
{
	TCC::assert_csplit();
	try {
		for(typename TCC::ClassIterator c=TCC::csplit.begin();c!=TCC::csplit.end();c++) {
			Data_Interval<IDXTYPE> tri={0,(*c)->n},tei={0,(*c)->n};
			(*c)->train->clear();	(*c)->train->push_back(tri);
			(*c)->test->clear();	(*c)->test->push_back(tei);
		}
	} catch(...) {
		throw fst_error("Data_Splitter_Resub::makeFirstSplit() error.");
	}
	return true;
}
bool Data_Splitter_RandomRandom<INTERVALCONTAINER,IDXTYPE,BINTYPE>::makeNextSplit()
{
	try {
		if(current_split<splits) {
			++current_split;
			for(typename TCC::ClassIterator c=TCC::csplit.begin();c!=TCC::csplit.end();c++) {
				makeRandomSplit((*c)->n,(*c)->train,(*c)->test);
			}
			return true;
		} else current_split=0;
	} catch(...) {
		throw fst_error("Data_Splitter_RandomRandom::makeNextSplit() error.");
	}
	return false;
}
Пример #14
0
static int fst_info_file_is_valid( char *dllpath ) {
    struct stat dllstat, fststat;
    char *fstpath = fst_dllpath_to_infopath( dllpath );

    if( !fstpath ) return FALSE;
    
    if( stat( dllpath, &dllstat ) ){ fst_error( "dll path %s invalid\n", dllpath );  return TRUE; }
    if( stat( fstpath, &fststat ) ) return FALSE;

    free( fstpath );
    if( dllstat.st_mtime > fststat.st_mtime )
	return FALSE;
    else 
	return TRUE;
}
bool Data_Splitter_5050<INTERVALCONTAINER,IDXTYPE>::makeFirstSplit()
{
	TCC::assert_csplit();
	try {
		for(typename TCC::ClassIterator c=TCC::csplit.begin();c!=TCC::csplit.end();c++) {
			const IDXTYPE trsiz=(*c)->n/2;
			const IDXTYPE tesiz=(*c)->n-trsiz;
			Data_Interval<IDXTYPE> tri={0,trsiz},tei={trsiz,tesiz};
			(*c)->train->clear();	(*c)->train->push_back(tri);
			(*c)->test->clear();	(*c)->test->push_back(tei);
		}
	} catch(...) {
		throw fst_error("Data_Splitter_5050::makeFirstSplit() error.");
	}
	return true;
}
void Data_Accessor_Splitting_MemTRN<DATATYPE,IDXTYPE,INTERVALCONTAINER>::initial_data_read() //!< \note off-limits in shared_clone
{
	if(Clonable::is_sharing_clone()) throw fst_error("Data_Accessor_Splitting_MemTRN()::initial_data_read() called from shared_clone instance.");
	{std::ostringstream sos; sos << "Reading data to memory..."; syncout::print(std::cout,sos);}
	IDXTYPE idx=0;
	for(unsigned int c=0;c<trnFile->getNoOfClasses();c++) 
	{
		for(IDXTYPE p=0;p<trnFile->getClassSize(c);p++) {
			for(unsigned int f=0;f<trnFile->getNoOfFeatures();f++) {
				this->data[idx++]=trnFile->read_val();
			}
		}
	}
	trnFile->close();
	{std::ostringstream sos; sos << "done."<<std::endl; syncout::print(std::cout,sos);}
}
void Data_Splitter_RandomRandom<INTERVALCONTAINER,IDXTYPE,BINTYPE>::makeRandomSplit(const IDXTYPE n, const boost::shared_ptr<INTERVALCONTAINER> list_train, const boost::shared_ptr<INTERVALCONTAINER> list_test)
{
	try {
		assert(list_train);
		assert(list_test);
		assert(n>0);
		assert(0<=perctrain); // better (0<perctrain) ?
		assert(0<=perctest); // better (0<perctest) ?
		assert(perctrain+perctest<=100);
		if(!_data || _n_max<n) {_data.reset(new BINTYPE[n]); _n_max=n;}
		const BINTYPE id_empty = 0;
		const BINTYPE id_train = 1;
		const BINTYPE id_test = 2;
		const IDXTYPE trsiz=(n * perctrain)/100;
		const IDXTYPE tesiz=(n * perctest)/100;
		assert(trsiz+tesiz<=n);
		IDXTYPE i;
		for(i=0;i<n;i++) _data[i]=id_empty;

		// now fill randomly perctrain% for training and perctest% for testing
		// NOTE: acceleration - rand() needs to be called only min{perctrain,100-perctrain} and min{perctest,100-perctest} times - just adjust _data pre-fill
		//                    - also, if(perctrain+perctest==100), then rand() loop is needed only for one of them
		if(perctrain<=50) {
			fill_randomly(n,id_empty,id_train,trsiz/*count*/,0/*minidx*/,n-1/*maxidx*/); // randomly choose train samples
		} else {
			fill(n,id_empty,id_train,0/*minidx*/,n-1/*maxidx*/);
			fill_randomly(n,id_train,id_empty,n-trsiz/*count*/,0/*minidx*/,n-1/*maxidx*/); // randomly choose non-train samples
		}
		if(perctrain+perctest==100) {
			fill(n,id_empty,id_test,0/*minidx*/,n-1/*maxidx*/);
		} else if(perctest<=(100-perctrain)/2) {
			fill_randomly(n,id_empty,id_test,tesiz/*count*/,0/*minidx*/,n-1/*maxidx*/); // randomly choose test samples
		} else {
			fill(n,id_empty,id_test,0/*minidx*/,n-1/*maxidx*/);
			fill_randomly(n,id_test,id_empty,n-trsiz-tesiz/*count*/,0/*minidx*/,n-1/*maxidx*/); // randomly choose non-test samples
		}

		// now transform the binary representation to TCC::train and TCC::test lists
		translate(n,id_train,list_train);
		translate(n,id_test,list_test);
		
	} catch(...) {
		throw fst_error("Data_Splitter_RandomRandom::makeRandomSplit() error.");
	}
}
Пример #18
0
static FSTInfo *fst_info_from_plugin( FST *fst ) {
    FSTInfo *info = (FSTInfo *) malloc( sizeof( FSTInfo ) );
    AEffect *plugin;
    int i;

    if( ! fst ) {
	fst_error( "fst is NULL\n" );
	return NULL;
    }

    if( ! info ) return NULL;
    
    plugin = fst->plugin;
    

    info->name = strdup(fst->handle->name ); 
    info->UniqueID = plugin->uniqueID;
    info->Category = strdup( "None" );          // FIXME:  
    info->numInputs = plugin->numInputs;
    info->numOutputs = plugin->numOutputs;
    info->numParams = plugin->numParams;
    info->wantMidi = fst_can_midi( fst ); 
    info->hasEditor = plugin->flags & effFlagsHasEditor ? TRUE : FALSE;
    info->canProcessReplacing = plugin->flags & effFlagsCanReplacing ? TRUE : FALSE;

    info->ParamNames = (char **) malloc( sizeof( char * ) * info->numParams );
    info->ParamLabels = (char **) malloc( sizeof( char * ) * info->numParams );
    for( i=0; i<info->numParams; i++ ) {
	char name[20];
	char label[9];
		plugin->dispatcher (plugin,
				    effGetParamName,
				    i, 0, name, 0);
		
		plugin->dispatcher (plugin,
				    effGetParamLabel,
				    i, 0, label, 0);

	info->ParamNames[i] = strdup( name );
	info->ParamLabels[i] = strdup( label );
    }
    return info;
}
Пример #19
0
static void 
queue_midi (JackVST *jvst, int val1, int val2, int val3)
{
	struct VstMidiEvent *pevent;
	jack_ringbuffer_data_t vec[2];

	jack_ringbuffer_get_write_vector (jvst->event_queue, vec);

	if (vec[0].len < sizeof (struct VstMidiEvent)) {
		fst_error ("event queue has no write space");
		return;
	}
		
	pevent = (struct VstMidiEvent *) vec[0].buf;

	//  printf("note: %d\n",note);
	
	pevent->type = kVstMidiType;
	pevent->byteSize = 24;
	pevent->deltaFrames = 0;
	pevent->flags = 0;
	pevent->detune = 0;
	pevent->noteLength = 0;
	pevent->noteOffset = 0;
	pevent->reserved1 = 0;
	pevent->reserved2 = 0;
	pevent->noteOffVelocity = 0;
	pevent->midiData[0] = val1;
	pevent->midiData[1] = val2;
	pevent->midiData[2] = val3;
	pevent->midiData[3] = 0;
	
	//printf("Sending: %x %x %x\n",val1,val2,val3);

	jack_ringbuffer_write_advance (jvst->event_queue, sizeof (struct VstMidiEvent));
}
	Criterion_Multinomial_Bhattacharyya* stateless_clone() const {throw fst_error("Criterion_Multinomial_Bhattacharyya::stateless_clone() not supported, use Criterion_Multinomial_Bhattacharyya::clone() instead.");}
	Data_Scaler_to01(const int dims=1): first_learn(true), missing_values(false), _missing_val_code(0) {if(dims!=1) throw fst_error("Data_Scaler_to01() implemented for 1-dimensional data only."); notify("Data_Scaler_to01 constructor.");}
	Criterion_Subset_Size* stateless_clone() const {throw fst_error("Criterion_Subset_Size::stateless_clone() not supported, use Criterion_Subset_Size::clone() instead.");}
	Classifier_Multinomial_NaiveBayes* stateless_clone() const {throw fst_error("Classifier_Multinomial_NaiveBayes::stateless_clone() not supported, use Classifier_Multinomial_NaiveBayes::clone() instead.");}
	Data_Splitter* sharing_clone() const {throw fst_error("Data_Splitter::sharing_clone() not supported, use Data_Splitter::stateless_clone() instead.");}
	Criterion_Negative* stateless_clone() const {throw fst_error("Criterion_Negative::stateless_clone() not supported, use Criterion_Negative::clone() instead.");}
	Result_Tracker_Regularizer* sharing_clone() const {throw fst_error("Result_Tracker_Regularizer::sharing_clone() not supported, use Result_Tracker_Regularizer::stateless_clone() instead.");}
void Data_Accessor_Splitting_MemTRN<DATATYPE,IDXTYPE,INTERVALCONTAINER>::initial_file_prepare() //!< \note off-limits in shared_clone
{
	if(Clonable::is_sharing_clone()) throw fst_error("Data_Accessor_Splitting_MemTRN()::initial_data_prepare() called from shared_clone instance.");
	trnFile.reset(new Data_File_TRN<DATATYPE,IDXTYPE>());
	trnFile->open(this->filename);
}