Differenze tra le versioni di "La gestione dei file MIDI mediante le funzioni esterne del API di VLC"

Da Gambas-it.org - Wikipedia.
Riga 1: Riga 1:
La libreria '''''LibVLC''''' consente di eseguire anche file MIDI, purché si abbiano installate nel sistema anche le risorse dei plugin di ''FluidSynth'' per VLC: ''vlc-plugin-fluidsynth'', nonché ovviamente lo stesso ''FluidSynth''.
+
La libreria '''''LibVLC''''' consente di eseguire anche file MIDI, purché si abbiano installati nel sistema anche:
 +
* ''vlc-plugin-fluidsynth''  - le risorse dei plugin di ''FluidSynth'' per VLC;
 +
* ''fluid-soundfont-gm''     - Fluid (R3) General MIDI SoundFont (GM);
 +
* ovviamente lo stesso ''FluidSynth''.
  
  

Versione delle 13:32, 6 set 2014

La libreria LibVLC consente di eseguire anche file MIDI, purché si abbiano installati nel sistema anche:

  • vlc-plugin-fluidsynth - le risorse dei plugin di FluidSynth per VLC;
  • fluid-soundfont-gm - Fluid (R3) General MIDI SoundFont (GM);
  • ovviamente lo stesso FluidSynth.


E' possibile eseguire dati Midi anche direttamente da internet.


Per creare un'applicazione con la presente risorsa, si dovrà utilizzare l'attuale libreria libvlc.so.5.4.0.


Esempio con applicazione grafica

Private inst As Pointer
Private mp As Pointer


Library "libvlc:5.4.0"

Private Enum libvlc_NothingSpecial = 0,
        libvlc_Opening,
        libvlc_Buffering,
        libvlc_Playing,
        libvlc_Paused,
        libvlc_Stopped,
        libvlc_Ended,
        libvlc_Error

' libvlc_instance_t * libvlc_new (int argc, const char *const *argv)
' Create And initialize a libvlc instance.
Private Extern libvlc_new(argc As Integer, argv As String) As Pointer

' libvlc_media_t * libvlc_media_new_path (libvlc_instance_t *p_instance, const char *path)
' Create a media for a certain Midi file path.
Private Extern libvlc_media_new_path(p_instance As Pointer, path As String) As Pointer

' libvlc_media_player_t * libvlc_media_player_new_from_media (libvlc_media_t *p_md)
' Create a Media Player object from a Media.
Private Extern libvlc_media_player_new_from_media(p_md As Pointer) As Pointer

' int libvlc_media_player_play (libvlc_media_player_t * p_mi)
' Play the Midi file.
Private Extern libvlc_media_player_play(p_mi As Pointer) As Integer

' void libvlc_media_player_stop (libvlc_media_player_t * p_mi)
' Stop the Midi file
Private Extern libvlc_media_player_stop(p_mi As Pointer)

' libvlc_time_t libvlc_media_player_get_time(libvlc_media_player_t * p_mi)
' Get the current movie time (in ms).
Private Extern libvlc_media_player_get_time(p_mi As Pointer) As Integer

' libvlc_state_t libvlc_media_player_get_state(libvlc_media_player_t *p_mi)
' Get current movie state.
Private Extern libvlc_media_player_get_state(p_mi As Pointer) As Integer

' void libvlc_media_player_release (libvlc_media_player_t * p_mi)
' Release a media_player after use Decrement the reference count of a media player object.
Private Extern libvlc_media_player_release(p_mi As Pointer)

' libvlc_release (libvlc_instance_t * p_instance)
' Decrement the reference count of a libvlc instance, and destroy it if it reaches zero.
Private Extern libvlc_release(p_instance As Pointer)


Public Sub Button1_Click()

 Dim m As Pointer
 
   
' Inizializza la libreria VLC:
   inst = libvlc_new(0, Null)
   
' Crea un nuovo oggetto multimedia:
   m = libvlc_media_new_path(inst, "/percorso/del/file/Midi")
   
' Crea un media player:
   mp = libvlc_media_player_new_from_media(m)
   
 ' Avvia l'esecuzione del file Midi da parte del media player:
   libvlc_media_player_play(mp)

   Do
     TextLabel1.Text = CStr(Date(0, 0, 0, 0, 0, 0, libvlc_media_player_get_time(mp)))
     Wait 0.01
   Loop Until libvlc_media_player_get_state(mp) > libvlc_Playing

End


Public Sub Button2_Click()

' Arresta l'esecuzione del file Midi:
   libvlc_media_player_stop(mp)

' Rilascia e chiude il media player:
   libvlc_media_player_release(mp)
    
' Chiude la libreria VLC:
   libvlc_release(inst)

End


Esempio con applicazione a riga di comando

Library "libvlc:5.4.0"

Enum libvlc_NothingSpecial = 0,
     libvlc_Opening,
     libvlc_Buffering,
     libvlc_Playing,
     libvlc_Paused,
     libvlc_Stopped,
     libvlc_Ended,
     libvlc_Error

' libvlc_instance_t * libvlc_new (int argc, const char *const *argv)
' Create And initialize a libvlc instance.
Private Extern libvlc_new(argc As Integer, argv As String) As Pointer

' libvlc_media_t * libvlc_media_new_path (libvlc_instance_t *p_instance, const char *path)
' Create a media for a certain Midi file path.
Private Extern libvlc_media_new_path(p_instance As Pointer, path As String) As Pointer

' libvlc_media_player_t * libvlc_media_player_new_from_media (libvlc_media_t *p_md)
' Create a Media Player object from a Media.
Private Extern libvlc_media_player_new_from_media(p_md As Pointer) As Pointer

' int libvlc_media_player_play (libvlc_media_player_t * p_mi)
' Play the Midi file.
Private Extern libvlc_media_player_play(p_mi As Pointer) As Integer

' libvlc_time_t libvlc_media_player_get_time(libvlc_media_player_t * p_mi)
' Get the current movie time (in ms).
Private Extern libvlc_media_player_get_time(p_mi As Pointer) As Integer

' libvlc_state_t libvlc_media_player_get_state(libvlc_media_player_t *p_mi)
' Get current movie state.
Private Extern libvlc_media_player_get_state(p_mi As Pointer) As Integer
 
' void libvlc_media_player_release (libvlc_media_player_t * p_mi)
' Release a media_player after use Decrement the reference count of a media player object.
Private Extern libvlc_media_player_release(p_mi As Pointer)

' libvlc_release (libvlc_instance_t * p_instance)
' Decrement the reference count of a libvlc instance, and destroy it if it reaches zero.
Private Extern libvlc_release(p_instance As Pointer)


Public Sub Main()

 Dim m As Pointer
 Dim inst As Pointer
 Dim mp As Pointer
  
   
' Inizializza la libreria VLC:
   inst = libvlc_new(0, Null)
   
' Crea un nuovo oggetto multimedia:
   m = libvlc_media_new_path(inst, "/percorso/del/file/Midi")
   
' Crea un media player:
   mp = libvlc_media_player_new_from_media(m)
   
 ' Avvia l'esecuzione del file Midi da parte del media player:
   libvlc_media_player_play(mp)

  While libvlc_media_player_get_state(mp) < libvlc_Stopped
    Write #File.Out, CStr(Date(0, 0, 0, 0, 0, 0, libvlc_media_player_get_time(mp))) & "\r"
  Wend


' Va in chiusura:

' Rilascia e chiude il media player:
   libvlc_media_player_release(mp)
    
' Chiude la libreria VLC:
   libvlc_release(inst)

End


Riferimenti