VBAndCs / sVB-Small-Visual-Basic

Small Visual Basic (sVB) is an educational programming language, created by Eng. Mohammad Hamdy as an evolved version of Microsoft Small Basic (SB). It is meant to be easier and more powerful at the same time, to introduce programming basics to kids and beginners of any age, provided that they can use the English keyboard on the Windows OS.
Other
233 stars 16 forks source link

Problems with the sound object and its play() method ... #27

Closed boa2145 closed 1 year ago

boa2145 commented 1 year ago

Good morning,

I still have problems with the sound object:

  1. The built-in sounds (e.g. PlayChimes) are working. Sometimes I only hear a part of the sound. The PlayMusic() method is working, but the first sound is always a bit choppy in the context of the mouse event handler.
  1. The Play(path+file) method is not working.
VBAndCs commented 1 year ago

@boa2145 Please post the code that causes the issues, so I can investigate. Thanks.

boa2145 commented 1 year ago

Example 1:

Screenshot (447)

https://github.com/VBAndCs/sVB-Small-Visual-Basic/assets/113761330/69cd2427-0c10-489d-8d4c-158955749456

https://github.com/VBAndCs/sVB-Small-Visual-Basic/assets/113761330/3639eef9-861f-4609-9ea9-d54daf0c9a8e

Regards ... Gregor

boa2145 commented 1 year ago

Example 2:

Screenshot (448)

https://github.com/VBAndCs/sVB-Small-Visual-Basic/assets/113761330/be72d5e6-8204-4d0e-9572-e372f4d8353f

https://github.com/VBAndCs/sVB-Small-Visual-Basic/assets/113761330/83c802e2-2e8f-4735-9ac4-276bacfb4b78

Regards ... Gregor

VBAndCs commented 1 year ago

@boa2145 Publishing such a program without its resources is not useful. Please zip the sample folder with all images and sounds and send them here (just drop it on the editor and it will upload it to GitHub and add it to the post as a link). Besides, I don't see the problem in the 4 videos you sent. Please send a video that shows the issue, and describe it.

boa2145 commented 1 year ago

Hello Mohammad, I wanted to show you that some sound methods are working. Then I don't know how to send you the gif- and wave-files. Sorry! The ressources are not very big files. I will do it later. I can upload a video with wav-files, but you don't hear anything, because the play(path+file) method doesn't work.

Kind regards ... Gregor

Mohammad Hamdy Ghanem @.***> schrieb am Mi., 7. Juni 2023, 02:12:

@boa2145 https://github.com/boa2145 Publishing such a program without its resources is not useful. Please zip the sample folder with all images and sounds and send them here. Besides, I don't see the problem in the 4 videos you sent. Please send a video that shows the issue, and describe it.

— Reply to this email directly, view it on GitHub https://github.com/VBAndCs/sVB-Small-Visual-Basic/issues/27#issuecomment-1579632143, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3D5YMQZDSOXC6LZ4RRRSKDXJ7BOXANCNFSM6AAAAAAY34VSDM . You are receiving this because you were mentioned.Message ID: @.***>

boa2145 commented 1 year ago

Ressources.zip

I hope the zip-file works. Regards ... Gregor

VBAndCs commented 1 year ago

@boa2145 sVB creates the exe file in the bin folder inside the project folder. It copies all xaml, style, txt and image files from the project folder to the bin folder, so that the exe, but not wav file (I didn't use any sound samples, so I forgot about it :)). There is a hint that any other file types should be copied manually to the bin folder.
Though, I will update sVB to copy souond files (wav, mpa, mp3, and wma) to the bin folder. I may publish this release today, which will also contain the GraphicsWindow.FullScreen property. Until then, you can just copy the wav file to the bin folder, and enjoy your app :)

Hint: for best practice, use a global variable to hold the sound file path: BoingSound = "boing.wav" This will be availabel for sound and image files in sVB 2.8.5, so you don't need to use: BoingSound = Program.Directory + "boing.wav" because using a relative file name will make sVB looks for it at the Program's Directory.

so, you can easily reuse it 4 times in your code:

If (BallY + BallH >= GraphicsWindow.Height) Then
      ' ..............     
      Sound.Stop(BoingSound)
      Sound.Play(BoingSound)
ElseIf (BallY <= 0) Then
     ' ..............     
      Sound.Stop(BoingSound)
      Sound.Play(BoingSound)
EndIf
boa2145 commented 1 year ago

Hello Mohammad,

Thank you for your reply.

I tried what you suggested, copied the wav-file to the bin-directory, then created the global variable at the beginning of the listing -> SoundBall = Program.Directory + "\boing.wav" and changed the if-statements, but I didn't hear any wav-sound.

The source code is not mine, but exercises from the book "Developer's Reference" by P. Conrod and L. Tylee. Why do these authors publish books with programming examples that don't (anymore) work with Small Basic? It's difficult for me to program with Small Basic when event handlers don't work and the sound can't be played. Then it doesn't make programming easy for me either, if all variables in SB are global and there are global and local variables in sVB. I now understand that variables in sVB must be used at the beginning and outside of procedures and functions so that they are global and can then be used in subprograms (and not below procedures and functions). Is there "shared" in sVB to be able to use or share variables in subprograms?

Small Basic is becoming less and less attractive to me because the philosophy of the app is worse than QBasic or QuickBasic for DOS, for example? Handling variables is really something for kids, no parameters and arguments for procedures and there are no functions at all. It seems that Small Basic is no longer being developed either. Since I'm more interested in sVB. For example, if you want to program games, Scratch is a great programming language, at least for those interested in programming languages ​​in education and much, much better than SB.

For me, really good programming languages ​​are e.g. Python and C#, Swift and JavaScript (script language) are also interesting. C, C++ and Java are terrible programming languages ​​for me. How can you learn such abstract languages? Almost nothing is intuitively comprehensible or self-explanatory and adapted to human thinking.

Best regards ... Gregor

VBAndCs commented 1 year ago

@boa2145 I've just published sVB 2.8.5. I copies sound files to the bin folder and allows you to use relative files as descried above. I also allows you to show the graphics window in the full screen mode (see info and a sample in the updated pdf)

Is there "shared" in sVB to be able to use or share variables in subprograms?

Yes; the global variables are shared to the whole file, and you can use them inside and outside subroutines.

boa2145 commented 1 year ago

Hello Mohammad, Thanks for your support. In one program it works with the sound, in another program it doesn't work, although I made the same changes with your update of sVB. I'm going to stop now and I don't want to take up your time.

PS: I tried out another computer with Windows 10 and all programs with sVB are working with sound. So, there are problems with Windows 11 and the sound. The problems with Small Basic and the sound and error messages related to several threads exist on Windows 10, too.

VBAndCs commented 1 year ago

@boa2145 Both programs work fine for me. Review your code, and make sure there is no other instance of the app still working in the task manager (or just restart). Also, make sure you commented out other sounds, not to play multiple sounds together.

VBAndCs commented 1 year ago

@boa2145 Note that this code:

   If (Controls.GetButtonCaption(TimerButton) = "Start") Then
      Controls.SetButtonCaption(TimerButton, "Stop")
      Timer.Resume()
   Else
      Controls.SetButtonCaption(TimerButton, "Start")
      Timer.Pause()
   EndIf

can be simplified using sVB objects:

   If TimerButton.Text = "Start" Then
      TimerButton.Text = "Stop"
      Timer.Resume()
   Else
      TimerButton.Text = "Start"
      Timer.Pause()
   EndIf
VBAndCs commented 1 year ago

Note that code will be much easier when you use the form designer instead of the graphics window. This is the generic program that can move any number of balls. Just add labels for balls on the form and set their images, and they will all move. For example, this is how to design a three-ball form: image

You can copy aby ball label and past it on the form designer to increase the balls :). And this is the generic code that will move all the ball labels on the form:

BallW = 30
BallH = 30
HideBalls()

Timer.Interval = 100
Timer.Tick = OnTick
Timer.Pause()

Sub TimerButton_OnClick()
   If TimerButton.Text = "Start" Then
      TimerButton.Text = "Stop"
      InitializeBalls()
      Timer.Resume()
   Else
      TimerButton.Text = "Start"
      Timer.Pause()
      HideBalls()
   EndIf
EndSub

Sub HideBalls()
   ForEach control1 In Me.Controls
      If control1.TypeName = ControlTypes.Label Then
         control1.Visible = False
      EndIf
   Next
EndSub

Sub InitializeBalls()
   ForEach ballLabel In Me.Controls
      If ballLabel.TypeName = ControlTypes.Label Then
         ballLabel.Left = Math.GetRandomNumber(Me.Width - BallW) -1
         ballLabel.Top = Math.GetRandomNumber(Me.Width - BallW) -1
         ballLabel.Width = BallW
         ballLabel.Height = BallH
         ballLabel.Tag = {
            5 + Math.GetRandomNumber(15),
            10 + Math.GetRandomNumber(25)
         }
         ballLabel.Visible = True
      EndIf
   Next
EndSub

Sub OnTick
   ForEach control1 In Me.Controls
      If control1.TypeName = ControlTypes.Label Then
         MoveBall(control1)
      EndIf
   Next
EndSub

Sub MoveBall(ballLabel)
   ballSpeed = ballLabel.Tag
   ballLabel.Left = ballLabel.Left + ballSpeed[1]
   ballLabel.Top = ballLabel.Top + ballSpeed[2]

   If ballLabel.Top + BallH >= Me.Height Then
      ballLabel.Top = Me.Height - BallH
      ballLabel.Tag = {ballSpeed[1], -ballSpeed[2]}
      Sound.PlayMusic("OC")

      'Sound.Stop("boing.wav")
      'Sound.Play("boing.wav")

   ElseIf ballLabel.Top <= 0 Then
      ballLabel.Top = 0
      ballLabel.Tag = {ballSpeed[1], -ballSpeed[2]}
      Sound.PlayMusic("OD")

      'Sound.Stop("boing.wav")
      'Sound.Play("boing.wav")

   ElseIf ballLabel.Left <= 0 Then
      ballLabel.Left = 0
      ballLabel.Tag = {-ballSpeed[1], ballSpeed[2]}
      Sound.PlayMusic("OE")

      'Sound.Stop("boing.wav")
      'Sound.Play("boing.wav")

   ElseIf ballLabel.Left + BallW >= Me.Width Then
      ballLabel.Left = Me.Width - BallW
      ballLabel.Tag = {-ballSpeed[1], ballSpeed[2]}
      Sound.PlayMusic("OF")

      'Sound.Stop("boing.wav")
      'Sound.Play("boing.wav")
   EndIf
EndSub
boa2145 commented 1 year ago

Hello Mohammad, I've now found the sound problem that was driving me insane fast. It had been a problem with my bluetooth speaker. I have now turned off bluetooth and connected it to the audio out jack on the monitor via aux and cable. Now my programs with the sound also works on Windows 11. Sometimes it's really teary-eyed. I'm sorry for taking up so much of your time.

boa2145 commented 1 year ago

I have to study how to program sVB forms to understand your listing above. I can study your examples step by step to improve my sVB skills. Good night for today ... Gregor

VBAndCs commented 1 year ago

@boa2145 In sVB 2.8.5.6, you don't need any more to call Sound.Stop(soundFiile) before playing it, as the Sound.Play(soundFiile) method will make sure to stop the file first.

boa2145 commented 1 year ago

Hello Mohammad,

thanks for your improvement that there is no need to use the sound.stop method in sVB programs furthermore.

Regards ... Gregor

Mohammad Hamdy Ghanem @.***> schrieb am Mo., 12. Juni 2023, 11:21:

@boa2145 https://github.com/boa2145 In sVB 2.8.5.6 https://marketplace.visualstudio.com/items?itemName=ModernVBNET.sVBInstaller, you don't need any more to call Sound.Stop(soundFiile) before playing it, as the Sound.Play(soundFiile) method will make sure to stop the file first.

— Reply to this email directly, view it on GitHub https://github.com/VBAndCs/sVB-Small-Visual-Basic/issues/27#issuecomment-1586939633, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3D5YMSRAGJAXN7MXD23D2LXK3NRRANCNFSM6AAAAAAY34VSDM . You are receiving this because you were mentioned.Message ID: @.***>

VBAndCs commented 1 year ago

@boa2145 Sound.Stop is still necessary when the user wants to end playing the sound, but there is no need to explicitly call it in loops and timer ticks that repeatedly plays the same sound like in the bouncing balls example:

      Sound.Stop("boing.wav")
      Sound.Play("boing.wav")

now you can just use: Sound.Play("boing.wav")