void THREADING_set_priority(priority_t priority) { #if defined(FOR_WINDOWS) int success = SetThreadPriority(GetCurrentThread(), priority.priority); if (success==0) { GFX_Message(NULL, "SetThreadPriority failed: %d", success); } #elif defined(__linux__) || defined(FOR_MACOSX) int success = pthread_setschedparam(pthread_self(), priority.policy, &priority.param); if (success!=0) { GFX_Message(NULL, "pthread_setschedparam(,%d,%d) returned %d (%s)", priority.policy, priority.param.sched_priority, success, success==EINVAL ? "policy is not a recognized policy, or param does not make sense for the policy." : success==EPERM ? "The caller does not have appropriate privileges to set the specified scheduling policy and parameters." : success==ENOTSUP ? "attempt was made to set the policy or scheduling parameters to an unsupported value" : "Unknown error type... (really strange)" ); } #else #error "unkwnonw architantaiehnr" #endif }
static void save_fxbp(SoundPlugin *plugin, wchar_t *wfilename, bool is_fxb){ Data *data = (Data*)plugin->data; AudioPluginInstance *instance = data->audio_instance; MemoryBlock memoryBlock; bool result = VSTPluginFormat::saveToFXBFile(instance, memoryBlock, is_fxb); if (result==false){ GFX_Message(NULL, "Unable to create FXB/FXP data for this plugin"); return; } String filename(wfilename); File file(filename); Result result2 = file.create(); if (result2.failed()){ GFX_Message(NULL, "Unable to create file %s (%s)", STRING_get_chars(wfilename), result2.getErrorMessage().toRawUTF8()); return; } bool result3 = file.replaceWithData(memoryBlock.getData(), memoryBlock.getSize()); if (result3==false){ GFX_Message(NULL, "Unable to write data to file %s (disk full?)", STRING_get_chars(wfilename)); return; } printf("\n\n\n ***************** result: %d\n\n\n\n",result); }
void FAUST_change_qtguistyle(const char *style_name){ QString filename = OS_get_full_program_file_path("packages/faust2/architecture/faust/gui/Styles/" + QString(getFaustGuiStyle()) + ".qss"); disk_t *disk = DISK_open_for_reading(filename); if (disk==NULL){ GFX_Message(NULL, "File not found (%s)", filename.toUtf8().constData()); } else { QString stylesheet = DISK_read_qstring_file(disk); if (DISK_close_and_delete(disk)==false) { GFX_Message(NULL, "Unable to read from %s", filename.toUtf8().constData()); stylesheet = ""; } if (stylesheet!="") g_qtgui_stylesheet = stylesheet; } if (g_qtgui_stylesheet != "") for(auto faustqdialog : g_faustqdialogs) faustqdialog->setStyleSheet(g_qtgui_stylesheet); }
bool transfer_temporary_file_to_file(void){ R_ASSERT(type==WRITE); R_ASSERT(temporary_write_file != NULL); #if SUPPORT_TEMP_WRITING_FUNCTIONS if (filename=="") return true; #endif bool exists = QFile::exists(filename); // Maybe take backup of the existing file here. if (exists) QFile::remove(filename); // And if this fails, use the backup (but still return false, of course) bool ret = QFile::copy(temporary_write_file->fileName(), filename); if (ret==false){ if (exists) GFX_Message(NULL, "Error. Unable to save file \"%s\". In addition the already existing file \"%s\" was deleted.\n", filename.toUtf8().constData(), filename.toUtf8().constData()); else GFX_Message(NULL, "Error. Unable to save file \"%s\"", filename.toUtf8().constData()); } return ret; }
priority_t THREADING_get_priority(void) { priority_t priority; #if defined(FOR_WINDOWS) priority.priority = GetThreadPriority(GetCurrentThread()); if (priority.priority==THREAD_PRIORITY_ERROR_RETURN) { GFX_Message(NULL, "GetThreadPriority failed: %d",GetLastError()); priority.priority = THREAD_PRIORITY_NORMAL; } #elif defined(__linux__) || defined(FOR_MACOSX) int success = pthread_getschedparam(pthread_self(), &priority.policy, &priority.param); if (success!=0) { GFX_Message(NULL, "pthread_getschedparam returned %d (really strange))",success); } #else #error "unkwnonw architantaiehnr" #endif return priority; }
static void *dev_create_plugin_data(const SoundPluginType *plugin_type, SoundPlugin *plugin, hash_t *state, float sample_rate, int block_size, bool is_loading){ Devdata *devdata = new Devdata; plugin->data = devdata; if (state!=NULL) { devdata->code = STRING_get_qstring(STRING_fromBase64(HASH_get_string(state, "code"))); devdata->options = STRING_get_qstring(STRING_fromBase64(HASH_get_string(state, "options"))); } else devdata->code = DEFAULT_FAUST_DEV_PROGRAM; if (is_loading==false) { FAUST_start_compilation(plugin); } else { if (FAUST_compile_now(plugin, is_loading)==false){ GFX_Message(NULL, "Something went wrong when compiling: %s", devdata->reply.error_message.toUtf8().constData()); plugin->data = NULL; delete devdata; return NULL; } } return devdata; }
int MIDI_initInstrumentPlugIn(struct Instruments *instrument){ MIDI_set_use_0x90_for_note_off(SETTINGS_read_int("use_0x90_for_note_off",0)==0?false:true); if(MIDI_New(instrument)==false){ GFX_Message(NULL, "Unable to open MIDI"); return INSTRUMENT_FAILED; } instrument->instrumentname = "MIDI instrument"; //instrument->getMaxVelocity = &MIDIgetMaxVelocity; instrument->getFxNames = MIDI_getFxNames; instrument->createFX = MIDI_createFX; instrument->getFX = &MIDIgetFX; instrument->getPatch = &MIDIgetPatch; instrument->CloseInstrument = MIDICloseInstrument; instrument->StopPlaying = MIDIStopPlaying; instrument->CopyInstrumentData = MIDI_CopyInstrumentData; instrument->PlayFromStartHook = MIDIPlayFromStartHook; instrument->LoadFX = MIDILoadFX; instrument->PP_Update = MIDI_PP_Update; instrument->handle_fx_when_theres_a_new_patch_for_track = MIDI_handle_fx_when_theres_a_new_patch_for_track; instrument->remove_patch = MIDI_remove_patch; instrument->setPatchData = MIDISetPatchData; instrument->getPatchData = MIDIGetPatchData; return INSTRUMENT_SUCCESS; }
int addNote2(float notenum,int velocity, int line,int counter,int dividor, int end_line,int end_counter,int end_dividor, int windownum, int blocknum, int tracknum) { struct Tracker_Windows *window; struct WBlocks *wblock=getWBlockFromNumA(-1,&window,blocknum); struct WTracks *wtrack=getWTrackFromNum(windownum,blocknum,tracknum); if(wblock==NULL || wtrack==NULL) { GFX_Message(NULL, "unknown wblock(%p) or wtrack(%p) %d/%d/%d\n",wblock,wtrack,windownum,blocknum,tracknum); return -1; } Place *place = PlaceCreate(line,counter,dividor); ValidatePlace(place); if (!PlaceLegal(wblock->block, place)) { GFX_Message(NULL, "Place %d + %d/%d is not legal", line, counter, dividor); return -1; } Place *end_place = end_line==-1 ? NULL : PlaceCreate(end_line,end_counter,end_dividor); ValidatePlace(end_place); if (end_place != NULL && !PlaceLegal(wblock->block, end_place)) { GFX_Message(NULL, "Place %d + %d/%d is not legal", end_line, end_counter, end_dividor); return -1; } struct Notes *note = InsertNote(wblock, wtrack, place, end_place, notenum, velocity, true); window->must_redraw=true; return ListFindElementPos3(&wtrack->track->notes->l,¬e->l); }
// Only used for audio files, so we don't bother with decompression. const wchar_t *DISK_base64_to_file(const wchar_t *wfilename, const char *chars){ QFile *file; QTemporaryFile *temporary_write_file = NULL; QFile outfile; QByteArray data = QByteArray::fromBase64(chars); if (wfilename==NULL) { temporary_write_file = new QTemporaryFile; file = temporary_write_file; } else { outfile.setFileName(STRING_get_qstring(wfilename)); file = &outfile; } if (file->open(QIODevice::WriteOnly)==false){ GFX_Message(NULL, "Unable to open file \"%s\" (%s)", file->fileName().toUtf8().constData(), file->errorString().toUtf8().constData()); return NULL; } if (file->write(data) != data.size()){ GFX_Message(NULL, "Unable to write to file \"%s\" (%s)", file->fileName().toUtf8().constData(), file->errorString().toUtf8().constData()); file->close(); return NULL; } file->close(); if (wfilename==NULL){ radium::ScopedMutex lock(&g_mutex); g_temporary_files[temporary_write_file->fileName()] = temporary_write_file; } return STRING_create(file->fileName()); }
void TRACK_make_monophonic_destructively(struct Tracks *track){ struct Tracker_Windows *window = root->song->tracker_windows; struct WBlocks *wblock = window->wblock; struct Notes *note = track->notes; bool have_made_undo = false; while(note!=NULL){ struct Notes *next = NextNote(note); if (next==NULL) break; if (PlaceGreaterThan(¬e->end, &next->l.p)){ PLAYER_lock();{ if (PlaceEqual(¬e->l.p, &next->l.p)) { ListRemoveElement3(&track->notes, &next->l); } else { PlaceCopy(¬e->end, &next->l.p); note = next; } }PLAYER_unlock(); if (have_made_undo==false){ ADD_UNDO(Notes(window, wblock->block, track, wblock->curr_realline ) ); have_made_undo = true; } } else { note = next; } } if (have_made_undo==false) GFX_Message(NULL, "Track is already monophonic"); else window->must_redraw = true; }
disk_t *DISK_open_temp_for_writing(void){ GFX_Message(NULL, "Warning, never tested"); disk_t *disk = new disk_t("", disk_t::WRITE); if (disk->open()==false){ delete disk; return NULL; } return disk; }
QString FAUST_get_cpp_code(const struct SoundPlugin *plugin){ Devdata *devdata = (Devdata*)plugin->data; if (devdata->reply.svg_dir==NULL || devdata->reply.svg_dir->isValid()==false) return ""; QString filename = devdata->reply.svg_dir->path() + QDir::separator() + "cppsource.cpp"; disk_t *disk = DISK_open_for_reading(filename); if (disk==NULL){ GFX_Message(NULL, "File not found (%s)", filename.toUtf8().constData()); return ""; } QString cpp_code = DISK_read_qstring_file(disk); if (DISK_close_and_delete(disk)==false) { GFX_Message(NULL, "Unable to read from %s", filename.toUtf8().constData()); return ""; } return cpp_code; }
wchar_t *DISK_close_temp_for_writing(disk_t *disk){ GFX_Message(NULL, "Warning, never tested"); disk->close(); QByteArray data = disk->temporary_write_file->readAll(); wchar_t *ret = STRING_create(data.toUtf8().constData()); delete disk; return ret; }
static void recreate_from_state(struct SoundPlugin *plugin, hash_t *state){ const wchar_t *filename = HASH_get_string(state, "filename"); int instrument_number = HASH_get_int(state, "instrument_number"); int resampler_type = HASH_get_int(state, "resampler_type"); if(filename==NULL){ RError("filename==NULL"); return; } if(set_new_sample(plugin,filename,instrument_number,resampler_type)==false) GFX_Message(NULL, "Could not load soundfile \"%s\". (instrument number: %d)\n",STRING_get_chars(filename),instrument_number); }
static wchar_t *read_line(disk_t *file){ wchar_t *line = DISK_read_wchar_line(file); //printf("%d: -%S-\n", g_curr_disk_line, line); if(line==NULL){ GFX_Message(NULL, "End of file before finished reading hash map"); return NULL; } return line; }
void PLUGINHOST_load_fxbp(SoundPlugin *plugin, wchar_t *wfilename){ Data *data = (Data*)plugin->data; AudioPluginInstance *instance = data->audio_instance; String filename(wfilename); File file(filename); MemoryBlock memoryBlock; bool success = file.loadFileAsData(memoryBlock); if (success==false){ GFX_Message(NULL, "Unable to load %s", STRING_get_chars(wfilename)); return; } success = VSTPluginFormat::loadFromFXBFile(instance, memoryBlock.getData(), memoryBlock.getSize()); if (success==false){ GFX_Message(NULL, "Could not use %s for this plugin", STRING_get_chars(wfilename)); return; } printf("************** size: %d\n",(int)memoryBlock.getSize()); }
static void set_wav_loop_points(Sample *sample, const wchar_t *filename, bool set_loop_on_off){ disk_t *file = DISK_open_binary_for_reading(filename); if(file==NULL){ GFX_Message(NULL, "Could not open file \"%s\". libsndfile could open the file though. Something might be wrong with your disk.",filename); return; } if(set_wav_loop_points_using_smpl_chunk(sample,file, set_loop_on_off)==false) set_wav_loop_points_using_cues(sample,file, set_loop_on_off); DISK_close_and_delete(file); }
int addSignature(int numerator, int denominator, Place place, int blocknum) { struct Tracker_Windows *window; struct WBlocks *wblock=getWBlockFromNumA(-1,&window,blocknum); if(wblock==NULL) { GFX_Message(NULL, "unknown block(%p)",blocknum); return -1; } if (!PlaceLegal(wblock->block, &place)) { GFX_Message(NULL, "Place %s is not legal", PlaceToString(&place)); return -1; } ADD_UNDO(Signatures_CurrPos(window)); struct Signatures *signature = SetSignature(wblock->block,&place,ratio(numerator, denominator)); window->must_redraw=true; return ListFindElementPos3(&wblock->block->signatures->l,&signature->l); }
void setNoteEndPlace(int line,int counter,int dividor,int windownum,int blocknum,int tracknum,int notenum){ struct Tracker_Windows *window; struct WBlocks *wblock; struct WTracks *wtrack; struct Notes *note = getNoteFromNumA(windownum, &window, blocknum, &wblock, tracknum, &wtrack, notenum); if (note==NULL) return; Place *place = PlaceCreate(line,counter,dividor); if (!PlaceLegal(wblock->block, place)) { GFX_Message(NULL, "Place %d + %d/%d is not legal", line, counter, dividor); return; } PlaceCopy(¬e->end, place); }
bool close(void){ bool ret = true; file()->close(); QFile::FileError error = file()->error(); if (error != 0) { GFX_Message(NULL, "Error %s file: %s",type==WRITE ? "writing to" : "reading from", error_to_string(error).toUtf8().constData()); ret = false; } if (type==WRITE) { bool copyret = transfer_temporary_file_to_file(); if (copyret==false) ret = false; } return ret; }
void MyPutMidi( struct MidiPort *midi_port, // uint32_t msg, int cc, int data1, int data2, STime time, int maxbuff, int skip ){ if(cc<0x80 || cc>0xef || (data1&0xff)>0x7f || (data2&0xff)>0x7f){ GFX_Message(NULL, "Error. Faulty midi-message. status: %x, data1: %x, data2: %x\n",cc,data1,data2); return; } OS_GoodPutMidi(midi_port->port,cc,data1,data2,time,(uint32_t)maxbuff); OnOffNotesTrack(midi_port,cc,data1,data2); }
static bool spool_to_next_wav_chunk(disk_t *file, int endpos){ if(DISK_spool(file,4)==false) // chunk id return false; // end of file int size=read_le32int(file); if(size%2) // chunks are aligned by two bytes, but the size doesn't have to be. size++; if(DISK_pos(file)>=endpos-1) return false; // end of file if(size<4 || DISK_spool(file,size)==false){ //RError("Broken wave file? Chunk size: %d\n",size); GFX_Message(NULL, "Warning: Wav file seems to be a little bit broken. If you think this might be a bug in Radium, please send the wave file to [email protected]"); return false; } return true; }
static void show_message(int type, char *message){ static double last_ignore = -3000.0; // don't want to ignore errors the first two seconds. static bool ignore_rest_of_the_program = false; char *typestring = type==IS_ERROR?"Error":"Warning"; if(ignore_rest_of_the_program==true) return; if(TIME_get_ms()-last_ignore < 2000) return; char full_message[1000]; sprintf(full_message,"%s: %s", typestring, message); #if 0 // Always use SYSTEM_show_message. vector_t v = {0}; VECTOR_push_back(&v, "continue"); VECTOR_push_back(&v, "quit"); VECTOR_push_back(&v, "ignore warnings and errors for two seconds"); VECTOR_push_back(&v, "ignore warnings and errors for the rest of the program"); int ret = GFX_Message(&v, full_message); if (ret==-1) ret = SYSTEM_show_message(full_message); #else int ret = SYSTEM_show_message(full_message); #endif switch(ret){ case 0: break; case 1: { char *hello = NULL; hello[0] = 50; abort(); } case 2: last_ignore=TIME_get_ms(); break; case 3: ignore_rest_of_the_program=true; break; } }
int addLPB(int lpb_value, Place place, int blocknum) { struct Tracker_Windows *window; struct WBlocks *wblock=getWBlockFromNumA(-1,&window,blocknum); if(wblock==NULL) return -1; if (!PlaceLegal(wblock->block, &place)) { GFX_Message(NULL, "Place %s is not legal", PlaceToString(&place)); return -1; } ADD_UNDO(LPBs_CurrPos(window)); struct LPBs *lpb = SetLPB(wblock->block,&place,lpb_value); window->must_redraw=true; return ListFindElementPos3(&wblock->block->lpbs->l,&lpb->l); }
int addBPM(int bpm, Place place, int blocknum) { struct Tracker_Windows *window; struct WBlocks *wblock=getWBlockFromNumA(-1,&window,blocknum); if(wblock==NULL) return -1; if (!PlaceLegal(wblock->block, &place)) { GFX_Message(NULL, "Place %s is not legal", PlaceToString(&place)); return -1; } ADD_UNDO(Tempos_CurrPos(window)); struct Tempos *tempo = SetTempo(wblock->block,&place,bpm); window->must_redraw=true; return ListFindElementPos3(&wblock->block->tempos->l,&tempo->l); }
void MIDISetPatchData(struct Patch *patch, char *key, char *value){ if(false){ }else if(!strcasecmp(key,"port")){ getPatchData(patch)->midi_port = MIDIgetPort(NULL, NULL, value==NULL ? NULL : !strcmp("",value) ? NULL : value); printf("Sat patchdata(%s)->midi_port to %s\n",patch->name,value); }else if(!strcasecmp(key,"channel")){ getPatchData(patch)->channel = atoi(value); }else if(!strcasecmp(key,"LSB")){ getPatchData(patch)->LSB = atoi(value); }else if(!strcasecmp(key,"MSB")){ getPatchData(patch)->MSB = atoi(value); }else if(!strcasecmp(key,"preset")){ getPatchData(patch)->preset = atoi(value); } else GFX_Message(NULL, "MIDISetPatchData: Unknown key \"%s\" for midi instrument", key); }
static AudioPluginInstance *get_audio_instance(const TypeData *type_data, float sample_rate, int block_size){ static bool inited=false; static AudioPluginFormatManager formatManager; if (inited==false){ formatManager.addDefaultFormats(); inited=true; } //int uid = VST_get_uid(type_data->library_file_full_path); //printf("uid: %d\n",uid); //getchar(); //((PluginDescription*)description)->uid = uid; //if (uid==-1) // return NULL; String errorMessage; PluginDescription description; description.fileOrIdentifier = String(type_data->file_or_identifier); description.uid = type_data->uid; AudioPluginInstance *instance = formatManager.createPluginInstance(description,sample_rate,block_size,errorMessage); if (instance==NULL){ GFX_Message(NULL, "Unable to open VST plugin %s: %s\n",description.fileOrIdentifier.toRawUTF8(), errorMessage.toRawUTF8()); return NULL; } instance->setPlayHead(&myAudioPlayHead); instance->prepareToPlay(sample_rate, block_size); return instance; }
static void *create_plugin_data(const SoundPluginType *plugin_type, SoundPlugin *plugin, hash_t *state, float sample_rate, int block_size){ #if JUCE_LINUX const MessageManagerLock mmLock; #endif TypeData *type_data = (struct TypeData*)plugin_type->data; if(isFullVersion()==false && num_running_plugins >= 2){ GFX_Message(NULL, "Using more than 2 VST plugins is only available to subscribers.<p>" "Subscribe <a href=\"http://users.notam02.no/~kjetism/radium/download.php\">here</a>."); return NULL; } AudioPluginInstance *audio_instance = get_audio_instance(type_data, sample_rate, block_size); if (audio_instance==NULL){ return NULL; } PluginDescription description = audio_instance->getPluginDescription(); //plugin->name = talloc_strdup(description.name.toUTF8()); Data *data = new Data(audio_instance, plugin, audio_instance->getNumInputChannels(), audio_instance->getNumOutputChannels()); plugin->data = data; if(type_data->effect_names==NULL) set_plugin_type_data(audio_instance,(SoundPluginType*)plugin_type); // 'plugin_type' was created here (by using calloc), so it can safely be casted into a non-const. if (state!=NULL) recreate_from_state(plugin, state); num_running_plugins++; return data; }
hash_t *HASH_load(disk_t *file){ wchar_t *line = L""; while(STRING_starts_with(line, "#") || STRING_equals2(STRING_trim(line), L"")) line = READ_LINE(file); int version; if(STRING_equals(line,">> HASH MAP BEGIN")){ version = 1; } else if (STRING_equals(line,">> HASH MAP V2 BEGIN")){ version = 2; } else if (STRING_equals(line,">> HASH MAP V3 BEGIN")){ version = 3; } else if (STRING_starts_with(line, ">> HASH MAP V")){ version = 3; vector_t v = {0}; int try_anyway = VECTOR_push_back(&v, "Try anyway (program might crash and/or behave unstable)"); int ok = VECTOR_push_back(&v, "Ok"); int res = GFX_Message(&v, "Need a newer version of Radium to load this file"); if (res!=try_anyway) return NULL; (void)ok; } else { GFX_Message(NULL, "Trying to load something which is not a hash map. First line: \"%S\"", line); return NULL; } line = READ_LINE(file); int elements_size = STRING_get_int(line); hash_t *hash=HASH_create(elements_size); hash->version = version; line = READ_LINE(file); while(!STRING_equals(line,"<< HASH MAP END") && !STRING_equals(line,"<< HASH MAP V2 END") && !STRING_equals(line,"<< HASH MAP V3 END")){ const char *key = STRING_get_chars(line); int i = 0; if(version > 1){ line = READ_LINE(file); i = STRING_get_int(line); int new_size = i+1; if(new_size > hash->num_array_elements) hash->num_array_elements = new_size; } else if(!strncmp(key,"<int hash>",strlen("<int hash>"))) { sscanf(key, "<int hash> %d", &i); key = ""; hash->num_array_elements++; } bool success; dyn_t dyn = DYN_load(file, &success); if (!success) return NULL; put_dyn(hash, key, i, dyn); line = READ_LINE(file); } return hash; }
wchar_t *HASH_to_string(const hash_t *hash){ GFX_Message(NULL, "Warning, never tested"); disk_t *disk = DISK_open_temp_for_writing(); HASH_save(hash, file); return DISK_close_temp_for_writing(disk); }