示例#1
0
void PianoRoll::mouseDown (const MouseEvent& e)
{
	bool snap = snapToGrid != e.mods.isShiftDown();
	int n = (int)((float)(getHeight()-e.y)*128.f/(float)getHeight());
	double t = pixelsToPpq((float)e.x,true);
	double accurateTime = pixelsToPpq((float)e.x,false);
	hoveringNoteIndex = sequence->getIndexOfNote(n,accurateTime);
	if (hoveringNoteIndex != No_Note) {
		hoveringNote = sequence->getEventPointer(hoveringNoteIndex);
		//existing note
		draggingNoteTimeDelta = 0.0;
		draggingNoteTransposition = 0;
		draggingNoteNumber = n;
		draggingNoteVelocity = originalNoteVelocity = hoveringNote->message.getVelocity();
		draggingNoteLength = sequence->getTimeOfMatchingKeyUp(hoveringNoteIndex) - sequence->getEventTime(hoveringNoteIndex);
		draggingNoteStartTime = sequence->getEventTime(hoveringNoteIndex);
		draggingNoteChannel = hoveringNote->message.getChannel()-1;
		draggingNoteEndOffset = (draggingNoteStartTime + draggingNoteLength) - accurateTime;
		lastDragTime = snap ? t : accurateTime;
		if (!selectedNotes.contains(hoveringNote)) {
			clearSelection();
			addToSelection(hoveringNote);
			jassert(hoveringNote->noteOffObject!=0);
			DBG("n=" + String(n) + "v=" + String(draggingNoteVelocity));
		}
		hoveringNoteIndex -= Dragging_A_Note;
	}
	else if (e.mods.isAltDown()){
		//make a new note
		wasResizing=true;
		clearSelection();
		hoveringNoteIndex = New_Note;
		draggingNoteNumber = n;
		draggingNoteVelocity = originalNoteVelocity = 127;
		draggingNoteLength = stepLengthInPpq-1;
		draggingNoteStartTime = snap ? t : accurateTime;
		draggingNoteChannel = defaultChannel;
		draggingNoteTimeDelta = 0.0;
		draggingNoteTransposition = 0;
		lastDragTime = snap ? t : accurateTime;
		if (sequence->getNumEvents()==0 && timeline->getLength()==0)
			timeline->setLoop(0,quarterNotesPerBar*ceil((lastDragTime+1)/(timebase*quarterNotesPerBar)));
		plugin->getCallbackLock().enter();
		sequence->addNote(MidiMessage(MIDI_NOTEON | draggingNoteChannel, draggingNoteNumber, draggingNoteVelocity, draggingNoteStartTime),
						  MidiMessage(MIDI_NOTEOFF | draggingNoteChannel, draggingNoteNumber, 0, draggingNoteStartTime+draggingNoteLength));
		plugin->getCallbackLock().exit();
		sequence->updateMatchedPairs();
		hoveringNote = sequence->getEventPointer(sequence->getIndexOfNote(draggingNoteNumber,draggingNoteStartTime,true));
		addToSelection(hoveringNote);
		sendChangeMessage();
	}
	else 
		clearSelection();
	noteLayer->repaint();
}
示例#2
0
/**
 * Mouse press event handler.
 */
void TiledWindow::mousePressEvent(QMouseEvent *ev) {
  clearDrops();
  auto tile = getTileAtMousePos(ev->pos());
  if (tile == NULL)
    return;
  if ((ev->modifiers() & Qt::ShiftModifier) != 0) {
    addRangeToSelection(tile);
  } else if ((ev->modifiers() & Qt::ControlModifier) != 0) {
    addToSelection(tile, true);
  } else if (!tile->isSelected()) {
    addToSelection(tile, false);
  }
  m_buttonPressed = true;
}
示例#3
0
void PianoRoll::mouseDoubleClick (const MouseEvent& e)
{
	if (e.mods.isLeftButtonDown())
	{
		bool snap = snapToGrid != e.mods.isShiftDown();
		int n = (int)((float)(getHeight()-e.y)*128.f/(float)getHeight());
		double t = pixelsToPpq((float)e.x,true);
		double accurateTime = pixelsToPpq((float)e.x,false);
		hoveringNoteIndex = sequence->getIndexOfNote(n,accurateTime);
		draggingNoteTimeDelta = 0.0;
		draggingNoteTransposition = 0;
		draggingNoteNumber = n;
		draggingNoteVelocity = originalNoteVelocity = 127;
		draggingNoteLength = stepLengthInPpq-1;
		draggingNoteStartTime = snap ? t : accurateTime;
		draggingNoteChannel = defaultChannel;
		lastDragTime = snap ? t : accurateTime;
		if (hoveringNoteIndex == No_Note) {
			if (sequence->getNumEvents()==0 && timeline->getLength()==0)
				timeline->setLoop(0,quarterNotesPerBar*ceil((lastDragTime+1)/(timebase*quarterNotesPerBar)));
			sequence->addNote(MidiMessage(MIDI_NOTEON | draggingNoteChannel, draggingNoteNumber, draggingNoteVelocity, draggingNoteStartTime),
							  MidiMessage(MIDI_NOTEOFF | draggingNoteChannel, draggingNoteNumber, 0, draggingNoteStartTime+draggingNoteLength));
			//sequence->updateMatchedPairs();
			addToSelection(sequence->getEventPointer(sequence->getIndexOfNote(n,draggingNoteStartTime,true)));
			sendChangeMessage();
			noteLayer->repaint();
		}
	}
}
示例#4
0
文件: ObjectSet.cpp 项目: akva2/BSGUI
bool ObjectSet::setData(const QModelIndex &index, const QVariant &value, int role)
{
    if (role == Qt::CheckStateRole)
    {
        if (value.toInt() == Qt::Checked)
            addToSelection(static_cast<Node *>(index.internalPointer()));
        else
            removeFromSelection(static_cast<Node *>(index.internalPointer()));
    }

    return false;
}
示例#5
0
文件: ObjectSet.cpp 项目: akva2/BSGUI
void ObjectSet::addToSelection(Node *node, bool signal, bool lock)
{
    if (lock)
        std::lock(m, DisplayObject::m);

    if (node->type() == NT_FILE)
    {
        for (auto n : node->children())
            addToSelection(n, false, false);
    }
    else if (node->type() == NT_PATCH)
    {
        Patch *patch = static_cast<Patch *>(node);
        patch->obj()->selectObject(_selectionMode, true);

        signalCheckChange(patch);
    }
    else if (node->type() == NT_COMPONENT)
    {
        ComponentType type = static_cast<Components *>(node->parent())->cType();

        if (modeMatch(_selectionMode, type))
        {
            Patch *patch = static_cast<Patch *>(node->parent()->parent());

            switch (type)
            {
            case CT_FACE:
                patch->obj()->selectFaces(true, {static_cast<Component *>(node)->index()});
                break;
            case CT_EDGE:
                patch->obj()->selectEdges(true, {static_cast<Component *>(node)->index()});
                break;
            case CT_POINT:
                patch->obj()->selectPoints(true, {static_cast<Component *>(node)->index()});
                break;
            }

            signalCheckChange(patch);
        }
    }

    if (lock)
    {
        m.unlock();
        DisplayObject::m.unlock();
    }

    if (signal)
        emit selectionChanged();
}
示例#6
0
/**
 * Add a range of tiles to the selection. One of the ends of tha range
 * is given by an already selected tile with the lowest flat index (see
 * calcFlatIndex).
 * The other end is the tile in the argument.
 * @param tile :: A new end tile of the range.
 */
void TiledWindow::addRangeToSelection(Tile *tile) {
  if (m_selection.isEmpty()) {
    addToSelection(tile, false);
    return;
  }

  int ifirst = rowCount() * columnCount();
  int ilast = 0;
  foreach (Tile *selected, m_selection) {
    int index = calcFlatIndex(selected);
    if (index < ifirst)
      ifirst = index;
    if (index > ilast)
      ilast = index;
  }
示例#7
0
void PianoRoll::mouseUp (const MouseEvent& e)
{
	int highnote,lownote;
	if (lasso.getWidth()>0) 
	{
		lownote = (int)((float)(getHeight()-lasso.getY())*128.f/(float)getHeight());
		highnote = (int)((float)(getHeight()-(lasso.getY()+lasso.getHeight()))*128.f/(float)getHeight());
		if (lownote>highnote) swapVariables(lownote,highnote);
		for (int index=0;index<(sequence->getNumEvents());index++) {
			MidiMessage m = sequence->getEventPointer(index)->message;
			DBG("eventtime=" + String(sequence->getEventTime(index)));
			if (m.isNoteOn()) {DBG("note=" + String(m.getNoteNumber()));}
			DBG("lassostart=" + String(pixelsToPpq((float)lasso.getX(),false)));
			DBG("lassoend=" + String(pixelsToPpq((float)(lasso.getX()+lasso.getWidth()),false)));
			if (m.isNoteOn() 
				&& sequence->getEventTime(index)>=pixelsToPpq((float)lasso.getX(),false) 
				&& sequence->getEventTime(index)<=pixelsToPpq((float)(lasso.getX()+lasso.getWidth()),false)
				&& m.getNoteNumber()>=lownote 
				&& m.getNoteNumber()<=highnote)
			{
				addToSelection(sequence->getEventPointer(index));
			}
		}
		lasso.setSize(0,0);
		repaint();
		noteLayer->repaint();
	}
	if (hoveringNoteIndex != No_Note) {
		if (hoveringNoteIndex<-2) hoveringNoteIndex+=9999;
		if (e.mods.isPopupMenu() && hoveringNoteIndex!=-2)
		{
			//right click, delete notes
			plugin->getCallbackLock().enter();
			for (int i=selectedNotes.size();--i>=0;)
				sequence->deleteEvent(sequence->getIndexOf(selectedNotes.getUnchecked(i)),true);			
			sequence->updateMatchedPairs();
			plugin->getCallbackLock().exit();
			clearSelection();
		}
		else {
			if (draggingNoteTimeDelta!=0 || draggingNoteTransposition!=0)
			{
				plugin->getCallbackLock().enter();
				if (draggingNoteTimeDelta!=0.0) {
					for (int i=0;i<selectedNotes.size();i++) {
						selectedNotes.getUnchecked(i)->message.addToTimeStamp(draggingNoteTimeDelta);
						selectedNotes.getUnchecked(i)->noteOffObject->message.addToTimeStamp(draggingNoteTimeDelta);
						//sequence->moveEvent(sequence->getIndexOf(selectedNotes.getUnchecked(i)),draggingNoteTimeDelta,true);
					}
					draggingNoteTimeDelta=0.0;
				}
				if (draggingNoteTransposition!=0) {
					for (int i=0;i<selectedNotes.size();i++)
						sequence->transposeEvent(sequence->getIndexOf(selectedNotes.getUnchecked(i)),draggingNoteTransposition);
					draggingNoteTransposition=0;
				}
				sequence->updateMatchedPairs(true);
				plugin->getCallbackLock().exit();
			}
			else if (wasResizing || e.mods.isAltDown())
			{
				//resize notes
				wasResizing=false;
				for (int i=selectedNoteLengths.size();--i>=0;)
				{
					if (selectedNotes.getUnchecked(i)!=0 && selectedNotes.getUnchecked(i)->noteOffObject!=0) {
						selectedNoteLengths.getReference(i).updateLength();
					}
					else {
						selectedNotes.remove(i);
						selectedNoteLengths.remove(i);
					}
				}
				plugin->getCallbackLock().enter();
				sequence->updateMatchedPairs(true);
				plugin->getCallbackLock().exit();
			}
		}
		hoveringNoteIndex = No_Note;
		hoveringNote=0;
		sendChangeMessage();
		noteLayer->repaint();
	}
}