Ejemplo n.º 1
0
void HttpThread::updateDataReadProgress(int bytesRead, int totalBytes)
{
qDebug() << "updateDataReadProgress" << bytesRead << totalBytes;
   if (m_terminate) return;
   copyProgress(double(bytesRead)/totalBytes); 
}
Ejemplo n.º 2
0
void Pull::run()
{
   QLOG_TRACE() << "Receiving file " << m_sourceFilePath;
   qDebug() << "SecureConnection::Pull " << m_sourceFilePath << "->" << m_destinationFilePath;

   // Set blocking, which apparently is required.
   QByteArray source(m_sourceFilePath.toLocal8Bit());
   libssh2_session_set_blocking(m_session, 1);
   struct stat fileInfo;
   LIBSSH2_CHANNEL* channel(libssh2_scp_recv(m_session, source.data(), &fileInfo));

   if (channel == 0) {
       QString msg("Could not stat file ");
       msg += m_sourceFilePath;
       throw Exception(m_session, msg);
   }

   QByteArray destination(m_destinationFilePath.toLocal8Bit());
   FILE* localFileHandle(fopen(destination.data(), "wb"));

   if (!localFileHandle) {
      QString msg("Could not open file for writing ");
      msg += m_destinationFilePath;
      throw Exception(msg);
   }

   // If the buffer size changes, anything connected to the copyProgress will
   // need updating as it assumes kbyte increments.
   char buffer[1024];
   off_t got(0);
   
   while (got < fileInfo.st_size && !m_terminate) {
       int amount(sizeof(buffer));
       if ((fileInfo.st_size - got) < amount) {
          amount = fileInfo.st_size - got;
       }

       int bc(libssh2_channel_read(channel, buffer, amount));

       if (bc > 0) {
          fwrite(buffer, 1, bc, localFileHandle);
       }else if (bc < 0) {
          m_success = false;
          m_errorMessage = "Error reading from channel";
          break;
       }
       got += bc;
       copyProgress();
//qDebug() << "sleeping 1"; sleep(1);
   }

   fclose(localFileHandle);

   libssh2_channel_send_eof(channel);
// This seems to cause a hang sometimes
//   libssh2_channel_wait_eof(channel);
   libssh2_channel_wait_closed(channel);
   libssh2_channel_free(channel);

   if (!m_errorMessage.isEmpty()) throw Exception(m_errorMessage);
   if (!m_terminate) m_success = true;
}
Ejemplo n.º 3
0
void
Effect::process(const synthclone::Zone &/*zone*/,
                synthclone::SampleInputStream &inputStream,
                synthclone::SampleOutputStream &outputStream)
{
    synthclone::SampleFrameCount frames = inputStream.getFrames();
    float sampleRate = static_cast<float>(inputStream.getSampleRate());
    synthclone::SampleFrameCount fadeInFrames = fadeInEnabled ?
        static_cast<synthclone::SampleFrameCount>(fadeInTime * sampleRate) : 0;
    synthclone::SampleFrameCount fadeOutFrames = fadeOutEnabled ?
        static_cast<synthclone::SampleFrameCount>(fadeOutTime * sampleRate) : 0;
    synthclone::SampleFrameCount totalFadeFrames = fadeInFrames + fadeOutFrames;

    qDebug() << "\tfade in frames:" << fadeInFrames;
    qDebug() << "\t fade out frames:" << fadeOutFrames;

    // If the amount of frames spent fading is greater than the number of total
    // frames, then shorten the fades proportionally.  If anyone has a better
    // suggestion, I'm all ears.
    if (totalFadeFrames > frames) {

        qDebug() << "adjusting fade frames";

        fadeInFrames = static_cast<synthclone::SampleFrameCount>
            (static_cast<float>(fadeInFrames) *
             (static_cast<float>(frames) /
              static_cast<float>(totalFadeFrames)));
        fadeOutFrames = frames - fadeInFrames;

        qDebug() << "\tfade in frames:" << fadeInFrames;
        qDebug() << "\t fade out frames:" << fadeOutFrames;

    }

    synthclone::SampleChannelCount channels = inputStream.getChannels();
    QScopedArrayPointer<float> audioDataPtr(new float[channels]);
    float *audioData = audioDataPtr.data();
    synthclone::SampleFrameCount currentFrame = 0;
    synthclone::SampleFrameCount framesRead;
    float volume;
    if (fadeInFrames) {

        qDebug() << "\tapplying fade in ...";

        emit statusChanged(tr("Creating fade-in of sample ..."));
        for (; currentFrame < fadeInFrames; currentFrame++) {
            framesRead = inputStream.read(audioData, 1);
            assert(framesRead == 1);
            volume = getAmplitude(fadeInStartVolume *
                                  (1.0 - (static_cast<float>(currentFrame + 1) /
                                          static_cast<float>(fadeInFrames))));
            for (int i = 0; i < channels; i++) {
                audioData[i] *= volume;
            }
            outputStream.write(audioData, 1);
            emit progressChanged(static_cast<float>(currentFrame + 1) /
                                 static_cast<float>(frames));
        }
    }
    synthclone::SampleFrameCount fadeOutStartFrame = frames - fadeOutFrames;
    synthclone::SampleFrameCount copyFrames = fadeOutStartFrame - currentFrame;

    qDebug() << "\tcopy frames:" << copyFrames;
    qDebug() << "\tfade out start frame:" << fadeOutStartFrame;

    if (copyFrames) {

        qDebug() << "copying frames ...";

        emit statusChanged(tr("Writing sample ..."));
        copyStartFrame = currentFrame;
        copyTotalFrames = frames;
        synthclone::SampleCopier copier;
        connect(&copier,
                SIGNAL(copyProgress(synthclone::SampleFrameCount,
                                    synthclone::SampleFrameCount)),
                SLOT(handleCopyProgress(synthclone::SampleFrameCount,
                                        synthclone::SampleFrameCount)),
                Qt::DirectConnection);
        copier.copy(inputStream, outputStream, copyFrames);
    }
    currentFrame += copyFrames;
    if (fadeOutFrames) {

        qDebug() << "\tapplying fade out ...";

        emit statusChanged(tr("Creating fade-out of sample ..."));
        for (; currentFrame < frames; currentFrame++) {
            framesRead = inputStream.read(audioData, 1);
            assert(framesRead == 1);
            volume = getAmplitude(fadeOutEndVolume *
                                  (static_cast<float>(currentFrame + 1 -
                                                      fadeOutStartFrame) /
                                   static_cast<float>(fadeOutFrames)));
            for (int i = 0; i < channels; i++) {
                audioData[i] *= volume;
            }
            outputStream.write(audioData, 1);
            emit progressChanged(static_cast<float>(currentFrame + 1) /
                                 static_cast<float>(frames));
        }
    }
    emit progressChanged(0.0);
    emit statusChanged("");

    qDebug() << "/Effect::process";

}
Ejemplo n.º 4
0
void Push::run()
{
   QLOG_TRACE() << "Sending file " << m_sourceFilePath;
   // Check the local file is there first
qDebug() << "SecureConnection::Push " << m_sourceFilePath << "->" << m_destinationFilePath;
   QByteArray source(m_sourceFilePath.toLocal8Bit());
   FILE* localFileHandle(fopen(source.data(), "rb"));
            
   if (!localFileHandle) {
      QString msg("Could not stat file ");
      msg += m_sourceFilePath;
      throw Exception(msg);
   }  
         
   struct stat fileInfo;
   stat(source.data(), &fileInfo);
         
   // Set blocking, which apparently is required.
   libssh2_session_set_blocking(m_session, 1);

   QByteArray destination(m_destinationFilePath.toLocal8Bit());
   LIBSSH2_CHANNEL* channel(libssh2_scp_send(m_session, destination.data(),
      fileInfo.st_mode & 0777, (unsigned long)fileInfo.st_size));
         
   if (channel == 0) {
      QString msg("Unable to open channel for writing to file ");
      msg += m_destinationFilePath;
      throw Exception(msg);
   }
  
   size_t nread;
   char buffer[1024];
   char* ptr;
   int rc;
      
   do {
       nread = fread(buffer, 1, sizeof(buffer), localFileHandle);
       if (nread <= 0)  break; // end of file
       ptr = buffer;
       
       do {
          // write the same data over and over, until error or completion 
          // rc indicates how many bytes were written this time 
          rc = libssh2_channel_write(channel, ptr, nread);
          if (rc < 0) {
             m_errorMessage = "Error writing to channel " + QString::number(rc);
             break;
          }else {
             ptr += rc;
             nread -= rc;
          }
       } while (nread && !m_terminate);
       copyProgress();
   
   } while (!m_terminate);
   
   fclose(localFileHandle);
   
   libssh2_channel_send_eof(channel);
   libssh2_channel_wait_eof(channel);
   libssh2_channel_wait_closed(channel);
   libssh2_channel_free(channel);
   
   if (!m_errorMessage.isEmpty()) throw Exception(m_errorMessage);
   if (!m_terminate) m_success = true;
}