|
|
(8 versioni intermedie di uno stesso utente non sono mostrate) |
Riga 1: |
Riga 1: |
− | Mostriamo di seguito il codice per di un semplice applicativo per la riproduzione di file Midi.
| + | #REDIRECT [[La_gestione_dei_file_MIDI_mediante_le_funzioni_esterne_del_API_di_Fluidsynth]] |
− | | |
− | Bisogna avere installato ''Jackd''. Una volta lanciato l'applicativo, aprire ''Jackd'' e nella scheda "''Audio''" connettere il dispositivo "''Fluidsynth''", presente nella colonna "Clients leggibili/Porte d'uscita", al dispositivo "''system''" presente nella colonna "Clients scrivibili/Porte d'entrata".
| |
− | | |
− | Si dovrà, inoltre, individuare un file ''soundfont bank'' con estensione <FONT color=#B22222>.sf2</font>, da far caricare successivamente dalla funzione esterna "''fluid_synth_sfload''" per poter ottenere i suoni.
| |
− | | |
− | | |
− | '''Private''' settings As Pointer
| |
− | '''Private''' synth As Pointer
| |
− | '''Private''' adriver As Pointer
| |
− | '''Private''' player As Pointer
| |
− | '''Private''' fileMidi As String
| |
− |
| |
− | Library "libfluidsynth:1.5.2"
| |
− |
| |
− | <FONT color=#006400>' ''fluid_settings_t* new_fluid_settings(void) ---> Crea un nuovo oggetto Settings.''</font>
| |
− | '''Private''' Extern new_fluid_settings() As Pointer
| |
− |
| |
− | <FONT color=#006400>' ''fluid_synth_t * new_fluid_synth (fluid_settings_t *settings) ---> Crea una nuova istanza FluidSynth.''</font>
| |
− | '''Private''' Extern new_fluid_synth(settP As Pointer) As Pointer
| |
− |
| |
− | <FONT color=#006400>' ''fluid_player_t* new_fluid_player(fluid_synth_t * synth) ---> Crea un nuovo lettore MIDI.''</font>
| |
− | '''Private''' Extern new_fluid_player(synth As Pointer) As Pointer
| |
− |
| |
− | <FONT color=#006400>' ''int fluid_settings_setintfluid_settings_t *settings, const char *name, int val) ---> Connette automaticamente il lettore Midi a Jack.''</font>
| |
− | '''Private''' Extern fluid_settings_setint(settP As Pointer, name As String, val As Integer) As Integer
| |
− |
| |
− | <FONT color=#006400>' ''fluid_audio_driver_t* new_fluid_audio_driver(fluid_settings_t * settings, fluid_synth_t * synth) ---> Crea un nuovo driver audio.''</font>
| |
− | '''Private''' Extern new_fluid_audio_driver(settings As Pointer, synth As Pointer) As Pointer
| |
− |
| |
− | <FONT color=#006400>' ''int fluid_is_soundfont(const char * filename) ---> Controlla se il file caricato è effettivamente un file SoundFont.''</font>
| |
− | '''Private''' Extern fluid_is_soundfont($filename As String) As Integer
| |
− |
| |
− | <FONT color=#006400>' ''int fluid_synth_sfload(fluid_synth_t * synth, const char * filename, nt reset_presets) ---> Carica file SoundFont.''</font>
| |
− | '''Private''' Extern fluid_synth_sfload(synth As Pointer, $filename As String, reset_presets As Integer) As Integer
| |
− |
| |
− | <FONT color=#006400>' ''int fluid_is_midifile(const char * filename) ---> Controlla se il file caricato è un file MIDI.''</font>
| |
− | '''Private''' Extern fluid_is_midifile($fileMidi As String) As Integer
| |
− |
| |
− | <FONT color=#006400>' ''int fluid_player_add(fluid_player_t * player, Const char * midifile) ---> Aggiunge un file MIDI alla coda del lettore.''</font>
| |
− | '''Private''' Extern fluid_player_add(player As Pointer, $fileMidi As String) As Integer
| |
− |
| |
− | <FONT color=#006400>' ''int fluid_player_play(fluid_player_t * player) ---> Attiva la modalità esegui (play) al lettore MIDI, se non sta già eseguendo un Midi.''</font>
| |
− | '''Private''' Extern fluid_player_play(player As Pointer) As Integer
| |
− |
| |
− | <FONT color=#006400>' ''int fluid_player_get_status(fluid_player_t * player) ---> Ottiene lo status del lettore MIDI.''</font>
| |
− | '''Private''' Extern fluid_player_get_satus(player As Pointer) As Integer
| |
− |
| |
− | <FONT color=#006400>' ''void delete_fluid_audio_driver(fluid_audio_driver_t * driver) ---> Elimina un'istanza di driver audio.''</font>
| |
− | '''Private''' Extern delete_fluid_audio_driver(driver As Pointer)
| |
− |
| |
− | <FONT color=#006400>' ''int delete_fluid_player(fluid_player_t * player) ---> Elimna un'istanza di lettore MIDI.''</font>
| |
− | '''Private''' Extern delete_fluid_player(player As Pointer) As Integer
| |
− |
| |
− | <FONT color=#006400>' ''int delete_fluid_synth(fluid_synth_t * synth) ---> Elimna un'istanza FluidSynth.''</font>
| |
− | '''Private''' Extern delete_fluid_synth(synth As Pointer) As Integer
| |
− |
| |
− | <FONT color=#006400>' ''void delete_fluid_settings(fluid_settings_t * settings) ---> Elimina l'oggetto Settings.''</font>
| |
− | '''Private''' Extern delete_fluid_settings(settings As Pointer)
| |
− |
| |
− |
| |
− | '''Public''' Sub Form_Open()
| |
− |
| |
− | Dim i As Integer
| |
− | Dim filesbk As String = "''percorso_file_soundfont.sf2''"
| |
− |
| |
− |
| |
− | settings = new_fluid_settings()
| |
− |
| |
− | synth = new_fluid_synth(settings)
| |
− |
| |
− | player = new_fluid_player(synth)
| |
− |
| |
− | i = fluid_settings_setint(settings, "audio.jack.autoconnect", 1)
| |
− | Print i; " --> Se il valore è uguale a 1, la funzione 'fluid_synth_setint' ha avuto successo. Se è uguale a 0 ha fallito."
| |
− |
| |
− | adriver = new_fluid_audio_driver(settings, synth)
| |
− |
| |
− | i = fluid_is_soundfont(filesbk)
| |
− | Print "E' un soundfont bank ? "; CBool(i), "Se il risultato è 'True', allora il file è un SoundFont; se è 'False', allora non lo è."
| |
− |
| |
− | i = fluid_synth_sfload(synth, filesbk, 1)
| |
− | Print i; " --> Se il valore è uguale a 1, la funzione 'fluid_synth_sfload' ha avuto successo. Se è uguale a -1 ha fallito."
| |
− |
| |
− | '''End'''
| |
− |
| |
− |
| |
− | '''Public''' Sub Button1_Click()
| |
− |
| |
− | Dim i As Integer
| |
− |
| |
− |
| |
− | i = fluid_player_add(player, fileMidi)
| |
− | Print i; " --> Se il valore è uguale a zero, la funzione 'fluid_player_add' ha avuto successo. Se è uguale a -1 ha fallito."
| |
− |
| |
− | i = fluid_player_play(player)
| |
− | Print i; " --> Se il valore è uguale a zero, la funzione 'fluid_player_play' ha avuto successo. Se è uguale a -1 ha fallito."
| |
− |
| |
− | Do
| |
− | Wait 0.01
| |
− | Loop Until fluid_player_get_status(player) <> 1
| |
− |
| |
− | i = delete_fluid_player(player)
| |
− | Print i; " --> Se il valore è uguale a zero, la funzione 'delete_fluid_player' ha avuto successo. Se è uguale a -1 ha fallito."
| |
− |
| |
− | player = new_fluid_player(synth)
| |
− |
| |
− | '''End'''
| |
− |
| |
− |
| |
− | '''Public''' Sub Form_Close()
| |
− |
| |
− | delete_fluid_audio_driver(adriver)
| |
− |
| |
− | delete_fluid_player(player)
| |
− |
| |
− | delete_fluid_synth(synth)
| |
− |
| |
− | delete_fluid_settings(settings)
| |
− |
| |
− | '''End'''
| |
− |
| |
− |
| |
− | '''Public''' Sub MenuApri_Click()
| |
− |
| |
− | Dim i As Integer
| |
− |
| |
− | With Dialog
| |
− | .Title = "Apri file Midi..."
| |
− | .Filter = ["*.mid", "File Midi"]
| |
− | If .OpenFile() Then Return
| |
− | fileMidi = .Path
| |
− | End With
| |
− |
| |
− | i = fluid_is_midifile(fileMidi)
| |
− | Print "E' un file Midi ? "; CBool(i), "Se il risultato è 'True', allora il file è un File Midi; se è 'False', allora non lo è."
| |
− |
| |
− | '''End'''
| |