Esempio n. 1
0
Watcher::Watcher(QObject *parent) :
    WatcherBase(parent) {
    watcher = new QFileSystemWatcher(this);

    trayIconOff = QIcon(":/icons/res_tray_icon_black.png");
    trayIconOn  = QIcon(":/icons/res_tray_icon_color.png");
    trayMenu = new QSystemTrayIcon(this);
    connect(trayMenu, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));
    trayIconToOff();
    QMenu *trayElements = new QMenu(Global::mainWindow);
    trayElements->addAction(tr("Show timeline"), this, SLOT(trayActivateApp()));
    trayElements->addAction(tr("Write a note"),  this, SLOT(writeNote()));
    trayMenu->setContextMenu(trayElements);
    trayMenu->show();

    feeling = new WatcherFeeling();
    feeling->setStyleSheet(Global::mainWindow->styleSheet());
}
Esempio n. 2
0
int fft2note(double n)
{
/* Takes the index of the component in the FFT output array
 * and finds the closest ( appropriate ) MIDI note.
 *
 * The "closest note" is restricted by setting the Key and
 * Scale. The chromatic C major scale being the obvious
 * default (e.g. any note of the equal-tempered scale).
 */
  if (n < 1.0)
    {
      if (noActivity++ > 70) { midiSilence(); }
      return;
    }
  noActivity = 0;

  int result;
  double frequency = FREQUENCY(n);
  int k = (sizeof(mdata)/sizeof(struct midiData))/2;
  int interval = (sizeof(mdata)/sizeof(struct midiData))/4;
  gWhere = 5;


  while(interval)
    {
#ifdef DEBUG
      printf("Considering %s (%d)\n", mdata[k].name, mdata[k].octave);
#endif

      if (mdata[k].frequency > frequency )
	{
	  k -= interval;
	}
      else
	{
	  k += interval;
	}
      interval /= 2;
    }

  result = k;
  if (   abs(mdata[k].frequency-frequency)
       > abs(mdata[k+1].frequency-frequency) )
    {
      result = k+1;
    }
  else if (   abs(mdata[result].frequency-frequency)
            > abs(mdata[k-1].frequency-frequency) )
    {  
      result = k-1;
    }
    
#ifdef DEBUG
      printf("I like %s (%d)\n", mdata[k].name, mdata[k].octave);
#endif
      gWhere = 7;
      int mnote = nearestValidMIDINote( mdata[result].note );

      if (!(lastnote == mnote) || (noActivity > 20) )
	{
/*	  midiDrum(mnote, 100); */
	  midiNote(mnote-12, 127);
	  writeNote(mnote);
	  Sleep(gDelay);
	}
      lastnote = mnote;

      gAct = (int) frequency;
      gNear = (int) mdata[result].frequency;
      gNMIDI = mdata[result].note;

      return ( mdata[result].note );
}