# a random music player • ### Question

• i wonder how many posible songs can this program produce

do=256
re=288
mi=324
fa=346
sol=384
la=432
si=486
re:
For i=1 To 7
nota[i]=Math.GetRandomNumber(7)
tempo[i]= Math.GetRandomNumber(2)
EndFor
For repetitions=1 To 3
i=0
While i<8
i=i+1
If tempo[i]=1 Then
time=500
ElseIf tempo[i]=2 then
time=250
EndIf
If nota[i]=1 Then
LDSound.Tone(do,time)
ElseIf nota[i]=2 then
LDSound.Tone(re,time)
ElseIf nota[i]=3 then
LDSound.Tone(mi,time)
ElseIf nota[i]=4 then
LDSound.Tone(fa,time)
ElseIf nota[i]=5 then
LDSound.Tone(sol,time)
ElseIf nota[i]=6 then
LDSound.Tone(la,time)
ElseIf nota[i]=7 then
LDSound.Tone(si,time)
EndIf
EndWhile
Program.Delay(500)
EndFor
Goto re

Thursday, December 20, 2018 4:14 AM

• Perhaps like this since already using LD extension.  LDSound.Tone is very poor quality using beep (ancient DOS thing) rather than a sound card.

```LDMusic.Instrument = LDMusic.Harpsichord
While 1=1
octave = 4+Math.GetRandomNumber(3)
note = Text.GetCharacter(Text.GetCharacterCode("A")-1+Math.GetRandomNumber(7))
time = 500*Math.GetRandomNumber(2)
value = LDMusic.PlayNote(octave,note,1)
Program.Delay(time)
LDMusic.EndNote(value)
EndWhile```
A little more work to handle sharps and flats, but that would sound bad if chosen randomly, not from a chord.

The instrument note has intrinsic length - piano key lasts longer than gunshot.  So the way to control length is to delay and stop the sound appropriately.

Friday, December 21, 2018 7:20 PM

### All replies

• Hello.

• What help do you need?
• Are you showing your program with others? If yes please change the type to General Discussion.

Thanks.

Roshan - 8th Grade Student (Age 12) - Learning Small Basic, Visual Basic and C#

Friday, December 21, 2018 1:48 AM
• well i was wondering how many posible melodic songs are

accounting if you use solfeggion frecuencies any song will sound nice

maybe the program could be simplified to this and make always the same tempo music

im no musician id like to see how some fellow musician could improve the program :)

do=256
re=288
mi=324
fa=346
sol=384
la=432
si=486
re:
For i=1 To 7
nota[i]=Math.GetRandomNumber(7)
tempo[i]= Math.GetRandomNumber(2)
EndFor
For repetitions=1 To 3
i=0
While i<8
i=i+1
if i=7 then

time=1000

else
time=500

endif

If nota[i]=1 Then
LDSound.Tone(do,time)
ElseIf nota[i]=2 then
LDSound.Tone(re,time)
ElseIf nota[i]=3 then
LDSound.Tone(mi,time)
ElseIf nota[i]=4 then
LDSound.Tone(fa,time)
ElseIf nota[i]=5 then
LDSound.Tone(sol,time)
ElseIf nota[i]=6 then
LDSound.Tone(la,time)
ElseIf nota[i]=7 then
LDSound.Tone(si,time)
EndIf
EndWhile
Program.Delay(500)
EndFor
Goto re

Friday, December 21, 2018 5:00 PM
• Perhaps like this since already using LD extension.  LDSound.Tone is very poor quality using beep (ancient DOS thing) rather than a sound card.

```LDMusic.Instrument = LDMusic.Harpsichord
While 1=1
octave = 4+Math.GetRandomNumber(3)
note = Text.GetCharacter(Text.GetCharacterCode("A")-1+Math.GetRandomNumber(7))
time = 500*Math.GetRandomNumber(2)
value = LDMusic.PlayNote(octave,note,1)
Program.Delay(time)
LDMusic.EndNote(value)
EndWhile```
A little more work to handle sharps and flats, but that would sound bad if chosen randomly, not from a chord.

The instrument note has intrinsic length - piano key lasts longer than gunshot.  So the way to control length is to delay and stop the sound appropriately.

Friday, December 21, 2018 7:20 PM