コード例 #1
0
ファイル: play.c プロジェクト: labrick-lib/TalkingPen
/*----------------------------------------------------------------------------------------
函数名: PlayService
参数:
		None
返回值:
		None
描述:
		播音服务的主循环,负责按键检测,数据解码并填充缓冲区,电量检测等等
----------------------------------------------------------------------------------------*/
void PlayService(void)
{
	KEYMSG msg;

	LedFlashForCam(LED_ON);
	while(g_nState == PLAY_STATE)
	{		
		if(KEY_MsgGet(&msg)){
//			LOG(("KEY:Value:%d,TYPE:%d,HOLDTIME:%d\r\n",msg.Key_MsgValue,msg.Key_MsgType,msg.Key_HoldTime));
			g_bHaveKeyAction = 1;
			if(msg.Key_MsgValue == KEY_ON_OFF){
				if(msg.Key_MsgType == KEY_TYPE_SP){
					if(!g_bStopPlay)
						StopPlayAudio();
					else
						PlayResume();
				}else if(msg.Key_MsgType == KEY_TYPE_LP){	
					g_nState = PWRDOWN_STATE;
				}
			}else if(msg.Key_MsgValue == KEY_RECORD){
				if(msg.Key_MsgType == KEY_TYPE_LP){
					g_nState = RECORD_STATE;		
				}else if(msg.Key_MsgType == KEY_TYPE_SP){
					PlayRecord();
				}
			}else if(msg.Key_MsgValue == KEY_MACESR){
				if(msg.Key_MsgType == KEY_TYPE_LP){
					g_nState = MVREC_STATE;
				}else if(msg.Key_MsgType == KEY_TYPE_SP){
					g_nState = ESR_STATE;
				}
			}else if(msg.Key_MsgValue == KEY_TOUCH){
				if(msg.Key_MsgType == KEY_TYPE_SP){
					ProcessHead();
				}
			}
		}
		PlayWork(0,0,0);
		PlayList();
		if(!PlayChange(GetCamCode())){
//			cam_init(eDRVPDMA_CHANNEL_3);	//笔头初始化参数
		}
		CommonCheck();
	}
	ClearPlayList();
	StopPlayAudio();
	LedFlashForCam(LED_OFF);
}
コード例 #2
0
ファイル: LibUpdate.cpp プロジェクト: anonbeat/guayadeque
// -------------------------------------------------------------------------------- //
guLibUpdateThread::ExitCode guLibUpdateThread::Entry()
{
    int Index;
    int Count;
    int LastIndex;
    wxCommandEvent evtup( wxEVT_MENU, ID_STATUSBAR_GAUGE_UPDATE );
    evtup.SetInt( m_GaugeId );

    wxCommandEvent evtmax( wxEVT_MENU, ID_STATUSBAR_GAUGE_SETMAX );
    evtmax.SetInt( m_GaugeId );

    if( m_ScanPath.IsEmpty() )
    {
        Count = m_LibPaths.Count();
        if( !Count )
        {
            guLogError( wxT( "No library directories to scan" ) );
            return 0;
        }

        // For every directory in the library scan for new files and add them to m_TrackFiles
        Index = 0;
        while( !TestDestroy() && ( Index < Count ) )
        {
            guLogMessage( wxT( "Doing Library Update in %s" ), m_LibPaths[ Index ].c_str() );
            ScanDirectory( m_LibPaths[ Index ] );
            Index++;
        }
    }
    else
    {
        ScanDirectory( m_ScanPath, true );
    }

    bool EmbeddMetadata = m_MediaViewer->GetMediaCollection()->m_EmbeddMetadata;
    // For every new track file update it in the database
    Count = m_TrackFiles.Count();
    if( Count )
    {
        m_Db->ExecuteUpdate( wxT( "BEGIN TRANSACTION;" ) );

        Index = 0;
        evtmax.SetExtraLong( Count );
        wxPostEvent( m_MainFrame, evtmax );
        LastIndex = -1;
        while( !TestDestroy() )
        {
            //guLogMessage( wxT( "%i - %i" ), Index, Count );
            if( ( Index >= Count ) )
                break;

            //guLogMessage( wxT( "Scanning: '%s'" ), m_TrackFiles[ Index ].c_str() );
            m_Db->ReadFileTags( m_TrackFiles[ Index ], EmbeddMetadata );
            //Sleep( 1 );
            Index++;
            if( Index > LastIndex )
            {
                evtup.SetExtraLong( Index );
                wxPostEvent( m_MainFrame, evtup );
                LastIndex = Index + 5;
            }
        }

        m_Db->ExecuteUpdate( wxT( "COMMIT TRANSACTION;" ) );
    }

    Count = m_CueFiles.Count();
    if( Count )
    {
        m_Db->ExecuteUpdate( wxT( "BEGIN TRANSACTION;" ) );

        evtmax.SetExtraLong( Count );
        wxPostEvent( m_MainFrame, evtmax );

        for( Index = 0; Index < Count; Index++ )
        {
            //
            // Delete all files from the same cue files
            //
            wxString query = wxT( "DELETE FROM songs WHERE song_path = '" );
            query += escape_query_str( wxPathOnly( m_CueFiles[ Index ] + wxT( "/" ) ) );
            query += wxT( "' AND song_offset > 0" );
            m_Db->ExecuteUpdate( query );
            //guLogMessage( wxT( "DELETE:\n%s" ), query.c_str() );
        }

        Index = 0;
        LastIndex = -1;
        while( !TestDestroy() )
        {
            //guLogMessage( wxT( "%i - %i" ), Index, Count );
            if( ( Index >= Count ) )
                break;

            //guLogMessage( wxT( "Scanning: '%s'" ), m_TrackFiles[ Index ].c_str() );
            m_Db->ReadFileTags( m_CueFiles[ Index ], EmbeddMetadata );
            //Sleep( 1 );
            Index++;
            if( Index > LastIndex )
            {
                evtup.SetExtraLong( Index );
                wxPostEvent( m_MainFrame, evtup );
                LastIndex = Index + 5;
            }
        }

        m_Db->ExecuteUpdate( wxT( "COMMIT TRANSACTION;" ) );
    }

    ProcessCovers();

    Count = m_PlayListFiles.Count();
    if( Count )
    {
        m_Db->ExecuteUpdate( wxT( "BEGIN TRANSACTION;" ) );

        Index = 0;
        evtmax.SetExtraLong( Count );
        wxPostEvent( m_MainFrame, evtmax );
        LastIndex = -1;
        while( !TestDestroy() )
        {
            //guLogMessage( wxT( "%i - %i" ), Index, Count );
            if( ( Index >= Count ) )
                break;

            guPlaylistFile PlayList( m_PlayListFiles[ Index ] );
            wxArrayInt PlayListIds;
            int ItemTrackId;
            int ItemIndex;
            int ItemCount;
            if( ( ItemCount = PlayList.Count() ) )
            {
                for( ItemIndex = 0; ItemIndex < ItemCount; ItemIndex++ )
                {
                    if( wxFileExists( PlayList.GetItem( ItemIndex ).m_Location ) )
                    {
                        ItemTrackId = m_Db->FindTrackFile( PlayList.GetItem( ItemIndex ).m_Location, NULL );
                        if( ItemTrackId )
                        {
                            PlayListIds.Add( ItemTrackId );
                        }
                    }
                }
                if( PlayListIds.Count() )
                {
                    if( m_Db->GetStaticPlayList( m_PlayListFiles[ Index ] ) == wxNOT_FOUND )
                    {
                        m_Db->CreateStaticPlayList( m_PlayListFiles[ Index ], PlayListIds );

                        wxCommandEvent evt( wxEVT_MENU, ID_PLAYLIST_UPDATED );
                        evt.SetClientData( ( void * ) m_MediaViewer );
                        wxPostEvent( m_MainFrame, evt );
                    }
                }
            }

            Index++;
            if( Index > LastIndex )
            {
                evtup.SetExtraLong( Index );
                wxPostEvent( m_MainFrame, evtup );
                LastIndex = Index + 5;
            }
        }

        m_Db->ExecuteUpdate( wxT( "COMMIT TRANSACTION;" ) );
    }

    //
    // This cant be called here as wxBitmap do X11 calls and this can only be done from the main
    // thread. So we must call DoCleanUp from the main thread once this thread is finished.
    // in the OnLibraryUpdated Event handler
    //
    // delete all orphans entries
    // m_Db->DoCleanUp();

    return 0;
}