Este foro usa cookies
Este foro utiliza cookies para almacenar su información de inicio de sesión si está registrado y su última visita si no lo está. Las cookies son pequeños documentos de texto almacenados en su computadora; las cookies establecidas por este foro solo se pueden usar en este sitio web y no representan ningún riesgo de seguridad. Las cookies en este foro también rastrean los temas específicos que ha leído y la última vez que los leyó. Si Ud. continúa navegando, entenderemos que acepta todas las cookies.

Se almacenará una cookie en su navegador, independientemente de la elección, para evitar que se le vuelva a hacer esta pregunta. Podrá cambiar la configuración de sus cookies en cualquier momento utilizando el enlace en el pie de página.

El foro antiguo se encuentra accesible desde https://foro.gambas-es.org en modo de solo lectura.

Calificación:
  • 0 voto(s) - 0 Media
  • 1
  • 2
  • 3
  • 4
  • 5

Dialogando con Procesos del S.O. desde Gambas
#1

No es infrecuente necesitar lanzar un proceso del sistema que nos pregunte cosas vía consola. En este video tutorial podéis ver una manera de dialogar con esos procesos abiertos con EXEC o con SHELL desde un programa de gambas.
En la descripción del vídeo tenéis un enlace al proyecto que en él se maneja.

Espero que os sea útil.


No podemos regresar
[-] Los siguientes 1 usuarios dice gracias a Shordi por este post:
  • tincho
    ¡Gracias!
#2

Hola Shordi.
Estoy tratando de seguir el ejemplo que hiciste pero para el programa de terminal mpg123 pero tira un error diciendo que se trata de un stream y no de un texto lo cual tiene sentido ya que estoy usando un archivo mp3
El caso es que par aoperar con este programa de terminal es necesario poder enviar teclas al programa y recuperar el texto que sale por la erminal (que no es visible)
Dejo el código aquí por si alguien desea hacer algún test.

GAMBAS
  1. Private hProcess As Process
  2.  
  3. Public Sub Form_Open()
  4.  
  5.   If Exist(Config.CurrentFile) Then
  6.     If Stat(Config.CurrentFile).Type = gb.File Then
  7.       ButtonBox1.Text = User.Home &/ "test.mp3"
  8.     Endif
  9.  
  10.  
  11. Public Sub Button1_Click()
  12.  
  13.   Dim sCommand As String
  14.  
  15.   sCommand = "mpg123 '" & ButtonBox1.Text & "'"
  16.  
  17.   hProcess = Shell sCommand For Input As "Process"
  18.  
  19.  
  20. Public Sub Process_Read()
  21.  
  22.   Read #Process, sLast, -1024
  23.   TextArea1.Text &= sLast
  24.  



1 Saludo.
    ¡Gracias!
#3

No se pueden mezclar churras con merinas, que se dice por mi tierra. La solución que yo he puesto es sólo para dialogar con las entradas y salidas estándar en forma de texto. No he profundizado en lo de manejar streams, pero supongo que estudiando la clase Process, puedes descubrir la manera.

De todas formas, si lo que quieres es oír música, enlaza el componente gb.sdl2.sound con tu proyecto y despúes con éste código es suficiente.

 
GAMBAS
  1.    music.Load(user.home &/ "Escritorio/marea.mp3")
  2.     music.play()
  3.    



Saludos

Perdón si he dicho una simpleza, pero es que yo nunca había utilizado gambas para oír música. He visto la clase music y, descubrimiento nuevo para mí, he comenazado a hacerme un reproductor propio... Big Grin Big Grin Big Grin Big Grin

Ya que estamos... ¿Alguien sabe cómo averiguar cuántos segundos de duración tiene un mp3?


Saludos.

ah... Vale, con ffmpeg. No he preguntado nada.

No podemos regresar
    ¡Gracias!
#4

(09-08-2021, 19:07)Shordi escribió:  De todas formas, si lo que quieres es oír música, enlaza el componente gb.sdl2.sound con tu proyecto y despúes con éste código es suficiente.

Gracias por el comentario, pero ya vengo usando eso en mi programa Vinilo.
Mi interés en usar este programa de terminal mpg123 es debido a  que la calidad del sonido con gb.sdl2 es mas pobre que la de mpg123 pero tal vez exista otra forma como ffmpeg o algo similar. se siguen aceptando ideas.
(09-08-2021, 19:07)Shordi escribió:  Ya que estamos... ¿Alguien sabe cómo averiguar cuántos segundos de duración tiene un mp3?
Yo uso esto:
GAMBAS
  1. ' Source:
  2. ' https://www.gambas-it.org/wiki/index.php?title=Estrarre_informazioni_e_TAG_da_file_audio_con_le_funzioni_esterne_del_API_di_Libtag_c
  3. '
  4. Library "libtag_c:0.0.0"
  5.  
  6. Public Struct TagLib_File
  7.   dummy As Integer
  8.  
  9. Public Struct TagLib_Tag
  10.   dummy As Integer
  11.  
  12. Public Struct TagLib_AudioProperties
  13.   dummy As Integer
  14.  
  15. ' void taglib_set_strings_unicode(BOOL unicode)
  16. ' By default all strings coming into or out of TagLib's C API are in UTF8.
  17. ' However, it may be desirable For TagLib To operate On Latin1(ISO - 8859 - 1) strings In which Case this should be set To FALSE.
  18. Private Extern taglib_set_strings_unicode(unicode As Boolean)
  19.  
  20. ' TagLib_File *taglib_file_new_type(const char *filename)
  21. ' Creates a TagLib file based on \a filename.
  22. Private Extern taglib_file_new(filename As String) As TagLib_File
  23.  
  24. ' TagLib_Tag *taglib_file_tag(const TagLib_File *file)
  25. ' Returns a pointer to the tag associated with this file.
  26. Private Extern taglib_file_tag(_file As TagLib_File) As TagLib_Tag
  27.  
  28. ' char *taglib_tag_title(const TagLib_Tag *tag)
  29. ' Returns a string with this tag's title.
  30. Private Extern taglib_tag_title(tag As TagLib_Tag) As String
  31.  
  32. ' char *taglib_tag_artist(const TagLib_Tag *tag)
  33. ' Returns a string with this tag's artist.
  34. Private Extern taglib_tag_artist(tag As TagLib_Tag) As String
  35.  
  36. ' char *taglib_tag_album(const TagLib_Tag *tag)
  37. ' Returns a string with this tag's album name.
  38. Private Extern taglib_tag_album(tag As TagLib_Tag) As String
  39.  
  40. ' unsigned int taglib_tag_year(const TagLib_Tag *tag)
  41. ' Returns the tag's year or 0 if year is not set.
  42. Private Extern taglib_tag_year(tag As TagLib_Tag) As Integer
  43.  
  44. ' char *taglib_tag_comment(const TagLib_Tag *tag)
  45. ' Returns a string with this tag's comment.
  46. Private Extern taglib_tag_comment(tag As TagLib_Tag) As String
  47.  
  48. ' unsigned int taglib_tag_track(const TagLib_Tag *tag)
  49. ' Returns the tag's track number or 0 if track number is not set.
  50. Private Extern taglib_tag_track(tag As TagLib_Tag) As Integer
  51.  
  52. 'Private Extern taglib_tag_encoder(tag As TagLib_Tag) As String
  53. 'Private Extern taglib_tag_volume_number(tag As TagLib_Tag) As Integer
  54.  
  55. ' char *taglib_tag_genre(const TagLib_Tag *tag)
  56. ' Returns a string with this tag's genre.
  57. Private Extern taglib_tag_genre(tag As TagLib_Tag) As String
  58.  
  59. ' const TagLib_AudioProperties *taglib_file_audioproperties(const TagLib_File *file)
  60. ' Returns a pointer to the the audio properties associated with this file.
  61. Private Extern taglib_file_audioproperties(_file As TagLib_File) As TagLib_AudioProperties
  62.  
  63. ' int taglib_audioproperties_length(const TagLib_AudioProperties *audioProperties)
  64. ' Returns the length of the file in seconds.
  65. Private Extern taglib_audioproperties_length(audioProperties As TagLib_AudioProperties) As Integer
  66.  
  67. ' int taglib_audioproperties_bitrate(const TagLib_AudioProperties *audioProperties)
  68. ' Returns the bitrate of the file in kb/s.
  69. Private Extern taglib_audioproperties_bitrate(audioProperties As TagLib_AudioProperties) As Integer
  70.  
  71. ' int taglib_audioproperties_samplerate(const TagLib_AudioProperties *audioProperties)
  72. ' Returns the sample rate of the file in Hz.
  73. Private Extern taglib_audioproperties_samplerate(audioProperties As TagLib_AudioProperties) As Integer
  74.  
  75. ' int taglib_audioproperties_channels(const TagLib_AudioProperties *audioProperties)
  76. ' Returns the number of channels in the audio stream.
  77. Private Extern taglib_audioproperties_channels(audioProperties As TagLib_AudioProperties) As Integer
  78.  
  79. ' void taglib_tag_free_strings(void)
  80. ' Frees all of the strings that have been created by the tag.
  81. Private Extern taglib_tag_free_strings()
  82.  
  83. ' void taglib_file_free(TagLib_File *file)
  84. ' Frees and closes the file.
  85. Private Extern taglib_file_free(_file As TagLib_File)
  86.  
  87.  
  88.   Dim fl As TagLib_File
  89.   Dim autag As TagLib_Tag
  90.   Dim auprop As TagLib_AudioProperties
  91.   Dim secondi, minuti As Integer
  92.   '
  93.  
  94.   'taglib_set_strings_unicode(False)
  95.   taglib_set_strings_unicode(True)
  96.  
  97.   fl = taglib_file_new(fileaudio)
  98.   If IsNull(fl) Then Error.Raise("Impossibile caricare il file audio: " & fileaudio)
  99.  
  100.   autag = taglib_file_tag(fl)
  101.   If IsNull(autag) Then Error.Raise("Impossibile ottenere i tag dal file audio: " & fileaudio)
  102.  
  103.   inf.Add(taglib_tag_album(autag), "Album")
  104.   inf.Add(taglib_tag_artist(autag), "Artist")
  105.   inf.Add(taglib_tag_track(autag), "Track")
  106.   inf.Add(taglib_tag_title(autag), "Title")
  107.   inf.Add(taglib_tag_year(autag), "Year")
  108.   inf.Add(taglib_tag_genre(autag), "Genre")
  109.   inf.Add(taglib_tag_comment(autag), "Comment")
  110.  
  111.   ' Mostra le proprietà del file audio:
  112.   auprop = taglib_file_audioproperties(fl)
  113.  
  114.   If IsNull(auprop) Then
  115.     inf.Add(True, "AudioError")
  116.   Else
  117.     inf.Add(taglib_audioproperties_length(auprop), "Length")
  118.     inf.Add(taglib_audioproperties_bitrate(auprop), "Bitrate")
  119.     inf.Add(taglib_audioproperties_samplerate(auprop), "Frequency")
  120.     inf.Add(taglib_audioproperties_channels(auprop), "Channels")
  121.  
  122.   ' Va in chiusura:
  123.   taglib_tag_free_strings()
  124.   taglib_file_free(fl)
  125.  
  126.   Return inf
  127.  



1 Saludo.
    ¡Gracias!
#5

Esta clase (de Vuott, supongo) me vendría bien, que ahora uso una llamada a shell ( 
GAMBAS
  1. Shell "ffprobe -hide_banner " & Quote(sPath) & " 2>" & tempo Wait


) que enlentece un montón cierta función,  pero mi equipo linux Mint no tiene esa librería en sus repositorios. La he buscado y es de Arch... pero requiere un montón de otras para instalarse. ¿No hay una alternativa para Mint? En el sistema existe libtag.so.1.17.0 que parece servir para lo mismo, pero no usa los mismos símbolos, por lo visto y no vale...

Sad Sad Sad

A ver si el reverenciado Consul se pasa por este foro y puede iluminarnos...

Saludos.

No podemos regresar
    ¡Gracias!
#6

(10-08-2021, 20:16)Shordi escribió:  Esta clase (de Vuott, supongo) me vendría bien, que ahora uso una llamada a shell

Si claro, el código es de Vuott.
(10-08-2021, 20:16)Shordi escribió:  En el sistema existe libtag.so.1.17.0 que parece servir para lo mismo, pero no usa los mismos símbolos

Voy a hacer unas pruebas y te digo algo.
Saludos.

1 Saludo.
    ¡Gracias!
#7

He encontrado en el foto de gambas-it.org otras funciones también de Vuott. Funcionan razonablemente bien... pero con fallos en algunos archivos que no sé identificar. Esta es mi versión:

GAMBAS
  1.  
  2.  Dim ver_mp3, layer As String
  3.  Dim j, durata As Integer
  4.  Dim vB, lB, brB As Byte
  5.  Dim initium, bitrate As Short
  6.  
  7.   s = File.Load(s)
  8.   initium = 1
  9.  
  10.   For j = initium To Len(s) - 1
  11.     If (Asc(s, j) = 255) And (Asc(s, j + 1) > 241) And (Asc(s, j + 2) > 15) Then
  12.       vB = Asc(s, j + 1) And 24
  13.       Select Case vB
  14.         Case 0
  15.           ver_mp3 = "2.5"
  16.         Case 16
  17.           ver_mp3 = "2"
  18.         Case 24
  19.           ver_mp3 = "1"
  20.       End Select
  21.       lB = Asc(s, j + 1) And 6
  22.       Select Case lB
  23.         Case 2
  24.           layer = "III"
  25.         Case 4
  26.           layer = "II"
  27.         Case 6
  28.           layer = "I"
  29.       End Select
  30.       brB = Asc(s, j + 2) And 240
  31.       bitrate = EstraeBitRate(ver_mp3, layer, brB)
  32.  
  33.       Exit
  34.       
  35.     Endif
  36.   Next
  37.   durata = Fix((Len(s) / bitrate) * 8)
  38.   Return tiempo(Format(Time(0, 0, 0, durata), "hh:nn:ss"))
  39.  
  40.  
  41.  
  42. Private Function EstraeBitRate(Vmpeg As String, layB As String, bitB As Byte) As Short
  43.  
  44.  Dim velCamp As Short
  45.  Dim abit8 As Integer[]
  46.  Dim avelcamp As Integer[]
  47.  
  48.   abit8 = [16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224]    
  49.   If Vmpeg = "1" Then   
  50.     Select Case layB    
  51.       Case "I"
  52.         Return bitB * 2
  53.       Case "II"
  54.         aVelcamp = [32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384]
  55.       Case "III"
  56.         aVelcamp = [32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320]
  57.     End Select
  58.   Else
  59.     Select Case layB     
  60.       Case "I"
  61.         aVelcamp = [32, 40, 56, 64, 80, 96, 112, 128, 160, 176, 192, 224, 256]
  62.       Case "II" To "III"
  63.         aVelcamp = [8, 16, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 320]
  64.     End Select
  65.         velcamp = aVelcamp[abit8.Find(bitB)]
  66.   Return velCamp
  67.  


Es mucho más rápida que la otra... pero ya te digo, en algunos archivos, no sé por qué, falla.

De momento me quedo con el
GAMBAS
  1. Private Sub cargatiempo(sPath As String) As String
  2.     
  3.     Dim tempo, salida As String
  4.    
  5.     tempo = Temp()
  6.     Shell "ffprobe -hide_banner " & Quote(sPath) & " 2>" & tempo
  7.     Wait 0.1
  8.     If Not Exist(tempo) Then Return
  9.     salida = File.Load(tempo)
  10.     Return tiempo(Between(salida, "Duration: ", "."))
  11.     


 Aunque también me da algún fallo que otro, sobre todo si el nombre el archivo contiene caracteres extraños, que todavía estoy investigando.
Es más lenta que la de vuott de arriba pero creo que falla menos... Si yo entendiera de archivos de música probaría a modificar la de Vuott... pero me da mucha pereza meterme en ese potaje sólo por un programeta tontito como el que he hecho.

Saludos

No podemos regresar
    ¡Gracias!


Posibles temas similares…
Tema / Autor Respuestas Vistas Último mensaje

Salto de foro:


Usuarios navegando en este tema: 1 invitado(s)