Esempio n. 1
0
void TuneTest::testConstructor()
{
    InstrumentPtr instrument = m_tune->instrument();
    QVERIFY2(instrument != 0, "Failed default tune has no instrument");

    // Tune with default instrument
    QVERIFY2(instrument->name() == NullInstrument().name(), "Failed to set Instrument in default constructor");

    delete m_tune;
    m_tune = new Tune(m_instrument);
    QVERIFY2(m_tune->instrument()->name() == m_instrument->name(), "Failed to set Instrument in constructor");
    QVERIFY2(m_tune->type() == MusicItem::TuneType, "Tune returns the wrong type");
}
Esempio n. 2
0
 MxScorePartParameters::MxScorePartParameters( const InstrumentPtr& instrument )
 :PartID( instrument->getID() )
 ,PartName( instrument->getName() )
 ,PartNameDisplay( "" )
 ,PartAbbreviation( instrument->getAbbreviation() )
 ,PartAbbreviationDisplay( "" )
 ,PartGroupingString( "" )
 ,ScoreInstrumentID( instrument->getID()+"_INSTR" )
 ,InstrumentName( instrument->getName() )
 ,InstrumentAbbreviation( instrument->getAbbreviation() )
 ,InstrumentSound( "" )
 ,SoloOrEnsemble( MxScorePartSoloOrEnsemble::NotSpecified )
 ,MidiDevice( "" )
 ,MidiID( instrument->getID()+"_INSTR" )
 ,MidiPort( -1 )
 ,MidiBank( -1 )
 ,MidiChannel( -1 ) /* The midi-channel element specifies a MIDI 1.0 channel numbers ranging from 1 to 16. */
 ,MidiProgram( -1 )
 ,MidiName( "" )
 ,MidiUnpitched( -1 )
 ,MidiVolume( -1 )
 ,MidiPan( -999 )
 ,MidiElevation( -999 )
 ,VirtualInstrumentLibrary( "" )
 ,VirtualInstrumentName( "" )
 {}
void VisualMusicModelTest::testInsertPart()
{
    Q_ASSERT(m_pluginManager->instrumentNames().count());
    QString testInstrumentName(m_pluginManager->instrumentNames().at(0));

    bool partRepeatData = true;

    QModelIndex scoreIndex = m_musicModel->insertScore(0, "Test score");
    QModelIndex tuneIndex  = m_musicModel->insertTuneIntoScore(0, scoreIndex, testInstrumentName);

    InstrumentPtr instrument = m_musicModel->data(tuneIndex, LP::TuneInstrument).value<InstrumentPtr>();
    Q_ASSERT(instrument->type() != LP::NoInstrument);

    QSignalSpy rowSequenceSpy(m_visualMusicModel, SIGNAL(scoreRowSequenceChanged(int)));
    QModelIndex partIndex = m_musicModel->insertPartIntoTune(0, tuneIndex, 0, partRepeatData);
    QVERIFY2(rowSequenceSpy.count() == 1,
             "Row sequence changed wasn't emitted after inserting part");
    rowSequenceSpy.clear();

    QVERIFY2(m_visualMusicModel->visualItemFromIndex(tuneIndex) != 0,
             "No visual item was inserted");

    VisualItem *partItem = m_visualMusicModel->visualItemFromIndex(partIndex);
    QVERIFY2(partItem->parent() == m_visualMusicModel,
             "Tune item has not visual music model as parent");

    TestVisualItem *testItem = static_cast<TestVisualItem*>(partItem);
    QVERIFY2(testItem, "Can't get testitem from item");

    QVERIFY2(testItem->hasData(LP::PartStaffType),
             "Staff type wasn't set in VisualItem");
    QVERIFY2(testItem->data(LP::PartStaffType).value<StaffType>() == instrument->staffType(),
             "VisualItem has wrong staff type");
    QVERIFY2(testItem->hasData(LP::PartRepeat),
             "Repeat data wasn't set");
    QVERIFY2(testItem->data(LP::PartRepeat).toBool() == partRepeatData,
             "Repeat wasn't set in new VisualPart");

    // Test row sequence change signal
    testItem->emitRowSequenceChanged();
    QVERIFY2(rowSequenceSpy.count() == 1, "Score row sequence changed signal wasn't emitted");
}
int	main(int argc, char *argv[]) {
	debugthreads = 1;
	Exposure	exposure;
	unsigned int	nImages = 1;
	std::string	reponame;
	std::string	filtername;
	int	c;
	int	longindex;
	double	temperature = std::numeric_limits<double>::quiet_NaN();
	while (EOF != (c = getopt_long(argc, argv, "b:c:de:f:hn:p:r:t:?",
		longopts, &longindex)))
		switch (c) {
		case 'b':
			exposure.mode(Binning(optarg));
			break;
		case 'c':
			Configuration::set_default(optarg);
			break;
		case 'd':
			debuglevel = LOG_DEBUG;
			break;
		case 'e':
			exposure.exposuretime(atof(optarg));
			break;
		case 'f':
			filtername = std::string(optarg);
			break;
		case 'h':
		case '?':
			usage(argv[0]);
			return EXIT_SUCCESS;
		case 'n':
			nImages = atoi(optarg);
			break;
		case 'p':
			exposure.purpose(Exposure::string2purpose(optarg));
			break;
		case 'r':
			reponame = std::string(optarg);
			break;
		case 't':
			temperature = atof(optarg);
			break;
		case 1:
			exposure.frame(ImageRectangle(optarg));
			break;
		default:
			throw std::runtime_error("unknown option");
		}

	// next argument must be instrument name or help
	if (optind >= argc) {
		std::cerr << "missing instrument name" << std::endl;
		return EXIT_FAILURE;
	}
	std::string	instrumentname(argv[optind++]);

	// get the configuration
	ConfigurationPtr	config = Configuration::get();

	// backend for instruments
	InstrumentBackend	instrumentbackend(config->database());
        InstrumentPtr   instrument = instrumentbackend.get(instrumentname);

	// get the image repository
	ImageRepoPtr	repo(NULL);
	if (reponame.size() > 0) {
		ImageRepoConfigurationPtr	imagerepos
			= ImageRepoConfiguration::get(config);
		repo = imagerepos->repo(reponame);
	}

	// prepare a repository from which we can extract the devices
	Repository	repository;
	Devices		devices(repository);

	// get the devices
	CameraPtr	camera = devices.getCamera(instrument->getCamera(0).deviceurl());
	CcdPtr		ccd = devices.getCcd(instrument->getCcd(0).deviceurl());

	// If temperature is set, and a cooler is present, initialize the
	// cooler and wait until temperature is reached
	CoolerPtr	cooler(NULL);
	if ((temperature == temperature)
		&& (instrument->hasCooler())) {
		double	absolute = 273.15 + temperature;
		if (absolute < 0) {
			std::string	msg
				= stringprintf("illegal temperature: %f",
					temperature);
			debug(LOG_ERR, DEBUG_LOG, 0, "%s", msg.c_str());
			throw std::runtime_error(msg);
		}
		cooler = devices.getCooler(instrument->getCooler(0).deviceurl());
		cooler->setTemperature(absolute);
		cooler->setOn(true);

		double	delta;
		do {
			double	actual = cooler->getActualTemperature();
			delta = fabs(absolute - actual);
			debug(LOG_DEBUG, DEBUG_LOG, 0,
				"set: %.1f, actual: %.1f, delta: %.1f",
				absolute, actual, delta);
		} while (delta > 1);
	}

	// if the instrument has a filter wheel, we get a pointer to it
	// and try 
	FilterWheelPtr	filterwheel(NULL);
	if (instrument->hasFilterWheel()) {
		filterwheel = devices.getFilterWheel(
			instrument->getFilterWheel(0).deviceurl());
		filterwheel->wait(20);
		if (filtername.size() > 0) {
			filterwheel->select(filtername);
			filterwheel->wait(20);
		}
	}

	// start the stream
	unsigned int	imagesRetrieved = 0;
	ccd->startStream(exposure);
	while (imagesRetrieved < nImages) {
		ImagePtr	image = ccd->getEntry(true).image;
		debug(LOG_DEBUG, DEBUG_LOG, 0, "got image[%u] %s",
			++imagesRetrieved,
			image->size().toString().c_str());
		if (!image->hasMetadata(std::string("INSTRUME"))) {
			image->setMetadata(FITSKeywords::meta(
				std::string("INSTRUME"), instrument->name()));
		}
		// do something about the image
		if (repo) {
			repo->save(image);
		}
	}
	// stop the stream
	ccd->stopStream();

	// find out how many images were dropped
	if (ccd->dropped() > 0) {
		std::cerr << "images dropped: " << ccd->dropped() << std::endl;
	}

	// turn off the cooler
	if (cooler) {
		cooler->setOn(false);
	}
	
	return EXIT_SUCCESS;
}
void	InstrumentTest::testRead() {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testRead() begin");
	ConfigurationPtr	config = Configuration::get(dbfilename);
	InstrumentConfigurationPtr	instrumentconfig
		= InstrumentConfiguration::get(config);
	InstrumentPtr	instrument = instrumentconfig->instrument("BLUBB");

	// check instrument
	CPPUNIT_ASSERT(instrument->name() == "BLUBB");

	// has method
	debug(LOG_DEBUG, DEBUG_LOG, 0, "test 'has' method");
	CPPUNIT_ASSERT(instrument->has(DeviceName::Camera));
	CPPUNIT_ASSERT(instrument->has(DeviceName::Ccd));

	// component_type method
	debug(LOG_DEBUG, DEBUG_LOG, 0, "test 'component_type' method");
	CPPUNIT_ASSERT(instrument->component_type(DeviceName::Camera)
		== InstrumentComponent::direct);
	CPPUNIT_ASSERT(instrument->component_type(DeviceName::Ccd)
		== InstrumentComponent::derived);
	CPPUNIT_ASSERT(instrument->component_type(DeviceName::Filterwheel)
		== InstrumentComponent::mapped);

	// devicename method
	debug(LOG_DEBUG, DEBUG_LOG, 0, "test 'devicename' method");
	CPPUNIT_ASSERT(instrument->devicename(DeviceName::Camera)
		== DeviceName("camera:simulator/camera"));
	debug(LOG_DEBUG, DEBUG_LOG, 0, "ccd device: %s",
		instrument->devicename(DeviceName::Ccd).toString().c_str());
	CPPUNIT_ASSERT(instrument->devicename(DeviceName::Ccd)
		== DeviceName("camera:simulator/camera"));
	CPPUNIT_ASSERT(instrument->devicename(DeviceName::Filterwheel).toString()
		== "filterwheel:sx/0");

	// name method
	debug(LOG_DEBUG, DEBUG_LOG, 0, "test 'name' method");
	debug(LOG_DEBUG, DEBUG_LOG, 0, "name(camera) = %s",
		instrument->name(DeviceName::Camera).c_str());
	CPPUNIT_ASSERT(instrument->name(DeviceName::Camera)
		== DeviceName("camera:simulator/camera").toString());

	debug(LOG_DEBUG, DEBUG_LOG, 0, "name(ccd) = %s",
		instrument->name(DeviceName::Ccd).c_str());
	CPPUNIT_ASSERT(instrument->name(DeviceName::Ccd) == "camera");
	CPPUNIT_ASSERT(instrument->name(DeviceName::Filterwheel)
		== "TEST");

	// unit method
	debug(LOG_DEBUG, DEBUG_LOG, 0, "test 'unit' method");
	CPPUNIT_ASSERT(instrument->unit(DeviceName::Camera) == 7);
	CPPUNIT_ASSERT(instrument->unit(DeviceName::Ccd) == 5);
	CPPUNIT_ASSERT(instrument->unit(DeviceName::Filterwheel) == 1291);
	
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testRead() end");
}