MultiKeyInsertionCommand::MultiKeyInsertionCommand(RosegardenDocument* doc,
        timeT time,
        Key key,
        bool convert,
        bool transpose,
        bool transposeKey,
	bool ignorePercussion) :
        MacroCommand(getGlobalName(&key))
{
   Composition &c = doc->getComposition();
   Studio &s = doc->getStudio();

    for (Composition::iterator i = c.begin(); i != c.end(); ++i) {
        Segment *segment = *i;

	Instrument *instrument = s.getInstrumentFor(segment);
	// if (instrument) {
	//    RG_DEBUG << endl <<
	//                "PERC DEBUG: instrument->isPercussion " << instrument->isPercussion() <<
	//                " ignorePercussion " << ignorePercussion << endl << endl << endl;
	//}
	if (instrument) if (instrument->isPercussion() && ignorePercussion) continue;

        // no harm in using getEndTime instead of getEndMarkerTime here:
        if (segment->getStartTime() <= time && segment->getEndTime() > time) {
            addCommand(new KeyInsertionCommand(*segment, time, key, convert, transpose, transposeKey,
	                                       ignorePercussion));
        } else if (segment->getStartTime() > time) {
            addCommand(new KeyInsertionCommand(*segment, segment->getStartTime(),
                                               key, convert, transpose, transposeKey, ignorePercussion));
        }
    }
}
Beispiel #2
0
void NotationPreview::createEventRects(const Segment *segment, RectList *npData)
{
    npData->clear();

    int segStartX = static_cast<int>(nearbyint(
            m_grid.getRulerScale()->getXForTime(segment->getStartTime())));

    bool isPercussion = false;
    Track *track = m_composition.getTrackById(segment->getTrack());
    if (track) {
        InstrumentId iid = track->getInstrument();
        Instrument *instrument = m_studio.getInstrumentById(iid);
        if (instrument && instrument->isPercussion()) isPercussion = true;
    }

    // For each event in the segment
    for (Segment::const_iterator i = segment->begin();
         i != segment->end(); ++i) {

        long pitch = 0;
        if (!(*i)->isa(Note::EventType) ||
            !(*i)->get<Int>(BaseProperties::PITCH, pitch)) {
            continue;
        }

        timeT eventStart = (*i)->getAbsoluteTime();
        timeT eventEnd = eventStart + (*i)->getDuration();
        //  if (eventEnd > segment->getEndMarkerTime()) {
        //      eventEnd = segment->getEndMarkerTime();
        //  }

        int x = static_cast<int>(nearbyint(
                m_grid.getRulerScale()->getXForTime(eventStart)));
        int width = static_cast<int>(nearbyint(
                m_grid.getRulerScale()->getWidthForDuration(
                        eventStart, eventEnd - eventStart)));

        //RG_DEBUG << "NotationPreview::createEventRects: x = " << x << ", width = " << width << " (time = " << eventStart << ", duration = " << eventEnd - eventStart << ")";

        if (x <= segStartX) {
            ++x;
            if (width > 1) --width;
        }
        if (width > 1) --width;
        if (width < 1) ++width;

        const double y0 = 0;
        const double y1 = m_grid.getYSnap();
        double y = y1 + ((y0 - y1) * (pitch - 16)) / 96;

        int height = 1;

        if (isPercussion) {
            height = 2;
            if (width > 2) width = 2;
        }

        if (y < y0) y = y0;
        if (y > y1 - height + 1) y = y1 - height + 1;

        // ??? static_cast<int>(nearbyint(y))?
        QRect r(x, static_cast<int>(y), width, height);

        npData->push_back(r);
    }
}