VERSION 1.0 CLASS BEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 0 'NotAnMTSObject END Attribute VB_Name = "cCore" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = True Attribute VB_PredeclaredId = False Attribute VB_Exposed = False Option Explicit ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Objeto responsável por controlar todos eventos do programa relacionados à exibição principal ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Guarda o nome do objeto Private Const ST_MY_NAME As String = "cCore" ' Objeto de eventos Private WithEvents ces_Stream As cEventStream Attribute ces_Stream.VB_VarHelpID = -1 ' Objeto de leitura da Lyric Private WithEvents clf_Lyric As cLyricFile Attribute clf_Lyric.VB_VarHelpID = -1 ' Objeto timer de referência Private WithEvents tmr_Timer As Timer Attribute tmr_Timer.VB_VarHelpID = -1 ' Guarda a referência de um PictureBox auxiliar para uso de texto Private pb_Aux As PictureBox ' Objeto de desenho destino Private fmr_Tray As fTray ' Estados do core Private Type CORE_STATUS csPluginSet As Boolean csPluginSetting As Boolean csTimerSet As Boolean csTraySet As Boolean csLyricSet As Boolean csLyricSetting As Boolean End Type ' Estado atual Private cs_Status As CORE_STATUS ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Propriedades do timer ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Property Get Timer() As Timer ' Retorna Set Timer = tmr_Timer End Property Public Property Let Timer(tmrInput As Timer) ' Seta Set tmr_Timer = tmrInput ' Seta intermitência tmr_Timer.Interval = ln_TrackPosRefresh ' Ativa timer tmr_Timer.Enabled = True ' Informa que o timer foi setado cs_Status.csTimerSet = True Exit Property ErrTreat: LogErrMessage Err.Description, ST_MY_NAME + ".Timer [let]" End Property ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Propriedades do tray ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Property Get Tray() As fTray ' Retorna Set Tray = fmr_Tray End Property Public Property Let Tray(fmrInput As fTray) ' Seta Set fmr_Tray = fmrInput ' Informa que o tray foi setado cs_Status.csTraySet = True End Property ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Propriedade de referência auxiliar PictureBox ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Property Get AuxPictureBox() As PictureBox ' Retorna Set AuxPictureBox = pb_Aux End Property Public Property Let AuxPictureBox(pbInput As PictureBox) ' Seta novo valor Set pb_Aux = pbInput End Property ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Ao iniciar a classe ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Sub Class_Initialize() ' Inicia objeto de acesso à letra Set clf_Lyric = New cLyricFile End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Ao fechar a classe ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Sub Class_Terminate() On Error Resume Next ' Desativa o timer tmr_Timer.Enabled = False ' Sinaliza que finalizou cs_Status.csPluginSetting = True cs_Status.csLyricSet = False cs_Status.csPluginSet = False cs_Status.csTimerSet = False cs_Status.csTraySet = False ' Limpa o form fmr_Tray.Clear ' Libera objetos associados Set tmr_Timer = Nothing Set ces_Stream = Nothing Set fmr_Tray = Nothing Set pb_Aux = Nothing Set clf_Lyric = Nothing End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Finaliza operações do plugin (mas não o finaliza) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Sub preClose() ' Desativa o timer tmr_Timer.Enabled = False ' Sinaliza que finalizou cs_Status.csPluginSet = False End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Eventos do player (plugin) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Sub PluginEvent(ID As PLUGIN_EVENT) On Error GoTo ErrTreat: ' Verifica o que ocorreu Select Case ID ' Se iniciou nova música Case PLUGIN_EVENT.pePlay ' Desativa timer tmr_Timer.Enabled = False ' Limpa form fmr_Tray.Clear ' Seta que não tem Lyric carregada cs_Status.csLyricSet = False ' Seta qual faixa está tocando ln_PlayingTrack = p_Plugin.PlaylistPosisition ln_IDPlayingTrack = p_Plugin.Music.ID ' Seta que está carregando a letra cs_Status.csLyricSetting = True ' Reajusta timer tmr_Timer.Interval = ln_TrackPosRefresh tmr_Timer.Enabled = True ' Se fechou plugin Case PLUGIN_EVENT.peClose, PLUGIN_EVENT.peError, PLUGIN_EVENT.peReset ' Desativa timer tmr_Timer.Enabled = False ' Seta que não está mais tocando ln_PlayingTrack = LN_INVALID_VALUE ln_IDPlayingTrack = LN_INVALID_VALUE ' Seta que não tem Lyric carregada cs_Status.csLyricSet = False ' Seta que o plugin não está pronto cs_Status.csPluginSet = False ' Seta que o plugin não está carregando cs_Status.csPluginSetting = False ' Limpa form fmr_Tray.Clear ' Libera stream Set ces_Stream = Nothing ' Reajusta timer tmr_Timer.Interval = ln_PlayerStateRefresh tmr_Timer.Enabled = False ' Se parou a música Case PLUGIN_EVENT.peStop ' Desativa timer tmr_Timer.Enabled = False ' Seta que não está tocando ln_PlayingTrack = LN_INVALID_VALUE ln_IDPlayingTrack = LN_INVALID_VALUE ' Seta que não tem Lyric carregada cs_Status.csLyricSet = False ' Limpa form fmr_Tray.Clear ' Libera stream Set ces_Stream = Nothing ' Se há atualização disponível If (ln_LastVersion > LN_LYRIK_VERSION) Then ' Se usuário ainda não foi avisado de tal atualização If (ln_LastVersion <> ln_LastVersionShow) Then ' Imprime informação PrintUpdate End If End If ' Reabilita timer tmr_Timer.Enabled = True ' Se pausou Case PLUGIN_EVENT.pePause ' Seta que não está mais tocando ln_PlayingTrack = LN_INVALID_VALUE ln_IDPlayingTrack = LN_INVALID_VALUE ' Se plugin continua parado Case PLUGIN_EVENT.peNothing ' Se a intermitência estiver curta If (tmr_Timer.Interval < ln_PlayerStateRefresh) Then ' Se for a primeira intermitência If (tmr_Timer.Interval <= ln_TrackPosRefresh) Then ' Reajusta tray fmr_Tray.ReajustWindow End If ' Aumenta a intermitência tmr_Timer.Interval = tmr_Timer.Interval + ln_TrackPosRefresh End If ' Se plugin está pronto Case PLUGIN_EVENT.peUp ' Seta que plugin está pronto cs_Status.csPluginSet = True ' Seta que plugin não está mais carregando cs_Status.csPluginSetting = False ' Reajusta timer tmr_Timer.Interval = ln_TrackPosRefresh tmr_Timer.Enabled = False tmr_Timer.Enabled = True End Select Exit Sub ErrTreat: LogErrMessage Err.Description, ST_MY_NAME + ".PluginEvent", ID End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Comando de reset ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Sub Reset() ' Verifica se o plugin continua pronto If cs_Status.csPluginSet Then ' Se tiver letra carregada If cs_Status.csLyricSet Then ' Simula o evento play do plugin PluginEvent pePlay End If End If End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Imprimindo que há atualização ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Sub PrintUpdate() ' Cria uma letra informando de atualização disponível Dim clAux As cLyric Set clAux = New cLyric ' Seta referências clAux.AuxPictureBox = pb_Aux ' Setando letra clAux.Load = Msg("LyrikNewVersion") ' Se endereço de update ainda não foi definido If (Len(st_LyrikUpdateUrl) = 0) Then ' Monta endereço de atualização st_LyrikUpdateUrl = Replace(ST_LYRIK_UPDATE_URL, ST_SERVER_ADDRESS, st_LyrikServer) End If ' Seta que não é editavel e possui URL clAux.Editable = False clAux.URL = st_LyrikUpdateUrl ' Imprime fmr_Tray.Lyric = clAux End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Limpa a Cache ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Sub ClearCache() On Error GoTo ErrTreat: ' Limpa a cache clf_Lyric.ClearCache Exit Sub ErrTreat: LogErrMessage Err.Description, ST_MY_NAME + ".ClearCache" End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Ao carregar o arquivo de letra ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Sub clf_Lyric_Loaded(Status As LOAD_LYRIK, ID As Long) On Error GoTo ErrTreat: Dim clLyric As cLyric ' Verifica se o plugin continua pronto e se carregou com sucesso If (cs_Status.csPluginSet And Not (Status = ll_NotFound)) Then ' Verifica se o index da música é o mesmo e se carregou com sucesso If (p_Plugin.PlaylistPosisition = ID) Then ' Desativa timer tmr_Timer.Enabled = False ' Executa outras tarefas do plugins DoEvents ' Cria novo objeto de letra Set clLyric = New cLyric ' Seta referências clLyric.AuxPictureBox = pb_Aux ' Carrega letra clLyric.Load = clf_Lyric.Lyric ' Imprime no form fmr_Tray.Lyric = clLyric fmr_Tray.Music = p_Plugin.Music ' Libera stream anterior Set ces_Stream = Nothing ' Cria novo stream Set ces_Stream = New cEventStream ' Transfere a letra para o stream ces_Stream.Load = clLyric ' Se plugin possuir precisão em milisegundos If p_Plugin.MiliTrackLength Then ' Se a letra possuir um timer próprio If (clLyric.TrackLength <> LN_INVALID_VALUE) Then ' Aplica mix entre timers no stream ces_Stream.TimeMix clLyric.TrackLength, p_Plugin.Music.MiliDuration End If End If ' Seta que a letra está carregada cs_Status.csLyricSet = True ' Reativa timer tmr_Timer.Enabled = True ' Se for um update do cache If (Status = ll_FromCache) Then ' Verificar se possui letra mais atualizada clf_Lyric.LoadFrom ll_FromLyrik, ID, clLyric.Mutation End If ' Libera apontamento da letra Set clLyric = Nothing Else ' Informa que trocou de música PluginEvent pePlay End If End If Exit Sub ErrTreat: LogErrMessage Err.Description, ST_MY_NAME + ".clf_Lyric_Loaded" End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Eventos do stream ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Sub ces_Stream_LoadEvent(lnLine As Long, lnWord As Long) On Error GoTo ErrTreat: ' Verifica se música continua carregada If cs_Status.csLyricSet Then ' Seleciona texto fmr_Tray.ChooseText lnLine, lnWord End If Exit Sub ErrTreat: LogErrMessage Err.Description, ST_MY_NAME + ".ces_Stream_LoadEvent" End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Evento timer ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Sub tmr_Timer_Timer() On Error GoTo ErrTreat: ' Verifica se plugin está pronto If cs_Status.csPluginSet Then ' Atualiza timer p_Plugin.Update ' Verifica se tem letra carregada If cs_Status.csLyricSet Then ' Atualiza stream ces_Stream.UpdateTimeEvent Else ' Se estiver para carregar a letra If cs_Status.csLyricSetting Then ' Tenta carregar letra cs_Status.csLyricSetting = False clf_Lyric.Load ln_PlayingTrack End If End If Else ' Verifica se plugin está parado If (Not cs_Status.csPluginSetting) Then ' Se há plugin If Not (p_Plugin Is Nothing) Then ' Reajusta timer tmr_Timer.Interval = ln_PlayerStateRefresh ' Informa que está carregando o plugin cs_Status.csPluginSetting = True ' Acorda o plugin p_Plugin.Wakeup End If End If End If Exit Sub ErrTreat: LogErrMessage Err.Description, ST_MY_NAME + ".tmr_Timer_Timer" End Sub