コード例 #1
0
/** Create an EventWorkspace containing fake data
 * of single-crystal diffraction.
 * Instrument is MINITOPAZ
 *
 * @return EventWorkspace_sptr
 */
EventWorkspace_sptr
createDiffractionEventWorkspace(int numEvents, int numPixels, int numBins) {
  double binDelta = 10.0;

  auto retVal = boost::make_shared<EventWorkspace>();
  retVal->initialize(numPixels, 1, 1);

  // --------- Load the instrument -----------
  const std::string filename = FileFinder::Instance().getFullPath(
      "IDFs_for_UNIT_TESTING/MINITOPAZ_Definition.xml");
  InstrumentDefinitionParser parser(filename, "MINITOPAZ",
                                    Strings::loadFile(filename));
  auto instrument = parser.parseXML(nullptr);
  retVal->populateInstrumentParameters();
  retVal->setInstrument(instrument);

  DateAndTime run_start("2010-01-01T00:00:00");

  for (int pix = 0; pix < numPixels; pix++) {
    for (int i = 0; i < numEvents; i++) {
      retVal->getSpectrum(pix) += Mantid::DataObjects::TofEvent(
          (i + 0.5) * binDelta, run_start + double(i));
    }
    retVal->getSpectrum(pix).addDetectorID(pix);
  }

  // Create the x-axis for histogramming.
  HistogramData::BinEdges x1(numBins);
  auto &xRef = x1.mutableData();
  for (int i = 0; i < numBins; ++i) {
    xRef[i] = i * binDelta;
  }

  // Set all the histograms at once.
  retVal->setAllX(x1);
  // Default unit: TOF.
  retVal->getAxis(0)->setUnit("TOF");

  // Give it a crystal and goniometer
  WorkspaceCreationHelper::setGoniometer(retVal, 0., 0., 0.);
  WorkspaceCreationHelper::setOrientedLattice(retVal, 1., 1., 1.);

  // Some sanity checks
  if (retVal->getInstrument()->getName() != "MINITOPAZ")
    throw std::runtime_error("MDEventsTestHelper::"
                             "createDiffractionEventWorkspace(): Wrong "
                             "instrument loaded.");
  Mantid::detid2det_map dets;
  retVal->getInstrument()->getDetectors(dets);
  if (dets.size() != 100 * 100)
    throw std::runtime_error("MDEventsTestHelper::"
                             "createDiffractionEventWorkspace(): Wrong "
                             "instrument size.");

  return retVal;
}
コード例 #2
0
 void HistoricalReplay::getPositionPnl(const std::string & symbol, numeric price, numeric & realized, numeric & unrealized)
 {
    const Instrument * instrument = getInstrument(symbol);
    // The caller must ensure that there is a position
    poco_check_ptr(instrument);
    portfolio_.getPositionPnl(*instrument, price, realized, unrealized);
 }
void EntertainingSessionImplementation::startPlayingMusic(const String& song, const String& instrumentAnimation, int instrid) {
	ManagedReference<CreatureObject*> entertainer = this->entertainer.get();

	Locker locker(entertainer);

	ManagedReference<GroupObject*> group = entertainer->getGroup();

	if (group != NULL) {
		if (group->getBandSong() != song) {

			Locker clocker(group, entertainer);

			group->setBandSong(song);
		}
	}

	sendEntertainingUpdate(entertainer, 0.0125, instrumentAnimation, 0x07352BAC, instrid);
	performanceName = song;
	playingMusic = true;

	entertainer->sendSystemMessage("@performance:music_start_self");

	entertainer->setListenToID(entertainer->getObjectID(), true);

	externalInstrument = getInstrument(entertainer);

	if (externalInstrument != NULL)
		externalInstrument->setBeingUsed(true);

	updateEntertainerMissionStatus(true, MissionObject::MUSICIAN);

	entertainer->notifyObservers(ObserverEventType::STARTENTERTAIN, entertainer);

	startEntertaining();
}
コード例 #4
0
Vector<Performance*> PerformanceManager::getPerformanceListFromMod(
		const String& requiredSkillMod, int playerSkillModValue, int instrument) {
	String instrumentName = "";
	if (instrument != 0)
		instrumentName = getInstrument(instrument);

	Vector<Performance*> performanceList;

	if (performances != NULL) {

		for (int i = 0; i < performances->size(); ++i) {
			Performance* perform = performances->get(i);
			if (perform->getRequiredSkillMod() == requiredSkillMod
					&& perform->getRequiredSkillModValue()
							<= playerSkillModValue) {
				if (instrumentName != "") {
					//Should be a music call, look only for performances with that instrument
					if (instrumentName == perform->getRequiredInstrument())
						performanceList.add(perform);
				} else {
					//Should be a dance call
					performanceList.add(perform);
				}
			}
		}

	}

	return performanceList;
}
コード例 #5
0
ファイル: notevisitor.cpp プロジェクト: 02191998/libmusicxml
//________________________________________________________________________
void notevisitor::print (ostream& out) const
{
		if (isGrace()) out << "grace ";
		if (isCue())   out << "cue ";
		int type = getType();
		if (type == kUndefinedType)
			out << "type undefined";
		else if (type == kUnpitched) {
			out << "unpitched note - duration " << getDuration() << " ";
		}
		else if (type == kRest) {
			out << "rest - duration " << getDuration() << " ";
		}
		else if (type == kPitched) {
			out << "note " << getStep();
			int alter = int(getAlter());
			float diff = getAlter() - alter;
			if (diff >= 0.5) alter++; 
			else if (diff <= -0.5) alter--; 
			while (alter < 0) { out << 'b'; alter++; }
			while (alter > 0) { out << '#'; alter--; }
			out << getOctave() << " (" << getMidiPitch() << ")";
			out << " - duration " << getDuration() << " ";
		}
		else out << "unknown type " <<  type << " ";
		if (inChord())	out << "in chord ";
		if (getTie() & StartStop::start)	out << "- tie start ";
		if (getTie() & StartStop::stop)	out << "- tie stop ";
		string instr = getInstrument();
		if (!instr.empty()) out << "instrument " << instr << " ";
		if (getDynamics() >= 0) out << "dynamics " << getDynamics();
}
コード例 #6
0
void DecoratorWorkspace::setNPeriods(size_t nPeriods, std::unique_ptr<const TimeSeriesProperty<int> >& periodLog) {

  // Create vector where size is the number of periods and initialize workspaces in each.
  auto temp = m_WsVec[0];
  m_WsVec = std::vector<DataObjects::EventWorkspace_sptr>(
      nPeriods);

  std::vector<int> periodNumbers = periodLog->valuesAsVector();
  std::set<int> uniquePeriods(periodNumbers.begin(), periodNumbers.end());
  const bool addBoolTimeSeries = (uniquePeriods.size() == nPeriods);

  for (size_t i = 0; i < m_WsVec.size(); ++i) {
    const int periodNumber = int(i+1);
    m_WsVec[i] =  createEmptyEventWorkspace();
    m_WsVec[i]->copyExperimentInfoFrom(temp.get());
    if(addBoolTimeSeries) {
        std::stringstream buffer;
        buffer << "period " << periodNumber;
        auto * periodBoolLog = new Kernel::TimeSeriesProperty<bool>(buffer.str());
        for(int j = 0; j < int(periodLog->size()); ++j){
            periodBoolLog->addValue(periodLog->nthTime(j), periodNumber == periodLog->nthValue(j));
        }
        Run& mutableRun =  m_WsVec[i]->mutableRun();
        mutableRun.addProperty(periodBoolLog);


        Kernel::PropertyWithValue<int> *currentPeriodProperty =
            new Kernel::PropertyWithValue<int>("current_period", periodNumber);
        mutableRun.addProperty(currentPeriodProperty);
    }

    copyLogs(temp, m_WsVec[i]); // Copy all logs from dummy workspace to period workspaces.
    m_WsVec[i]->setInstrument(temp->getInstrument());
  }
}
コード例 #7
0
/**
 * Get instrument name from a workspace
 * @param workspace :: [input] Workspace to get instrument name from
 * @returns :: name of instrument (empty if failed to get it)
 */
std::string MuonAnalysisDataLoader::getInstrumentName(
    const Workspace_sptr workspace) const {
  if (workspace) {
    const auto period = MuonAnalysisHelper::firstPeriod(workspace);
    if (period) {
      const auto instrument = period->getInstrument();
      if (instrument) {
        return instrument->getName();
      }
    }
  }
  return "";
}
コード例 #8
0
void EntertainingSessionImplementation::doPerformanceAction() {
	ManagedReference<CreatureObject*> entertainer = this->entertainer.get();

	if (entertainer == NULL)
		return;

	Locker locker(entertainer);

	Performance* performance = NULL;

	PerformanceManager* performanceManager = SkillManager::instance()->getPerformanceManager();
	ManagedReference<Instrument*> instrument = getInstrument(entertainer);

	if (isDancing())
		performance = performanceManager->getDance(performanceName);
	else if (isPlayingMusic() && instrument)
		performance = performanceManager->getSong(performanceName, instrument->getInstrumentType());
	else {
		cancelSession();
		return;
	}

	if (performance == NULL) { // shouldn't happen
		StringBuffer msg;
		msg << "Performance was null.  Please report to www.swgemu.com/bugs ! Name: " << performanceName << " and Type: " << dec << instrument->getInstrumentType();

		entertainer->sendSystemMessage(msg.toString());
		return;
	}

	int actionDrain = performance->getActionPointsPerLoop();

	//Adjust cost based upon player's quickness
	actionDrain = entertainer->calculateCostAdjustment(CreatureAttribute::QUICKNESS, actionDrain);

	if (entertainer->getHAM(CreatureAttribute::ACTION) <= actionDrain) {
		if (isDancing()) {
			stopDancing();
			entertainer->sendSystemMessage("@performance:dance_too_tired");
		}

		if (isPlayingMusic()) {
			stopPlayingMusic();
			entertainer->sendSystemMessage("@performance:music_too_tired");
		}
	} else {
		entertainer->inflictDamage(entertainer, CreatureAttribute::ACTION, actionDrain, false, true);
	}
}
void EntertainingSessionImplementation::increaseEntertainerBuff(CreatureObject* patron){
	ManagedReference<CreatureObject*> entertainer = this->entertainer.get();

	PerformanceManager* performanceManager = SkillManager::instance()->getPerformanceManager();
	Performance* performance = NULL;

	ManagedReference<Instrument*> instrument = getInstrument(entertainer);

	if (performanceName == "")
		return;

	if (dancing) {
		performance = performanceManager->getDance(performanceName);
	} else if (playingMusic && instrument != NULL) {
		performance = performanceManager->getSong(performanceName, instrument->getInstrumentType());
	} else {
		cancelSession();
		return;
	}

	if(!canGiveEntertainBuff())
		return;

	if (performance == NULL) { // shouldn't happen
		return;
	}

	ManagedReference<PlayerObject*> entPlayer = entertainer->getPlayerObject();
	//Check if the patron is a valid buff target
	//Whether it be passive(in the same group) or active (/setPerform target)
	if ((!entertainer->isGrouped() || entertainer->getGroupID() != patron->getGroupID())
			&& entPlayer->getPerformanceBuffTarget() != patron->getObjectID()) {
		return;
	}

	if(isInDenyServiceList(patron))
		return;

	float buffAcceleration = 1 + ((float)entertainer->getSkillMod("accelerate_entertainer_buff") / 100.f);

	addEntertainerBuffDuration(patron, performance->getType(), 2.0f * buffAcceleration);
	addEntertainerBuffStrength(patron, performance->getType(), performance->getHealShockWound());

}
void EntertainingSessionImplementation::doFlourish(int flourishNumber) {
	ManagedReference<CreatureObject*> entertainer = this->entertainer.get();

	int fid = flourishNumber;

	if (!dancing && !playingMusic) {
		entertainer->sendSystemMessage("@performance:flourish_not_performing");
		return;
	}

	PerformanceManager* performanceManager = SkillManager::instance()->getPerformanceManager();
	Performance* performance = NULL;
	ManagedReference<Instrument*> instrument = getInstrument(entertainer);

	if (dancing)
		performance = performanceManager->getDance(performanceName);
	else if (playingMusic && instrument)
		performance = performanceManager->getSong(performanceName, instrument->getInstrumentType());
	else {
		cancelSession();
		return;
	}

	if (!performance) { // shouldn't happen
		StringBuffer msg;
		msg << "Performance was null.  Please report to www.swgemu.com/bugs ! Name: " << performanceName << " and Type: " << dec << instrument->getInstrumentType();

		entertainer->sendSystemMessage(msg.toString());
		return;
	}

	float baseActionDrain = performance->getActionPointsPerLoop() - (int)(entertainer->getHAM(CreatureAttribute::QUICKNESS)/35.f);

	//float baseActionDrain = -40 + (getQuickness() / 37.5);
	float flourishActionDrain = baseActionDrain / 2.0;

	int actionDrain = (int)round((flourishActionDrain * 10 + 0.5) / 10.0); // Round to nearest dec for actual int cost

	if (entertainer->getHAM(CreatureAttribute::ACTION) <= actionDrain) {
		entertainer->sendSystemMessage("@performance:flourish_too_tired");
	} else {
		entertainer->inflictDamage(entertainer, CreatureAttribute::ACTION, actionDrain, false, true);

		if (dancing) {
			StringBuffer msg;
			msg << "skill_action_" << fid;
			entertainer->doAnimation(msg.toString());
		} else if (playingMusic) {
			Flourish* flourish = new Flourish(entertainer, fid);
			entertainer->broadcastMessage(flourish, true);
		}

		//check to see how many flourishes have occurred this tick
		if(flourishCount < 5) {
			// Add buff
			addEntertainerFlourishBuff();

			// Grant Experience
			if(flourishCount < 2)
				flourishXp += performance->getBaseXp() + performance->getFlourishXpMod();

			flourishCount++;
		}
		entertainer->notifyObservers(ObserverEventType::FLOURISH, entertainer, fid);

		entertainer->sendSystemMessage("@performance:flourish_perform");
	}
}
void EntertainingSessionImplementation::doEntertainerPatronEffects() {
	ManagedReference<CreatureObject*> creo = entertainer.get();

	if (creo == NULL)
		return;

	if (performanceName == "")
		return;

	Locker locker(creo);

	//**DECLARATIONS**
	VectorMap<ManagedReference<CreatureObject*>, EntertainingData>* patrons = NULL;

	SkillManager* skillManager = creo->getZoneServer()->getSkillManager();

	PerformanceManager* performanceManager = skillManager->getPerformanceManager();
	Performance* performance = NULL;

	ManagedReference<Instrument*> instrument = getInstrument(creo);

	float woundHealingSkill = 0.0f;
	float playerShockHealingSkill = 0.0f;
	float buildingShockHealingSkill = creo->getSkillMod("private_med_battle_fatigue");
	float factionPerkSkill = creo->getSkillMod("private_faction_mind_heal");

	//**LOAD PATRONS, GET THE PERFORMANCE AND ENT'S HEALING SKILL.**
	if (dancing) {
		patrons = &watchers;
		performance = performanceManager->getDance(performanceName);
		woundHealingSkill = (float) creo->getSkillMod("healing_dance_wound");
		playerShockHealingSkill = (float) creo->getSkillMod("healing_dance_shock");
	} else if (playingMusic && instrument != NULL) {
		patrons = &listeners;
		performance = performanceManager->getSong(performanceName, instrument->getInstrumentType());
		woundHealingSkill = (float) creo->getSkillMod("healing_music_wound");
		playerShockHealingSkill = (float) creo->getSkillMod("healing_music_shock");

	} else {
		cancelSession();
		return;
	}

	if (performance == NULL) {
		return;
	}

	ManagedReference<BuildingObject*> building = creo->getRootParent().get().castTo<BuildingObject*>();

	if (building != NULL && factionPerkSkill > 0 && building->isPlayerRegisteredWithin(creo->getObjectID())) {
		unsigned int buildingFaction = building->getFaction();
		unsigned int healerFaction = creo->getFaction();
		PlayerObject* ghost = creo->getPlayerObject();

		if (ghost != NULL && healerFaction != 0 && healerFaction == buildingFaction && ghost->getFactionStatus() == FactionStatus::OVERT) {
			woundHealingSkill += factionPerkSkill;
			playerShockHealingSkill += factionPerkSkill;
		}
	}

	//**DETERMINE WOUND HEAL AMOUNTS.**
	int woundHeal = ceil(performance->getHealMindWound() * (woundHealingSkill / 100.0f));
	int shockHeal = ceil(performance->getHealShockWound() * ((playerShockHealingSkill + buildingShockHealingSkill) / 100.0f));

	//**ENTERTAINER HEALS THEIR OWN MIND.**
	healWounds(creo, woundHeal*(flourishCount+1), shockHeal*(flourishCount+1));

	//**APPLY EFFECTS TO PATRONS.**
	if (patrons != NULL && patrons->size() > 0) {

		for (int i = 0; i < patrons->size(); ++i) {
			ManagedReference<CreatureObject*> patron = patrons->elementAt(i).getKey();

			try {
				//**VERIFY THE PATRON IS NOT ON THE DENY SERVICE LIST

				if (creo->isInRange(patron, 10.0f)) {
					healWounds(patron, woundHeal*(flourishCount+1), shockHeal*(flourishCount+1));
					increaseEntertainerBuff(patron);

				} else { //patron is not in range, force to stop listening
					ManagedReference<PlayerManager*> playerManager = patron->getZoneServer()->getPlayerManager();

					Locker locker(patron, entertainer.get());

					if (dancing) {
						if (playerManager != NULL)
							playerManager->stopWatch(patron, creo->getObjectID(), true, false, false, true);

						if (!patron->isListening())
							sendEntertainmentUpdate(patron, 0, "", true);

					} else if (playingMusic) {
						if (playerManager != NULL)
							playerManager->stopListen(patron, creo->getObjectID(), true, false, false, true);

						if (!patron->isWatching())
							sendEntertainmentUpdate(patron, 0, "", true);
					}
				}

			} catch (Exception& e) {
				error("Unreported exception caught in EntertainingSessionImplementation::doEntertainerPatronEffects()");
			}
		}
	} //else
	//System::out << "There are no patrons.\n";


	info("EntertainingSessionImplementation::doEntertainerPatronEffects() end");
}
コード例 #12
0
ファイル: sound_2gs.cpp プロジェクト: bluegr/scummvm
void SoundGen2GS::advanceMidiPlayer() {
	if (_disableMidi)
		return;

	const uint8 *p;
	uint8 parm1, parm2;
	static uint8 cmd, chn;

	if (_playingSound == -1 || _vm->_game.sounds[_playingSound] == NULL) {
		warning("Error playing Apple IIGS MIDI sound resource");
		_playing = false;
		return;
	}

	IIgsMidi *midiObj = (IIgsMidi *) _vm->_game.sounds[_playingSound];

	_ticks++;
	_playing = true;
	p = midiObj->getPtr();

	while (true) {
		// Check for end of MIDI sequence marker (Can also be here before delta-time)
		if (*p == MIDI_STOP_SEQUENCE) {
			debugC(3, kDebugLevelSound, "End of MIDI sequence (Before reading delta-time)");
			_playing = false;
			midiObj->rewind();
			return;
		}
		if (*p == MIDI_TIMER_SYNC) {
			debugC(3, kDebugLevelSound, "Timer sync");
			p++; // Jump over the timer sync byte as it's not needed
			continue;
		}

		// Check for delta time
		uint8 delta = *p;
		if (midiObj->_ticks + delta > _ticks)
			break;
		midiObj->_ticks += delta;
		p++;

		// Check for end of MIDI sequence marker (This time it after reading delta-time)
		if (*p == MIDI_STOP_SEQUENCE) {
			debugC(3, kDebugLevelSound, "End of MIDI sequence (After reading delta-time)");
			_playing = false;
			midiObj->rewind();
			return;
		}

		// Separate byte into command and channel if it's a command byte.
		// Otherwise use running status (i.e. previously set command and channel).
		if (*p & 0x80) {
			cmd = *p++;
			chn = cmd & 0x0f;
			cmd >>= 4;
		}

		switch (cmd) {
		case MIDI_NOTE_OFF:
			parm1 = *p++;
			parm2 = *p++;
			debugC(3, kDebugLevelSound, "channel %X: note off (key = %d, velocity = %d)", chn, parm1, parm2);
			midiNoteOff(chn, parm1, parm2);
			break;
		case MIDI_NOTE_ON:
			parm1 = *p++;
			parm2 = *p++;
			debugC(3, kDebugLevelSound, "channel %X: note on (key = %d, velocity = %d)", chn, parm1, parm2);
			midiNoteOn(chn, parm1, parm2);
			break;
		case MIDI_CONTROLLER:
			parm1 = *p++;
			parm2 = *p++;
			debugC(3, kDebugLevelSound, "channel %X: controller %02X = %02X", chn, parm1, parm2);
			// The tested Apple IIGS AGI MIDI resources only used
			// controllers 0 (Bank select?), 7 (Volume) and 64 (Sustain On/Off).
			// Controller 0's parameter was in range 94-127,
			// controller 7's parameter was in range 0-127 and
			// controller 64's parameter was always 0 (i.e. sustain off).
			switch (parm1) {
			case 7:
				_channels[chn].setVolume(parm2);
				break;
			}
			break;
		case MIDI_PROGRAM_CHANGE:
			parm1 = *p++;
			debugC(3, kDebugLevelSound, "channel %X: program change %02X", chn, parm1);
			_channels[chn].setInstrument(getInstrument(parm1));
			break;
		case MIDI_PITCH_WHEEL:
			parm1 = *p++;
			parm2 = *p++;
			debugC(3, kDebugLevelSound, "channel %X: pitch wheel (unimplemented)", chn);
			break;

		default:
			debugC(3, kDebugLevelSound, "channel %X: unimplemented command %02X", chn, cmd);
			break;
		}
	}
コード例 #13
0
PixelColor makeColor(HumdrumFile& infile, int line, int spine, int style,
      Array<int>& rhylev, int track) {
   PixelColor output;
   int trackCount;
   PerlRegularExpression pre;
   const char* instrument = "";

   PixelColor purple     (225, 121, 255);
   PixelColor yellowgreen(150, 200,   0);

   switch (toupper(style)) {
      case 'M':    // color by metric position
         if (rhylev[line] >= 2) {
            output.setColor("red");
         } else if (rhylev[line] == 1) {
            output.setColor("lightorange");
         } else if (rhylev[line] == 0) {
            output.setColor("yellow");
         } else if (rhylev[line] == -1) {
            output.setColor("green");
         } else if (rhylev[line] == -2) {
            output.setColor("blue");
         } else if (rhylev[line] <= -3) {
            output.setColor("violet");
         } else {
            output.setColor("silver");
         }
         break;

      case 'V':    // color spines by voice
         instrument = getInstrument(infile, track);
         if (pre.search(instrument, "Bassus", "i")) {
            output.setColor("red");
         } else if (pre.search(instrument, "Contra", "i")) {
            output.setColor("darkorange");
         } else if (pre.search(instrument, "Tenor", "i")) {
            output.setColor("blue");
         } else if (pre.search(instrument, "Altus", "i")) {
            output = purple;
         } else if (pre.search(instrument, "Superius", "i")) {
            output.setColor("limegreen");
         } else if (pre.search(instrument, "Cantus", "i")) {
            output.setColor("limegreen");
         } else if (pre.search(instrument, "Discantus", "i")) {
            output = yellowgreen;
         } else {
            output.setColor("black");
         }
         break;
         
      case 'H':    // color spines by hue
      default:
         trackCount = infile.getMaxTracks();
         output.setHue(((int)infile[line].getTrack(spine))/(double)trackCount);
   }

   PixelColor bcolor(bgcolor);
   double csum = (bcolor.Red + bcolor.Green + bcolor.Blue)/(255*3);
   if (csum > 0.5) {
      output.Red = output.Red / 2;
      output.Green = output.Green / 2;
      output.Blue = output.Blue / 2;
   }

   return output;
}
コード例 #14
0
ファイル: Musician.cpp プロジェクト: shukiel/CPP_FinalProject
void Musician::toOs(ostream& os) const
{
	Participator::toOs(os);
	os << "Instrument: " << getInstrument() << endl;
}