示例#1
0
// --[  Method  ]---------------------------------------------------------------
//
//  - Class     : CSoundSystem
//  - prototype : bool GetMasterVolume(float* pfPercentage) const
//
//  - Purpose   : Gets the master volume (percentage).
//
// -----------------------------------------------------------------------------
bool CSoundSystem::GetMasterVolume(float* pfPercentage) const
{
    if(m_bActive == false)
    {
        return false;
    }

    int nVol = BASS_GetVolume();
    *pfPercentage = nVol / 2.55f;

    return true;
}
示例#2
0
文件: BassMusic.cpp 项目: 3rdexp/soui
int CBassMusicEngine::GetVolume()
{
	float fVolume = BASS_GetVolume();

	if ( fVolume == -1 )
	{
		ShowError(TEXT("获取声音大小错误"));
		return 0;
	}

	return int(fVolume*100);
}
示例#3
0
void Clock::KeyDown( int keyCode )
{
	if( keyCode == SDLK_ESCAPE )
		running = 0;

	if( keyCode == SDLK_UP )
		increaseMusicVolume();
	if( keyCode == SDLK_DOWN )
		decreaseMusicVolume();

	if( keyCode == SDLK_LALT )
	{
		if( lastVolumeOut == 0 )
		{
			lastVolumeOut = time(0);
			volDecreaseRate = 15.0f * (1.0f / BASS_GetVolume());
			dimMode = 1;
			curSettings->SetBrightness( curSettings->dimmedBrightness );
		} else {
			lastVolumeOut = 0;
			dimMode = 0;
			curSettings->SetBrightness( curSettings->normalBrightness );
		}
		forceRedraw = 1;
	}

	if( keyCode == SDLK_LCTRL )
	{
		dimMode = 1 - dimMode;
		forceRedraw = 1;
		if( dimMode == 0 )
			curSettings->SetBrightness( curSettings->normalBrightness );
		else
			curSettings->SetBrightness( curSettings->dimmedBrightness );
	}

	if( keyCode == SDLK_a )
		SetModule( (Module*)new SetAlarms() );
}
示例#4
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    setupUi(this);

    Finished_Init = false;
    AllowInit = false;
    PreBuf_timer = new QTimer;
    Update_timer= new QTimer;
    Ping_timer= new QTimer;
    Spectrum_timer = new QTimer;
    BufferStatusUpdate_timer= new QTimer;
    singleClickTimer=new QTimer;
    m_msgbox = NULL;
    isPlaying=false;
    syncLost=false;
    currentRadio=NULL;
    currentTrack="";
    dConnectionProgress=NULL;
    dDelConfirm=NULL;
    dShowHistory=NULL;
    netManager=NULL;
    currentRadioURL=-1;
    streamsErrLoop=false;
    pSpec=NULL;
    mMoving=false;
    savedVolume=0.5;
    isMuted=false;
    treeSelectionChanged=false;
    isRecording=false;
    newVersionAnimation=NULL;
    recButtonAnimation=NULL;
    isRootOperation=false;
#ifdef VISUALS
    isVisResized=false;
    isVisRendering=false;
    visWin=new VisWinCL(this);
    bigVis=false;
    bigVisRunning=false;
#endif

    initBitRate();
    initOggQualityMap();

    qDebug()<<"Cheking BASS version";
    if (HIWORD(BASS_GetVersion())!=BASSVERSION) {
        qDebug()<<"An incorrect version of BASS.DLL was loaded";
        QMessageBox::warning(this,QString("warning"),QString("An incorrect version of BASS.DLL was loaded"));
    }

    BASS_SetConfigPtr(BASS_CONFIG_NET_AGENT, (void*) _T(PLAYER_HTTPAGENT));


#ifdef Q_OS_WIN
    if (BASS_PluginLoad("bass_aac.dll",0)==0) {
        qDebug()<<"Unable to load bass_aac.ddl  BassError="<<BASS_ErrorGetCode();
    }
#elif Q_OS_LINUX
    if (BASS_PluginLoad("bass_aac.so",0)==0) {
        qDebug()<<"Unable to load bass_aac.ddl  BassError="<<BASS_ErrorGetCode();
    }
#endif


    QSettings tSettings(AppPath+CONFIG_FILENAME,QSettings::IniFormat);
    tSettings.setIniCodec("ISO 8859-1");
    Proxy=tSettings.value("proxy","").toString();
    ProxyPort=tSettings.value("proxyport","").toString();
    ProxyUser=tSettings.value("proxyuser","").toString();
    ProxyPass=tSettings.value("proxypass","").toString();
    visualPlugin=tSettings.value("visual",VIS_WIN_PLUG).toString();
    qDebug()<<"visualPlugin="<<visualPlugin;
    recPath=tSettings.value("recpath","").toString();
    recPath=recPath.replace("\\","\\\\");
#ifdef Q_OS_WIN
    if (recPath!="" && recPath.at(recPath.length()-1)!='\\')
        recPath=recPath+"\\";
#else
    if (recPath!="" && recPath.at(recPath.length()-1)!='/')
        recPath=recPath+"/";
#endif

    if (recPath=="") {
#ifdef Q_OS_WIN
        recPath=QDir::toNativeSeparators(QStandardPaths::standardLocations(QStandardPaths::MusicLocation).at(0)+"/");
#endif

#ifdef Q_OS_MAC
        recPath=AppPath.fromLatin1(argv[0]);
        recPath+="/";
#endif
    }

    qDebug()<<"Recording path ="<<recPath;

    if (Proxy!="") {
        qDebug()<<"Proxy="<<Proxy;
        QString tBassProxyStr=ProxyUser;
        if (ProxyPass!="")
            tBassProxyStr+=":"+ProxyPass;
        if (ProxyUser!="")
            tBassProxyStr+="@";
        tBassProxyStr+=Proxy+":"+ProxyPort;
        qDebug()<<"BASSProxy="<<tBassProxyStr;
        qDebug()<<"BASSProxy="<<tBassProxyStr.toLatin1().data();
        //strcpy(proxyStrChar,Proxy.toLatin1().data());
        BASS_SetConfigPtr(BASS_CONFIG_NET_PROXY,tBassProxyStr.toLatin1().data());
        //BASS_SetConfigPtr(BASS_CONFIG_NET_PROXY,&proxyStrChar);
    }
    else {
        BASS_SetConfigPtr(BASS_CONFIG_NET_PROXY, NULL);
    }

    //if( !InitVersion() ) ErrorMsgBox(_T("\n Error Setting up Version strings \n"));
    if( !InitBassErrorMap() ) ErrorMsgBox(_T("\n Error setting up Error Msgs \n"));
    if (!BASS_Init(-1,44100,0,NULL,NULL)) {
        ErrorMsgBox(_T("\nUnable to initialize BASS library\n"), 86, false);
        exit(86);
    }

    savedVolume=BASS_GetVolume();
    slVolume->setValue(savedVolume*slVolume->maximum());


#ifdef Q_OS_WIN
    // allocate ACM format buffer, using suggested buffer size
    acmformlen = BASS_Encode_GetACMFormat(0,NULL,0,NULL,0);
    acmform = (WAVEFORMATEX*)malloc(acmformlen);
    memset(acmform,0,acmformlen);
    acmduncil = (WAVEFORMATEX*)malloc(acmformlen);
    memset(acmduncil, 0, acmformlen);
    //
#endif

    connect(radioTree,SIGNAL(AddStationSig(QModelIndex,RadioCL*)),this,SLOT(AddStation(QModelIndex,RadioCL*)));
    connect(radioTree, SIGNAL(treeSelectionChanged(const QModelIndex &, const QModelIndex &)), this,
            SLOT(radioTreeSelectionChanges(const QModelIndex &, const QModelIndex &)));

    qDebug()<<"Connecting timers signals ";
    connect(PreBuf_timer, SIGNAL(timeout()), this, SLOT(prebufTimeout()));
    connect(Update_timer, SIGNAL(timeout()), this, SLOT(updateTimeout()));
    connect(Ping_timer, SIGNAL(timeout()),this, SLOT(pingRadio()));
    connect(Spectrum_timer, SIGNAL(timeout()), this, SLOT(specTimeout()));
    connect(BufferStatusUpdate_timer, SIGNAL(timeout()),this, SLOT(updateBufferStatus()));
    connect(singleClickTimer, SIGNAL(timeout()),this, SLOT(singleClickTimeout()));

    qDebug()<<"Connecting mgh signals";
    connect( &mgh, SIGNAL(SendUpdTrackInfo(QString)), this, SLOT(on_UpdTrackInfo(QString)) );
    connect( &mgh, SIGNAL(SendUpdRadioInfo(QString,QString,QString,QString)), this, SLOT(on_UpdRadioInfo(QString,QString,QString,QString)));
    connect( &mgh, SIGNAL(SendSyncLost()), this, SLOT(on_SyncLost()) );
    connect( &mgh, SIGNAL(SendPlaybackStarts()), this, SLOT(on_PlaybackStarts()) );
    connect( &mgh, SIGNAL(SendClickRecord()), this, SLOT(on_ClickRecord()) );

    qDebug()<<"Creating actions";
    createActions();
    qDebug()<<"Creating tray icon";
    createTrayIcon();

    qDebug()<<"Setting tray icon";
    setIcon(PLAYER_STATUS_INACTIVE);
    trayIcon->setVisible(true);
    trayIcon->show();
    setWindowTitle(QString(PLAYER_NAME)+" v"+RADIOLA_VERSION);

    qDebug()<<"Initializing spectrum image";
    specbuf = NULL;
    specmode = DEFAULT_SPEC_MODE; // spectrum mode
    specpos = 0; // spectrum mode (and marker pos for 2nd mode)
    pSpec = new QImage(SPECWIDTH, SPECHEIGHT, QImage::Format_Indexed8);
    // setup palette
    pSpec->setColor(0, qRgb(0,0,0));
    for(int a=1; a < 128; a++) {
        pSpec->setColor(a, qRgb(2*a, 256-2*a, 0));
    }
    for(int a=0; a < 32; a++) {
        pSpec->setColor(128+a, qRgb(0, 0, 8*a));
        pSpec->setColor(128+32+a, qRgb(8*a, 0, 255));
        pSpec->setColor(128+64+a, qRgb(255, 8*a, 8*(31-a)));
        //pSpec->setColor(128+64+a, qRgb(8*(31-a), 8*a, 8*a));
        pSpec->setColor(128+96+a, qRgb(255, 255, 8*a));
        //pSpec->setColor(128+96+a, qRgb(255, 255, 8*a));
    }
    pSpec->setColor(254, qRgb(112, 112, 255));
    pSpec->setColor(253, qRgb(255, 128, 128));
    pSpec->setColor(255, qRgb(212,208,200));    // background color
    // create the bitmap
    specbuf = (BYTE*)pSpec->bits();
    pSpec->fill(255);
    specButton->setSpec(pSpec);

    readSettings();

    qDebug()<<"Connecting tray signals ";
    connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
            this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));

    setupRadioTree();

    historyFile.setFileName(GetHistoryDir());

    if (!historyFile.open(QIODevice::ReadWrite | QIODevice::Append)) {
        qDebug()<<"Unable to open history file for write"<<historyFile.fileName();
        return;
    }

    StopPlayback();

    QIcon icon = QIcon(MAINWIN_ICON);
    setWindowIcon(icon);

    new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_S), this, SLOT(showSettings()));
    new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_E), this, SLOT(showRecPath()));
    new QShortcut(QKeySequence(Qt::Key_F1), this, SLOT(showHelp()));
    new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_H), this, SLOT(showHistory()));
#ifdef Q_OS_WIN
    new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_V), this, SLOT(showVisualization()));
#endif
    new QShortcut(QKeySequence(Qt::Key_Space), this, SLOT(on_pbPlay_clicked()));
    new QShortcut(QKeySequence(Qt::Key_MediaPlay), this, SLOT(on_pbPlay_clicked()));
    new QShortcut(QKeySequence(Qt::Key_Delete), this, SLOT(removeRow()));
    new QShortcut(QKeySequence(Qt::Key_Insert), this, SLOT(insertStation()));
    new QShortcut(QKeySequence(Qt::Key_Plus), this, SLOT(insertSubfolder()));

    QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect();
    effect->setBlurRadius(1); //Adjust accordingly
    effect->setOffset(3,3); //Adjust accordingly
    setShadow(bnShowHistory);
    setShadow(pbPlay);
    setShadow(pbRecord);
    setShadow(pbQuit);

    recButtonAnimation=new QMovie(":/images/rec_animation.gif");
    connect(recButtonAnimation,SIGNAL(frameChanged(int)),this,SLOT(setRecButtonIcon(int)));

    singleClickTimer->setInterval(QApplication::doubleClickInterval());
    singleClickTimer->setSingleShot(true);

    CheckNewVersion();

    netManager = new QNetworkAccessManager(this);
    if (Proxy!="") {
        netManager->setProxy(QNetworkProxy(QNetworkProxy::HttpProxy,Proxy,ProxyPort.toInt(),ProxyUser,ProxyPass));
    }
    connect(netManager, SIGNAL(finished(QNetworkReply*)),this, SLOT(pingReply(QNetworkReply*)));
}
示例#5
0
float Player::getValue()
{
    return BASS_GetVolume();
}
示例#6
0
void Clock::Update()
{
	time_t tck;
	tm* locl;

	tck = time(0);
	locl = localtime( &tck );
	if( hr != locl->tm_hour )
	{
		hr = locl->tm_hour;
		renderHr = 1;

		sprintf((char*)&dateText, "%s, %d %s %d", weekDays[locl->tm_wday], locl->tm_mday, monthNames[locl->tm_mon], locl->tm_year + 1900 );
	}
	if( mn != locl->tm_min )
	{
		mn = locl->tm_min;
		renderMn = 1;
	}
	blpdim = locl->tm_sec % 2;

	// Sleeping
	if( lastVolumeOut != 0 )
	{
		if( tck - lastVolumeOut >= volDecreaseRate )
		{
			if( BASS_GetVolume() > 0.0f )
			{
				decreaseMusicVolume();
				lastVolumeOut = tck;
			} else {
				//curSettings->SetBrightness( curSettings->sleepBrightness );
				if( curSettings->sleepPandoraOnSleepComplete != 0 )
					PutPandoraToSleep();
			}
		}
	}

	if( curSettings->Alarms->count > 0 )
	{
		for( int idx = 0; idx < curSettings->Alarms->count; idx++ )
		{
			bool playAlarm = false;
			Alarm* temp = (Alarm*)curSettings->Alarms->ItemAt(idx);
			if( temp->onHour == hr && temp->onMinute == mn )
			{

				switch( temp->checkMode )
				{
					case ALARM_CHECK_DAYOFWEEK:
						playAlarm = temp->onDay[locl->tm_wday];
						break;
					case ALARM_CHECK_YEARLYDATE:
						break;
					case ALARM_CHECK_SPECIFICDATE:
						break;
				}

				if( !temp->alarmActive && playAlarm )
				{
					lastVolumeOut = 0;
					rampUpVolume = true;
					if( hasBASS )
						BASS_ChannelPlay( BASS_StreamCreateFile( 0, ".//resource//alarm.ogg", 0, 0, BASS_STREAM_AUTOFREE ), 0 );
					temp->alarmActive = true;
					dimMode = 0;
					curSettings->SetBrightness( curSettings->normalBrightness );
					forceRedraw = 1;
				}

			} else {
				temp->alarmActive = false;
			}
		}
	}

	if( rampUpVolume )
	{
		increaseMusicVolume();
		increaseMusicVolume();
		increaseMusicVolume();
		increaseMusicVolume();
		if( BASS_GetVolume() == 1.0f )
			rampUpVolume = false;
	}

	if( lastcurMusicIndex != curSettings->MusicIndex )
		forceRedraw = 1;
	lastcurMusicIndex = curSettings->MusicIndex;

}
示例#7
0
void Clock::Render( int pageChanged )
{
	char details[100];

	if( pageChanged || forceRedraw )
	{
		SDL_FillRect( display, 0, SDL_MapRGB( display->format, 0, 0, 0 ) );

		DrawString( (char*)&dateText, 400, 0, 1, ( dimMode == 0 ? white : black ), ( dimMode == 0 ? cyan : blue ), 2, alignTop );

		sprintf((char*)&details, "Song %d of %d", curSettings->MusicIndex + 1, musicFiles.size() );
		DrawString( details, 6, 440, 0, ( dimMode == 0 ? white : black ), ( dimMode == 0 ? orange : dkred ), 1, alignBottomLeft );
		if( musicFiles.size() > 0 )
		{
			if( BASS_StreamGetFilePosition( curMP3, BASS_FILEPOS_CURRENT ) == -1 )
				DrawString( "<< Paused >>", 400, 480, 0, ( dimMode == 0 ? white : black ), ( dimMode == 0 ? orange : dkred ), 1, alignBottom );
			else
				DrawString( musicFiles.at(curSettings->MusicIndex), 6, 480, 0, ( dimMode == 0 ? white : black ), ( dimMode == 0 ? orange : dkred ), 1, alignBottomLeft );
		} else if ( hasBASS ) {
			DrawString( "No playlist", 6, 480, 0, ( dimMode == 0 ? white : black ), ( dimMode == 0 ? orange : dkred ), 1, alignBottomLeft );
		} else {
			DrawString( "No audio", 6, 480, 0, ( dimMode == 0 ? white : black ), ( dimMode == 0 ? orange : dkred ), 1, alignBottomLeft );
		}
	}

	char curTime[3];
	curTime[2] = 0;
	if( pageChanged || renderHr != 0 )
	{
		curTime[0] = clockAscii[(hr - (hr % 10)) / 10];
		curTime[1] = clockAscii[hr % 10];
		DrawString( (char*)&curTime, 370, 240, 2, ( dimMode == 0 ? red : black ), ( dimMode == 0 ? dkred : red ), 3, alignRight );
		renderHr = 0;
		if( hr == 0 && !pageChanged )
			pageChanged = true;
	}
	if( pageChanged || renderMn != 0 )
	{
		curTime[0] = clockAscii[(mn - (mn % 10)) / 10];
		curTime[1] = clockAscii[mn % 10];
		DrawString( (char*)&curTime, 430, 240, 2, ( dimMode == 0 ? red : black ), ( dimMode == 0 ? dkred : red ), 3, alignLeft );
		renderMn = 0;
	}
	if( blpdim )
		DrawString( ":", 400, 240, 2, ( dimMode == 0 ? red : black ), ( dimMode == 0 ? dkred : red ), 3, alignCentre );

	DrawAt( ( curSettings->Alarms->count == 0 ? belldim : ( dimMode == 0 ? bell : belllow ) ), 780, 80, alignTopRight );

	if( lastVolumeOut == 0 )
		DrawAt( sleepdim, 780, 140, alignTopRight );
	else
		DrawAt( ( dimMode == 0 ? sleepico : sleeplow ), 780, 140, alignTopRight );

	DrawAt( ( dimMode == 0 ? volumeico : volumeicolow ), 780, 200, alignTopRight );
	int curVol = (int)(BASS_GetVolume() * 100.0f);

	DrawRect( 744, 250, 24, 100, SDL_MapRGB( display->format, gray.r, gray.g, gray.b ) );
	DrawRect( 744, 250 + (100-curVol), 24, curVol, SDL_MapRGB( display->format, ( dimMode == 0 ? red.r : dkred.r ), ( dimMode == 0 ? red.g : dkred.g ), ( dimMode == 0 ? red.b : dkred.b ) ) );


	if( pageChanged )
		Invalidate();

	forceRedraw = 0;
}