Пример #1
0
LircCommander::LircCommander(LircClient *lirc, RosegardenMainWindow *rgGUIApp)
        : QObject()
{
    m_lirc = lirc;
    m_rgGUIApp = rgGUIApp;
    connect(m_lirc, SIGNAL(buttonPressed(const char *)),
            this, SLOT(slotExecute(const char *)) );

    connect(this, SIGNAL(play()),
            m_rgGUIApp, SLOT(slotPlay()) );
    connect(this, SIGNAL(stop()),
            m_rgGUIApp, SLOT(slotStop()) );
    connect(this, SIGNAL(record()),
            m_rgGUIApp, SLOT(slotRecord()) );
    connect(this, SIGNAL(rewind()),
            m_rgGUIApp, SLOT(slotRewind()) );
    connect(this, SIGNAL(rewindToBeginning()),
            m_rgGUIApp, SLOT(slotRewindToBeginning()) );
    connect(this, SIGNAL(fastForward()),
            m_rgGUIApp, SLOT(slotFastforward()) );
    connect(this, SIGNAL(fastForwardToEnd()),
            m_rgGUIApp, SLOT(slotFastForwardToEnd()) );
    connect(this, SIGNAL(toggleRecord()),
            m_rgGUIApp, SLOT(slotToggleRecord()) );
    connect(this, SIGNAL(trackDown()),
            m_rgGUIApp, SLOT(slotTrackDown()) );
    connect(this, SIGNAL(trackUp()),
            m_rgGUIApp, SLOT(slotTrackUp()) );
    connect(this, SIGNAL(trackMute()),
            m_rgGUIApp, SLOT(slotToggleMute()) );
    connect(this, SIGNAL(trackRecord()),
            m_rgGUIApp, SLOT(slotToggleRecordCurrentTrack()) );
    connect(this, SIGNAL(undo()),
            CommandHistory::getInstance(), SLOT(undo()) );
    connect(this, SIGNAL(redo()),
            CommandHistory::getInstance(), SLOT(redo()) );
    connect(this, SIGNAL(aboutrg()),
            m_rgGUIApp, SLOT(slotHelpAbout()) );
    connect(this, SIGNAL(editInMatrix()),
            m_rgGUIApp, SLOT(slotEditInMatrix()) );
    connect(this, SIGNAL(editInPercussionMatrix()),
            m_rgGUIApp, SLOT(slotEditInPercussionMatrix()) );
    connect(this, SIGNAL(editInEventList()),
            m_rgGUIApp, SLOT(slotEditInEventList()) );
    connect(this, SIGNAL(editAsNotation()),
            m_rgGUIApp, SLOT(slotEditAsNotation()) );
    connect(this, SIGNAL(quit()),
            m_rgGUIApp, SLOT(slotQuit()) );
    connect(this, SIGNAL(closeTransport()),
            m_rgGUIApp, SLOT(slotCloseTransport()) );
    connect(this, SIGNAL(toggleTransportVisibility()),
            m_rgGUIApp, SLOT(slotToggleTransportVisibility()) );
}
Пример #2
0
TranzportClient::TranzportClient(RosegardenMainWindow* rgGUIApp) :
    QObject(),
    device_online(true),
    previous_buttons(*reinterpret_cast<uint32_t*>(previousbuf+2)),
    current_buttons(*reinterpret_cast<uint32_t*>(currentbuf+2)),
    datawheel(currentbuf[6]),
    status(currentbuf[1]),
    m_rgGUIApp(rgGUIApp),
    m_rgDocument(rgGUIApp->getDocument()),
    m_composition(&m_rgDocument->getComposition())
{
    m_descriptor = open("/dev/tranzport0",O_RDWR);
    
    if (m_descriptor < 0) {
        throw Exception(qstrtostr(QObject::tr("Failed to open tranzport device /dev/tranzport0")));
    }

    bzero(currentbuf,8);
    bzero(previousbuf,8);

    fcntl(m_descriptor,F_SETOWN, getpid());
    int socketFlags = fcntl(m_descriptor, F_GETFL, 0);
    if (socketFlags != -1) {
        fcntl(m_descriptor, F_SETFL, socketFlags | O_NONBLOCK);
    }

    m_socketReadNotifier = new QSocketNotifier(m_descriptor, QSocketNotifier::Read, 0);
    m_socketWriteNotifier = new QSocketNotifier(m_descriptor, QSocketNotifier::Write,0);

    connect(m_socketReadNotifier, SIGNAL(activated(int)), this, SLOT(readData()));
    connect(m_socketWriteNotifier, SIGNAL(activated(int)), this, SLOT(writeCommandQueue()));
        
    connect(this, SIGNAL(play()),
            m_rgGUIApp, SLOT(slotPlay()) );
    connect(this, SIGNAL(stop()),
            m_rgGUIApp, SLOT(slotStop()) );
    connect(this, SIGNAL(record()),
            m_rgGUIApp, SLOT(slotRecord()) );
    connect(this, SIGNAL(rewind()),
            m_rgGUIApp, SLOT(slotRewind()) );
    connect(this, SIGNAL(rewindToBeginning()),
            m_rgGUIApp, SLOT(slotRewindToBeginning()) );
    connect(this, SIGNAL(fastForward()),
            m_rgGUIApp, SLOT(slotFastforward()) );
    connect(this, SIGNAL(fastForwardToEnd()),
            m_rgGUIApp, SLOT(slotFastForwardToEnd()) );
    connect(this, SIGNAL(toggleRecord()),
            m_rgGUIApp, SLOT(slotToggleRecord()) );
    connect(this, SIGNAL(trackDown()),
            m_rgGUIApp, SLOT(slotTrackDown()) );
    connect(this, SIGNAL(trackUp()),
            m_rgGUIApp, SLOT(slotTrackUp()) );
    connect(this, SIGNAL(trackMute()),
            m_rgGUIApp, SLOT(slotToggleMute()) );
    connect(this, SIGNAL(trackRecord()),
            m_rgGUIApp, SLOT(slotToggleRecordCurrentTrack()) );
    connect(this, SIGNAL(solo(bool)),
            m_rgGUIApp, SLOT(slotToggleSolo(bool)));

    connect(m_rgGUIApp, SIGNAL(documentChanged(RosegardenDocument*)),
            this, SLOT(documentChanged(RosegardenDocument*)));

    connect(m_rgDocument, SIGNAL(pointerPositionChanged(timeT)),
            this, SLOT(pointerPositionChanged(timeT)));

    connect(m_rgDocument, SIGNAL(loopChanged(timeT,timeT)),
            this, SLOT(loopChanged(timeT,timeT)));

    connect(this, SIGNAL(undo()),
            CommandHistory::getInstance(),SLOT(undo()));

    connect(this, SIGNAL(redo()),
            CommandHistory::getInstance(), SLOT(redo()));

    connect(this, SIGNAL(setPosition(timeT)),
            m_rgDocument, SLOT(slotSetPointerPosition(timeT)));

    m_composition->addObserver(this);
    m_socketWriteNotifier->setEnabled(false);
    stateUpdate();

    RG_DEBUG << "TranzportClient::TranzportClient: connected to tranzport device: " << m_descriptor << endl;
}
Пример #3
0
void LircCommander::slotExecute(const char *command)
{
    struct command tmp, *res;

    RG_DEBUG << "LircCommander::slotExecute: invoking command: " << command;

    // find the function for the name
    tmp.name = command;
    res = (struct command *)bsearch(&tmp, commands,
                                    sizeof(commands) / sizeof(struct command),
                                    sizeof(struct command),
                                    compareCommandName);
    if (res != NULL)
    {
        switch (res->code)
        {
        case cmd_play:
            emit play();
            break;
        case cmd_stop:
            emit stop();
            break;
        case cmd_record:
            emit record();
            break;
        case cmd_rewind:
            emit rewind();
            break;
        case cmd_rewindToBeginning:
            emit rewindToBeginning();
            break;
        case cmd_fastForward:
            emit fastForward();
            break;
        case cmd_fastForwardToEnd:
            emit fastForwardToEnd();
            break;
        case cmd_toggleRecord:
            emit toggleRecord();
            break;
        case cmd_trackDown:
            emit trackDown();
            break;
        case cmd_trackUp:
            emit trackUp();
            break;
        case cmd_trackMute:
            emit trackMute(); 
            break;
        case cmd_trackRecord:
            emit trackRecord(); 
            break;
        case cmd_undo:
            emit undo(); 
            break;
        case cmd_redo:
            emit redo(); 
            break;
        case cmd_aboutrg:
            emit aboutrg(); 
            break;
        case cmd_editInEventList:
            emit editInEventList(); 
            break;
        case cmd_editInMatrix:
            emit editInMatrix(); 
            break;
        case cmd_editInPercussionMatrix:
            emit editInPercussionMatrix(); 
            break;
        case cmd_editAsNotation:
            emit editAsNotation(); 
            break;
        case cmd_quit:
            emit quit(); 
            break;
        case cmd_closeTransport:
            emit closeTransport(); 
            break;
        case cmd_toggleTransportVisibility:
            emit toggleTransportVisibility(); 
            break;
        default:
            RG_DEBUG <<  "LircCommander::slotExecute: unhandled command " << command;
            return;
        }
        RG_DEBUG <<  "LircCommander::slotExecute: handled command: " << command;
    }
    else
    {
        RG_DEBUG <<  "LircCommander::slotExecute: invoking command: " << command
                 <<  " failed (command not defined in LircCommander::commands[])" << endl;
    };
}
Пример #4
0
void
TranzportClient::readData()
{
    memcpy(previousbuf, currentbuf, 8);
    ssize_t val;
    static timeT loop_start_time=0;
    static timeT loop_end_time=0;

    while ((val=read(m_descriptor,currentbuf,8)) == 8) {
        uint32_t new_buttons = current_buttons ^ previous_buttons;
        if (status == 0x1) {
            RG_DEBUG << "TranzportClient: device just came online";

            while (not commands.empty()) {
                commands.pop();
            }
            device_online = true;

            m_rgDocument = m_rgGUIApp->getDocument();
            m_composition = &m_rgGUIApp->getDocument()->getComposition();
            stateUpdate();
        }

        if (status == 0xff) {
            RG_DEBUG << "TranzportClient: device just went offline";

            device_online = false;
            return;
        }

        if (new_buttons & TrackSolo  and
            current_buttons & TrackSolo) {
            if (current_buttons & Shift) {
                bool soloflag = m_composition->isSolo();
                emit solo(not soloflag);
            }
        }

        if (new_buttons & Add  and
            current_buttons & Add) {
            if (current_buttons & Shift) {
            } else {
                AddMarkerCommand* cmd = new AddMarkerCommand(m_composition,
                                                             m_composition->getPosition(),
                                                             "tranzport",
                                                             "");
                CommandHistory::getInstance()->addCommand(cmd);
            }
        }

        if (new_buttons & Prev  and
            current_buttons & Prev) {
            RG_DEBUG << "TranzportClient:: received marker previous";

            if (current_buttons & Shift) {
            } else {
                timeT currentTime = m_composition->getPosition();
                Composition::markercontainer& mc = m_composition->getMarkers();
                timeT closestPrevious = -1;

                for (Composition::markerconstiterator it = mc.begin();
                     it != mc.end();
                     ++it) {
                    timeT markerTime = (*it)->getTime();
                    if (markerTime < currentTime  and
                        markerTime > closestPrevious) {
                        closestPrevious = markerTime;
                    }
                }

                if (closestPrevious >= 0) {
                    RG_DEBUG << "Tranzport:: setting position: " << closestPrevious;

                    emit setPosition(closestPrevious);
                }
            }
        }

        if (new_buttons & Next  and
            current_buttons & Next)
        {
            RG_DEBUG << "TranzportClient:: received marker next";

            if (current_buttons & Shift) {
            } else {
                timeT currentTime = m_composition->getPosition();
                Composition::markercontainer& mc = m_composition->getMarkers();
                timeT closestNext = std::numeric_limits<long>::max();
                
                for (Composition::markerconstiterator it = mc.begin();
                     it != mc.end();
                     ++it) {
                    timeT markerTime = (*it)->getTime();
                    if (markerTime > currentTime and
                        markerTime < closestNext) {
                        closestNext = markerTime;
                    }
                }

                if (closestNext < std::numeric_limits<long>::max()) {
                    RG_DEBUG << "Tranzport:: setting position: " << closestNext;

                    emit setPosition(closestNext);
                }
            }
        }

        if (new_buttons & Undo  and
            current_buttons & Undo) {
            if (current_buttons & Shift) {
                emit redo();
            } else {
                emit undo();
            }
        }

        if (new_buttons & Play  and
            current_buttons & Play) {
            if (current_buttons & Shift) {
            } else {
                emit play();
            }
        }

        if (new_buttons & Stop  and
            current_buttons & Stop) {
            if (current_buttons & Shift) {
            } else {
                emit stop();
            }
        }

        if (new_buttons & Record  and
            current_buttons & Record) {
            if (current_buttons & Shift) {
            } else {
                emit record();
            }
        }

        if (new_buttons & Loop  and
            current_buttons & Loop) {
            if (current_buttons & Shift) {
            } else {
                loop_start_time = m_composition->getPosition();
                loop_end_time = loop_start_time;
            }
        }

        if (new_buttons & Loop  and
            (not (current_buttons & Loop))) {
            if (current_buttons & Shift) {
            } else {
                if (loop_start_time == loop_end_time) {
                    m_rgDocument->setLoop(0,0);
                }

                loop_start_time = 0;
                loop_end_time = 0;
            }
        }

        if (new_buttons& Rewind  and
            current_buttons & Rewind) {
            if (current_buttons&Shift) {
                emit rewindToBeginning();
            } else {
                emit rewind();
            }
        }

        if (new_buttons & FastForward  and
            current_buttons & FastForward) {
            if (current_buttons & Shift) {
                emit fastForwardToEnd();
            } else {
                emit fastForward();
            }
        }

        if (new_buttons & TrackRec  and
            current_buttons & TrackRec) {
            if (current_buttons & Shift) {
            } else {
                emit trackRecord();
            }
        }

        if (new_buttons & TrackRight  and
            current_buttons & TrackRight) {
            if (current_buttons & Shift) {
            } else {
                emit trackDown();
            }
        }

        if (new_buttons & TrackLeft  and
            current_buttons & TrackLeft) {
            if (current_buttons& Shift) {
            } else {
                emit trackUp();
            }
        }

        if (new_buttons & TrackMute  and
            current_buttons & TrackMute) {
            if (current_buttons & Shift) {
            } else {
                emit trackMute();
            }
        }

        if (datawheel) {
            if (datawheel < 0x7F) {
                if (current_buttons & Loop) {
                    loop_end_time += datawheel *
                        m_composition->getDurationForMusicalTime(loop_end_time, 0,1,0,0);
                    m_rgDocument->setLoop(loop_start_time, loop_end_time);
                } else if(current_buttons & Shift) {
                    timeT here = m_composition->getPosition();
                    here += datawheel * m_composition->getDurationForMusicalTime(here,0,0,1,0);
                    if (here <= m_composition->getEndMarker()) {
                        emit setPosition(here);
                    }
                } else {
                    timeT here = m_composition->getPosition();
                    here += datawheel * m_composition->getDurationForMusicalTime(here,0,1,0,0);
                    if (here <= m_composition->getEndMarker()) {
                        emit setPosition(here);
                    }
                }
            } else {
#define DATAWHEEL_VALUE (1 + (0xFF - (datawheel)))
                if (current_buttons & Loop) {
                    loop_end_time -= (1 + (0xFF - datawheel)) *
                        m_rgGUIApp->getDocument()->getComposition().getDurationForMusicalTime(loop_end_time, 0,1,0,0);
                    m_rgDocument->setLoop(loop_start_time, loop_end_time);
                }

                if (current_buttons & Shift) {
                    timeT here = m_composition->getPosition();
                    here -= DATAWHEEL_VALUE *  m_composition->getDurationForMusicalTime(here,0,0,1,0);
                    if (here >= m_composition->getStartMarker()) {
                        emit setPosition(here);
                    }
                } else {
                    timeT here = m_composition->getPosition();
                    here -= DATAWHEEL_VALUE *  m_composition->getDurationForMusicalTime(here,0,1,0,0);
                    if (here >= m_composition->getStartMarker()) {
                        emit setPosition(here);
                    }
                }
#undef DATAWHEEL_VALUE
            }
        }

        memcpy(previousbuf, currentbuf, 8);
    }

    if (val == -1) {
        if (errno == EAGAIN) {
            return;
        } else {
            RG_DEBUG << "TranzportClient::readData: error " << strerror(errno);
        }
    } else {
        RG_DEBUG << "TranzportClient::readData: partial read of length " << val;
        RG_DEBUG << "TranzportClient::readData: this should not happen " << val;
    }
}