Example #1
0
void Piano::viewMousePressEvent(QMouseEvent* event)
      {
      button = event->button();
      shift  = event->modifiers() & Qt::ShiftModifier;
      if (keyDown != -1) {
            emit keyReleased(keyDown, shift);
            keyDown = -1;
            }
      keyDown = y2pitch(event->y());
      if (keyDown < 0 || keyDown > 127) {
            keyDown = -1;
            }
      else {
            int velocity = event->x()*127/40;
            // REMOVE Tim. Noteoff. Changed. Zero note on vel is not allowed now.
//             emit keyPressed(keyDown, velocity>127 ? 127 : velocity, shift); //emit keyPressed(keyDown, shift);
            if(velocity > 127)
              velocity = 127;
            else if(velocity <= 0)
              velocity = 1;  // Zero note on vel is not allowed.
            emit keyPressed(keyDown, velocity, shift); //emit keyPressed(keyDown, shift);
            }
            
      if (keyDown != -1 && keyDown != _curSelectedPitch) {
            _curSelectedPitch = keyDown;
            emit curSelectedPitchChanged(_curSelectedPitch);
            redraw(); 
            MusEGlobal::song->update(SC_DRUMMAP);
            }
      }
Example #2
0
QPoint EventCanvas::raster(const QPoint& p) const
{
    int x = p.x();
    if (x < 0)
        x = 0;
    x = editor->rasterVal(x);
    int pitch = y2pitch(p.y());
    int y = pitch2y(pitch);
    return QPoint(x, y);
}
Example #3
0
void Piano::viewMouseMoveEvent(QMouseEvent* event)
{
    int pitch = y2pitch(event->y());
    emit pitchChanged(pitch);
    setPitch(pitch);

    if (button != Qt::NoButton) {
        int nk = y2pitch(event->y());
        if (nk < 0 || nk > 127)
            nk = -1;
        if (nk != keyDown) {
            if (keyDown != -1) {
                emit keyReleased(keyDown, shift);
            }
            keyDown = nk;
            if (keyDown != -1) {
                int velocity = event->x()*127/40;
                emit keyPressed(keyDown, velocity>127 ? 127 : velocity, shift);
            }
        }
    }
}
Example #4
0
void Piano::mouseMoveEvent(QMouseEvent* event)
      {
      int pitch = y2pitch(event->pos().y());
      if (pitch != curPitch) {
            curPitch = pitch;
            emit pitchChanged(curPitch);
            if ((curKeyPressed != -1) && (curKeyPressed != pitch)) {
                  emit keyReleased(curKeyPressed);
                  curKeyPressed = pitch;
                  emit keyPressed(curKeyPressed);
                  }
            update();
            }
      }
Example #5
0
void PianoView::mouseMoveEvent(QMouseEvent* event)
      {
      QPointF p(mapToScene(event->pos()));
      int pitch = y2pitch(int(p.y()));
      emit pitchChanged(pitch);
      int tick = int(p.x()) -480;
      if (tick < 0) {
            tick = 0;
            pos.setTick(tick);
            pos.setInvalid();
            }
      else
            pos.setTick(tick);
      emit posChanged(pos);
      QGraphicsView::mouseMoveEvent(event);
      }
Example #6
0
void Piano::mousePressEvent(QMouseEvent* event)
      {
      curKeyPressed = y2pitch(event->pos().y());
      emit keyPressed(curKeyPressed);
      }
Example #7
0
void EventCanvas::viewMousePressEvent(QMouseEvent* event)/*{{{*/
{
    ///keyState = event->state();
    _keyState = ((QInputEvent*) event)->modifiers();
    _button = event->button();

    //printf("viewMousePressEvent buttons:%x mods:%x button:%x\n", (int)event->buttons(), (int)keyState, event->button());

    // special events if right button is clicked while operations
    // like moving or drawing lasso is performed.
    if (event->buttons() & Qt::RightButton & ~(event->button()))
    {
        //printf("viewMousePressEvent special buttons:%x mods:%x button:%x\n", (int)event->buttons(), (int)keyState, event->button());
        switch (_drag)
        {
        case DRAG_LASSO:
            _drag = DRAG_OFF;
            redraw();
            return;
        case DRAG_MOVE:
            _drag = DRAG_OFF;
            endMoveItems(_start, MOVE_MOVE, 0);
            return;
        default:
            break;
        }
    }

    // ignore event if (another) button is already active:
    if (event->buttons() & (Qt::LeftButton | Qt::RightButton | Qt::MidButton) & ~(event->button()))
    {
        //printf("viewMousePressEvent ignoring buttons:%x mods:%x button:%x\n", (int)event->buttons(), (int)keyState, event->button());
        return;
    }
    bool shift = _keyState & Qt::ShiftModifier;
    bool alt = _keyState & Qt::AltModifier;
    bool ctrl = _keyState & Qt::ControlModifier;
    _start = event->pos();

    //---------------------------------------------------
    //    set curItem to item mouse is pointing
    //    (if any)
    //---------------------------------------------------

    CItemList list = _items;
    if(multiPartSelectionAction && !multiPartSelectionAction->isChecked())
        list = getItemlistForCurrentPart();
    if (virt())
    {
        _curItem = list.find(_start);//_items.find(_start);
    }
    else
    {
        _curItem = 0; //selectAtTick(_start.x());
        iCItem ius;
        bool usfound = false;
        for (iCItem i = list.begin(); i != list.end(); ++i)
        {
            MidiTrack* mtrack = (MidiTrack*)i->second->part()->track();
            int sy = _start.y();
            int p = y2pitch(sy);
            if(editor->isGlobalEdit())
                p += mtrack->getTransposition();
            int p2 = pitch2y(p);
            QPoint lpos(_start.x(), p2);
            QRect box = i->second->bbox();
            int x = rmapxDev(box.x());
            int y = rmapyDev(box.y());
            int w = rmapxDev(box.width());
            int h = rmapyDev(box.height());
            QRect r(x, y, w, h);
            r.translate(i->second->pos().x(), i->second->pos().y());
            if(r.contains(lpos))
            {
                if (i->second->isSelected())
                {
                    _curItem = i->second;
                    break;
                }
                else if (!usfound)
                {
                    ius = i;
                    usfound = true;
                }
            }
        }
        if (!_curItem && usfound)
            _curItem = ius->second;

    }

    if(editor->isGlobalEdit() && _curItem)
    {
        populateMultiSelect(_curItem);
    }

    if (_curItem && (event->button() == Qt::MidButton))
    {
        if (!_curItem->isSelected())
        {
            selectItem(_curItem, true);
            updateSelection();
            redraw();
        }
        startDrag(_curItem, shift);
    }
    else if (event->button() == Qt::RightButton)
    {
        if (_curItem)
        {
            if (shift)
            {
                _drag = DRAG_RESIZE;
                setCursor();
                int dx = _start.x() - _curItem->x();
                _curItem->setWidth(dx);
                _start.setX(_curItem->x());
                deselectAll();
                selectItem(_curItem, true);
                updateSelection();
                redraw();
            }
            else
            {
                _itemPopupMenu = genItemPopup(_curItem);
                if (_itemPopupMenu)
                {
                    QAction *act = _itemPopupMenu->exec(QCursor::pos());
                    if (act)
                        itemPopup(_curItem, act->data().toInt(), _start);
                    delete _itemPopupMenu;
                }
            }
        }
        else
        {
            _canvasPopupMenu = genCanvasPopup(true);
            if (_canvasPopupMenu)
            {
                QAction *act = _canvasPopupMenu->exec(QCursor::pos(), 0);
                if (act)
                {
                    int actnum = act->data().toInt();
                    canvasPopup(actnum);
                    if(actnum >= 20) //Nome of the tools have a higher number than 9
                    {
                        editor->updateCanvas();
                        los->arranger->updateCanvas();
                    }
                }
                delete _canvasPopupMenu;
            }
        }
    }
    else if (event->button() == Qt::LeftButton)
    {
        switch (_tool)
        {
        case PointerTool:
            if (_curItem)
            {
                /*if (_curItem->part() != _curPart)
                {
                    _curPart = _curItem->part();
                    _curPartId = _curPart->sn();
                    curPartChanged();
                }*/
                itemPressed(_curItem);
                if (shift)
                    _drag = DRAG_COPY_START;
                else if (alt)
                {
                    _drag = DRAG_CLONE_START;
                }
                else if (ctrl)
                { //Select all on the same pitch (e.g. same y-value)
                    deselectAll();
                    //printf("Yes, ctrl and press\n");
                    for (iCItem i = _items.begin(); i != _items.end(); ++i)
                    {
                        if (i->second->y() == _curItem->y())
                            selectItem(i->second, true);
                    }
                    updateSelection();
                    redraw();
                }
                else
                    _drag = DRAG_MOVE_START;
            }
            else
                _drag = DRAG_LASSO_START;
            setCursor();
            break;

            case RubberTool:
            deleteItem(_start);
            _drag = DRAG_DELETE;
            setCursor();
            break;

            case PencilTool:
            if (_curItem)
            {
                _drag = DRAG_RESIZE;
                setCursor();
                int dx = _start.x() - _curItem->x();
                _curItem->setWidth(dx);
                _start.setX(_curItem->x());
            }
            else
            {
                _drag = DRAG_NEW;
                setCursor();
                _curItem = newItem(_start, event->modifiers());
                if (_curItem)
                    _items.add(_curItem);
                else
                {
                    _drag = DRAG_OFF;
                    setCursor();
                }
            }
            deselectAll();
            if (_curItem)
            {
                selectItem(_curItem, true);
                // Play the note
                itemPressed(_curItem);
            }
            updateSelection();
            redraw();
            break;

            default:
            break;
        }
    }
    mousePress(event);
}/*}}}*/
Example #8
0
void EventCanvas::mouseMove(QMouseEvent* event)
{
    emit pitchChanged(y2pitch(event->pos().y()));
    int x = event->pos().x();
    emit timeChanged(editor->rasterVal(x));
}