// Apply bus automation curves (monitor, gain, pan). void qtractorBus::applyCurveFile ( BusMode busMode, qtractorCurveFile *pCurveFile ) const { if (m_pMonitorSubject == NULL) return; if (pCurveFile == NULL) return; if (pCurveFile->items().isEmpty()) return; qtractorCurveList *pCurveList = pCurveFile->list(); if (pCurveList == NULL) return; qtractorSession *pSession = m_pEngine->session(); if (pSession == NULL) return; qtractorMainForm *pMainForm = qtractorMainForm::getInstance(); if (pMainForm == NULL) return; qtractorMonitor *pMonitor = NULL; if (busMode & Input) pMonitor = monitor_in(); else pMonitor = monitor_out(); if (pMonitor == NULL) return; pCurveFile->setBaseDir(pSession->sessionDir()); QListIterator<qtractorCurveFile::Item *> iter(pCurveFile->items()); while (iter.hasNext()) { qtractorCurveFile::Item *pCurveItem = iter.next(); switch (pCurveItem->index) { case 0: // 0=MonitorSubject pCurveItem->subject = monitorSubject(); break; case 1: // 1=PanSubject pCurveItem->subject = pMonitor->panningSubject(); break; case 2: // 2=GainSubject pCurveItem->subject = pMonitor->gainSubject(); break; } } pCurveFile->apply(pSession->timeScale()); }
// Map bus (monitor, gain, pan) controllers (MIDI). void qtractorBus::mapControllers ( BusMode busMode ) { if (m_pMonitorObserver == NULL) return; qtractorMidiControl *pMidiControl = qtractorMidiControl::getInstance(); if (pMidiControl == NULL) return; qtractorMonitor *pMonitor = NULL; if (busMode & Input) pMonitor = monitor_in(); else pMonitor = monitor_out(); if (pMonitor == NULL) return; qtractorMidiControl::Controllers& controllers = (busMode & Input ? m_controllers_in : m_controllers_out); QListIterator<qtractorMidiControl::Controller *> iter(controllers); while (iter.hasNext()) { qtractorMidiControl::Controller *pController = iter.next(); qtractorMidiControlObserver *pObserver = NULL; switch (pController->index) { case 0: // 0=MonitorObserver pObserver = monitorObserver(); break; case 1: // 1=PanObserver pObserver = pMonitor->panningObserver(); break; case 2: // 2=GainObserver pObserver = pMonitor->gainObserver(); break; } if (pObserver) { pObserver->setType(pController->ctype); pObserver->setChannel(pController->channel); pObserver->setParam(pController->param); pObserver->setLogarithmic(pController->logarithmic); pObserver->setFeedback(pController->feedback); pObserver->setInvert(pController->invert); pObserver->setHook(pController->hook); pMidiControl->mapMidiObserver(pObserver); } } qDeleteAll(controllers); controllers.clear(); }
int main(int argc, char ** argv) { int rank, size, varid, numvars; int bins, step, mod; char *filename, *in_stream, *data_var_name; MPI_Comm comm = MPI_COMM_WORLD; enum ADIOS_READ_METHOD method = ADIOS_READ_METHOD_FLEXPATH; //enum ADIOS_READ_METHOD method = ADIOS_READ_METHOD_BP; ADIOS_SELECTION * global_range_select; double *data; uint64_t tstep, global_size, mysize, mystart, sz; MPI_Init (&argc, &argv); MPI_Comm_rank(comm, &rank); MPI_Comm_size(comm, &size); /* Command line parsing */ if (rank == 0 && argc < 4) { fprintf(stderr, "\nHistogram usage: <exec> input-stream-name num-bins" " arr1 [arr2] [arr3] [...]\n" "\t where arr1, arr2, arr3 ... are the names of the arrays to be analyzed.\n"); MPI_Abort(comm, -1); } MPI_Barrier(comm); in_stream = argv[1]; //Parse cmd line bins = atoi(argv[2]); numvars = argc - 3; const char *vars[numvars]; for (varid=0; varid < numvars; varid++) { vars[varid] = argv[varid + 3]; } /* Adios open and init */ adios_read_init_method (method, comm, "verbose=1"); ADIOS_FILE * f = adios_read_open (in_stream, method, comm, ADIOS_LOCKMODE_ALL, -1); step = 0; //not used now while (adios_errno != err_end_of_stream){ //resource monitor /*loop over different arrays inside stream*/ for (varid = 0; varid < numvars; varid++){ #ifdef ENABLE_MONITOR //double t1 = wfgettimeofday(); lib_mem_init(); ind_timer_start(0, "whole timestep"); #endif //Init variables.... global_size = 0; tstep = 0; mod = 0; mysize = 0; mystart = 0; adios_schedule_read (f, NULL, "ntimestep", 0, 1, &tstep); adios_perform_reads (f, 1); ADIOS_VARINFO * glob_info = adios_inq_var (f, vars[varid]); global_size = glob_info->dims[0]; //printf("[DEBUG] global_size = %" PRIu64 " ntimestep = %" PRIu64 "\n", // global_size, tstep); //printf("[HIST%d] received data for timestep %" PRIu64 " with ndim: %d and globalsize:%" // PRIu64 " \n", rank, tstep, ndim, global_size); //sleep(800); //debug //Array slice computation mod = global_size % size;//size = MPI size if (mod == 0){ mysize = global_size / size; mystart = mysize * rank; } else { mysize = global_size / (size); if (rank < mod){ mysize++; mystart = mysize * rank; } else { mystart = (mod * (mysize + 1)) + ((rank - mod) * mysize); } } #ifdef ENABLE_MONITOR nohandler_mem(rank); #endif //printf("[HISTO%d]: mysize = %" PRIu64" mystart = %" PRIu64 "\n", rank, mysize, mystart); //debug //if (step == 0) sleep(800); uint64_t starts[] = {mystart}; uint64_t counts[] = {mysize}; global_range_select = adios_selection_boundingbox (1, starts, counts); //Allocate space for arrays uint64_t msize = ((uint64_t) sizeof(double) * mysize); //printf("[DEBUG] mysize = %" PRIu64 " msize= %" PRIu64" \n", mysize, msize); //data = (double *) malloc(sizeof(double) * mysize); data = new double[mysize]; if (data == NULL){ //printf("DEBUG: malloc returned NULL, size was %d\n", msize); } else { if (rank == 0) printf("[HIST0] DEBUG: malloc successful, size was %d\n", mysize); } //memset (data, 0, sizeof(double) * mysize); //Read data adios_schedule_read (f, global_range_select, vars[varid], 0, 1, data); adios_perform_reads (f, 1); #ifdef ENABLE_MONITOR nohandler_mem(rank); #endif //printf("PERFORM_READS success of variable: %s\n", vars[varid]); /* Data check if (step == 4) { FILE *fp; char *log; asprintf(&log, "histo-input%d-%d.log", step, rank); fp = fopen(log, "w"); fprintf(fp, "timestep: %" PRIu64 " mysize: %"PRIu64 "\n", tstep, mysize); for (i=0; i<(int)mysize; i++){ fprintf(fp, "%lf\n", data[i]); } fclose(fp); sleep(800); } */ // find max and min sz = 0; sz = mysize; double min = data[0]; double max = data[0]; for (uint64_t i = 1; i < sz; ++i) { if (data[i] > max) max = data[i]; if (data[i] < min) min = data[i]; }//local max, min found. //local data should just use shared mem. double g_min, g_max; // Find the global max/min MPI_Allreduce (&min, &g_min, 1, MPI_DOUBLE, MPI_MIN, comm); MPI_Allreduce (&max, &g_max, 1, MPI_DOUBLE, MPI_MAX, comm); //printf("[HIST%d] glob-min: %f, glob-max: %f\n", rank, g_min, g_max); nohandler_mem(rank); double width = (g_max - g_min)/bins; std::vector<uint64_t> hist(bins); for (uint64_t i = 0; i < sz; ++i)//fill local bins { //printf("[HISTO%d] local filling adding index %" PRIu64 "\n", rank, i); int idx = int((data[i] - g_min)/width);//discover index if (idx == bins) // we hit the max --idx; //printf("[%d]: %f -> %d\n", rank, data[i], idx); ++hist[idx]; } delete[] data; // Global reduce histograms std::vector<uint64_t> g_hist(bins); MPI_Reduce(&hist[0], &g_hist[0], bins, MPI_UINT64_T, MPI_SUM, 0, comm); //debug //printf("[Completed histogram routine]\n"); if (rank == 0) //print histogram to file { FILE *fp; const char *log = "histograms.log"; fp = fopen(log, "a"); fprintf(fp, "Histogram for %s, timestep %" PRIu64"\n", vars[varid], tstep); for (int i = 0; i < bins; ++i) fprintf(fp, " %f-%f: %" PRIu64 "\n", g_min + i*width, g_min + (i+1)*width, g_hist[i]); fclose (fp); } #ifdef ENABLE_MONITOR nohandler_mem(rank); #endif if (rank == 0) //print histogram to terminal { printf("Histogram for %s, timestep %" PRIu64"\n", vars[varid], tstep); for (int i = 0; i < bins; ++i) printf(" %f-%f: %" PRIu64 "\n", g_min + i*width, g_min + (i+1)*width, g_hist[i]); } //resource monitor #ifdef ENABLE_MONITOR //double t2 = wfgettimeofday(); ind_timer_end(0); char monitor_title[40]; sprintf(monitor_title, "histogram-%s", vars[varid]); monitor_out (rank, size, tstep, msize, t1, t2, comm, monitor_title); #endif } //end of read + analysis for 3 variables adios_release_step(f); //delete[] data; if (rank == 0) printf("[HIST%d] read and wrote data for timestep %" PRIu64 "\n", rank, tstep); step++; adios_advance_step(f, 0, -1); /* if (step == 6){ double t1 = wfgettimeofday(); FILE *tfp; tfp = fopen("time.log", "a"); fprintf(tfp, "rank %d histogram end time: %f\n", rank, t1); fclose(tfp); } */ }//end of adios stream while loop if (rank == 0) printf("[HIST%d] out of read loop\n", rank); /* performance measurement */ /* if (rank == 0){ double t3 = wfgettimeofday(); FILE *tfp; tfp = fopen("time.log", "a"); fprintf(tfp, "master histogram end time: %f\n", t3); fclose(tfp); } */ #ifdef ENABLE_MONITOR outer_timer_end(rank, "histogram"); #endif adios_read_close(f); adios_read_finalize_method(method); MPI_Finalize(); return 0; }
// Save bus automation curves (monitor, gain, pan). void qtractorBus::saveCurveFile ( qtractorDocument *pDocument, QDomElement *pElement, BusMode busMode, qtractorCurveFile *pCurveFile ) const { if (m_pMonitorSubject == NULL) return; if (pCurveFile == NULL) return; qtractorCurveList *pCurveList = pCurveFile->list(); if (pCurveList == NULL) return; qtractorSession *pSession = m_pEngine->session(); if (pSession == NULL) return; qtractorMainForm *pMainForm = qtractorMainForm::getInstance(); if (pMainForm == NULL) return; QString sBusName(busName()); qtractorMonitor *pMonitor = NULL; if (busMode & Input) { pMonitor = monitor_in(); sBusName += "_in"; } else { pMonitor = monitor_out(); sBusName += "_out"; } if (pMonitor == NULL) return; pCurveFile->clear(); pCurveFile->setBaseDir(pSession->sessionDir()); qtractorCurve *pCurve; if (busMode & Input) { // It suffices for Duplex... pCurve = monitorSubject()->curve(); if (pCurve) { qtractorCurveFile::Item *pCurveItem = new qtractorCurveFile::Item; pCurveItem->name = pCurve->subject()->name(); pCurveItem->index = 0; // 0=MonitorSubject pCurveItem->ctype = qtractorMidiEvent::CONTROLLER; pCurveItem->channel = 0; pCurveItem->param = 80; // 80=General Purpose Button 1 (on/off) pCurveItem->mode = pCurve->mode(); pCurveItem->process = pCurve->isProcess(); pCurveItem->capture = pCurve->isCapture(); pCurveItem->locked = pCurve->isLocked(); pCurveItem->logarithmic = pCurve->isLogarithmic(); pCurveItem->color = pCurve->color(); pCurveItem->subject = pCurve->subject(); pCurveFile->addItem(pCurveItem); }} pCurve = pMonitor->panningSubject()->curve(); if (pCurve) { qtractorCurveFile::Item *pCurveItem = new qtractorCurveFile::Item; pCurveItem->name = pCurve->subject()->name(); pCurveItem->index = 1; // 1=PanningSubject pCurveItem->ctype = qtractorMidiEvent::CONTROLLER; pCurveItem->channel = 0; pCurveItem->param = 10; // 10=Pan Position (coarse) pCurveItem->mode = pCurve->mode(); pCurveItem->process = pCurve->isProcess(); pCurveItem->capture = pCurve->isCapture(); pCurveItem->locked = pCurve->isLocked(); pCurveItem->logarithmic = pCurve->isLogarithmic(); pCurveItem->color = pCurve->color(); pCurveItem->subject = pCurve->subject(); pCurveFile->addItem(pCurveItem); } pCurve = pMonitor->gainSubject()->curve(); if (pCurve) { qtractorCurveFile::Item *pCurveItem = new qtractorCurveFile::Item; pCurveItem->name = pCurve->subject()->name(); pCurveItem->index = 2; // 2=GainSubject pCurveItem->ctype = qtractorMidiEvent::CONTROLLER; pCurveItem->channel = 0; pCurveItem->param = 7; // 7=Volume (coarse) pCurveItem->mode = pCurve->mode(); pCurveItem->process = pCurve->isProcess(); pCurveItem->capture = pCurve->isCapture(); pCurveItem->logarithmic = pCurve->isLogarithmic(); pCurveItem->locked = pCurve->isLocked(); pCurveItem->color = pCurve->color(); pCurveItem->subject = pCurve->subject(); pCurveFile->addItem(pCurveItem); } if (pCurveFile->isEmpty()) return; const QString sBaseName(sBusName + "_curve"); const int iClipNo = (pCurveFile->filename().isEmpty() ? 0 : 1); pCurveFile->setFilename(pSession->createFilePath(sBaseName, "mid", iClipNo)); pCurveFile->save(pDocument, pElement, pSession->timeScale()); }
// Save bus (monitor, gain, pan) controllers (MIDI). void qtractorBus::saveControllers ( qtractorDocument *pDocument, QDomElement *pElement, BusMode busMode ) const { if (m_pMonitorObserver == NULL) return; qtractorMidiControl *pMidiControl = qtractorMidiControl::getInstance(); if (pMidiControl == NULL) return; qtractorMainForm *pMainForm = qtractorMainForm::getInstance(); if (pMainForm == NULL) return; qtractorMixer *pMixer = pMainForm->mixer(); if (pMixer == NULL) return; qtractorMonitor *pMonitor = NULL; qtractorMixerRack *pMixerRack = NULL; if (busMode & Input) { pMonitor = monitor_in(); pMixerRack = pMixer->inputRack(); } else { pMonitor = monitor_out(); pMixerRack = pMixer->outputRack(); } qtractorMixerStrip *pMixerStrip = pMixerRack->findStrip(pMonitor); if (pMixerStrip == NULL) return; qtractorMidiControl::Controllers controllers; if (busMode & Input) // It suffices for Duplex... if (pMidiControl->isMidiObserverMapped(m_pMonitorObserver)) { qtractorMidiControl::Controller *pController = new qtractorMidiControl::Controller; pController->name = m_pMonitorObserver->subject()->name(); pController->index = 0; // 0=MonitorObserver pController->ctype = m_pMonitorObserver->type(); pController->channel = m_pMonitorObserver->channel(); pController->param = m_pMonitorObserver->param(); pController->logarithmic = m_pMonitorObserver->isLogarithmic(); pController->feedback = m_pMonitorObserver->isFeedback(); pController->invert = m_pMonitorObserver->isInvert(); pController->hook = m_pMonitorObserver->isHook(); pController->latch = m_pMonitorObserver->isLatch(); controllers.append(pController); } qtractorMidiControlObserver *pPanObserver = pMixerStrip->meter()->panningObserver(); if (pMidiControl->isMidiObserverMapped(pPanObserver)) { qtractorMidiControl::Controller *pController = new qtractorMidiControl::Controller; pController->name = pPanObserver->subject()->name(); pController->index = 1; // 1=PanObserver pController->ctype = pPanObserver->type(); pController->channel = pPanObserver->channel(); pController->param = pPanObserver->param(); pController->logarithmic = pPanObserver->isLogarithmic(); pController->feedback = pPanObserver->isFeedback(); pController->invert = pPanObserver->isInvert(); pController->hook = pPanObserver->isHook(); pController->latch = pPanObserver->isLatch(); controllers.append(pController); } qtractorMidiControlObserver *pGainObserver = pMixerStrip->meter()->gainObserver(); if (pMidiControl->isMidiObserverMapped(pGainObserver)) { qtractorMidiControl::Controller *pController = new qtractorMidiControl::Controller; pController->name = pGainObserver->subject()->name(); pController->index = 2; // 2=GainObserver pController->ctype = pGainObserver->type(); pController->channel = pGainObserver->channel(); pController->param = pGainObserver->param(); pController->logarithmic = pGainObserver->isLogarithmic(); pController->feedback = pGainObserver->isFeedback(); pController->invert = pGainObserver->isInvert(); pController->hook = pGainObserver->isHook(); pController->latch = pGainObserver->isLatch(); controllers.append(pController); } qtractorMidiControl::saveControllers(pDocument, pElement, controllers); qDeleteAll(controllers); controllers.clear(); }