Help with Methods

I am need of help with getting my first Xojo project started. I am very new to programing and especially Xojo itself. I started with a program called RTcmix but switched over after talking to a professor whom recommended using Xojo. What I’d like to do is create a program that can read DNA nucleotide sequences in order to convert it to music. I’ve messed around with the NotePlayer and have a general idea of how it works. I assigned pitch values to each of the nucleotides (A, C, G, and T) and made buttons that played the notes when you push them. Now, I am having trouble creating a method that would be able to read a line of nucleotides and play them consecutively. For example, if I had something like ACCGGCTTAA it would play the pitch assigned for A, then C, then C, etc.

Here’s what I’ve got so far…

dim letter as string
dim A,C,G,T as string
dim pitch as integer

if letter = "A"then
pitch = 60
elseif letter = “C” then
pitch = 64
elseif letter = “G” then
pitch = 67
elseif letter = “T” then
pitch = 69
end if


Where do I go from here? Any ideas and help would be greatly appreciated.

Just some ideas of one approach.

First, put your pitches into a Dictionary to avoid the If.

static pitchDict as Dictionary
if pitchDict is nil then
  pitchDict = new Dictionary
  pitchDict.Value( "A" ) = 60 
  pitchDict.Value( "C" ) = 64
end if

Next, use Split to get the individual nucleotides:

dim nucleotides() as string = Split( aLine, "" )

Turn that into the pitches (make it a property of the Window or some other accessible location):

redim Pitches() // Integer array
for i as integer = 0 to nucleotides.Ubound
  if pitchDict.HasKey( nucleotides( i ) ) then
    Pitches.Append pitchDict.Value( nucleotides( i ) )
  end if
next i

PlayTimer.Period = 1000 // Once a second
PlayTimer.Mode = 2

The last two lines start a Timer (added to your window) that will play each note in Pitches once per second. The Timer.Action event will have the code that will play each note.

Sub Action()
  if Pitches.Ubound = -1 then
    me.Mode = 0 // Turn off the Timer
    dim thisNote as integer = Pitches( 0 )
    Pitches.Remove 0
    NotePlayer1.PlayNote( thisNote, 60 )
  end if
End Sub

The idea here is that you turn your line of nucleotides into an array of pitches, then start a timer that plays each one for a second (or whatever you want).

Thanks for the help!