Page 1 of 1
wat is the best way to store static data
Posted: Sat Mar 30, 2019 8:48 pm
by droadje
Hi,
What is the best way to solve my situation:
I have created a guitar fretboard with buttons.
If you click a button, it shows the note name for 1 second. This already works.
But now, I want to be able to show for example all E notes on the fretboard, so i have to make a data thingy, where i can get the information of which button contains a E note.
for each button, i have a procedure when clicked like this:
Code: Select all
Procedure Button1_0(EventType)
If GetGadgetText(Button1_0) = ""
SetGadgetText(Button1_0, "E")
CreateThread(@empty(), Button1_0)
Else
SetGadgetText(Button1_0, "")
EndIf
EndProcedure
Button1_0 is de first button on string 1 and had de note E
So the data i need to store (and retrieve) is like: string-button-note
1 - button1_0-E
1 - button1_1-F
1 - button1_2-F#
1-.....
1-....
2 - button2_1 - B
2 - button2_2 - C
and so on for 6 strings with 12 notes
So for example i want all the E notes on the fretboard on so i need to retrieve from a table which buttons there are with the E notes on which 6 strings.
What is the best way to store this information so i can easaly retrieve/query the data?
should i go for structure or map or list or perhaps a in memory sqlite database ?
Re: wat is the best way to store static data
Posted: Sat Mar 30, 2019 9:09 pm
by infratec
If you can not use this I would use a list or an array.
A map makes no sense, since you don't have a meaningfull key.
But I have to say that I not really understand what you want to achieve.
And your shown procedure set the text to "" when it is already "".
This makes no sense.
Re: wat is the best way to store static data
Posted: Sat Mar 30, 2019 9:12 pm
by infratec
Maybe a structure like
Code: Select all
Structure
String.i
Button.i
Note$
EndStructure
Re: wat is the best way to store static data
Posted: Sat Mar 30, 2019 9:16 pm
by infratec
Or, when it fits your problem, use a map with the note as key
and store the string and the button in a structure of a list below.
Then you can find the note element and use foreach for all pressed keys.
Code: Select all
Structure StringButtonStructure
String.i
Button.i
EndStructure
Structure NoteMapStructure
List StringButtonList.StringButtonStructure()
EndStructure
NewMap NoteMap.NoteMapStructure()
If Not FindMapElement(NoteMap(), "E")
AddMapElement(NoteMap(), "E")
EndIf
AddElement(NoteMap()\StringButtonList())
NoteMap()\StringButtonList()\String = 1
NoteMap()\StringButtonList()\Button = 1
AddElement(NoteMap()\StringButtonList())
NoteMap()\StringButtonList()\String = 3
NoteMap()\StringButtonList()\Button = 1
AddElement(NoteMap()\StringButtonList())
NoteMap()\StringButtonList()\String = 4
NoteMap()\StringButtonList()\Button = 1
If Not FindMapElement(NoteMap(), "F")
AddMapElement(NoteMap(), "F")
EndIf
AddElement(NoteMap()\StringButtonList())
NoteMap()\StringButtonList()\String = 2
NoteMap()\StringButtonList()\Button = 3
AddElement(NoteMap()\StringButtonList())
NoteMap()\StringButtonList()\String = 5
NoteMap()\StringButtonList()\Button = 1
AddElement(NoteMap()\StringButtonList())
NoteMap()\StringButtonList()\String = 6
NoteMap()\StringButtonList()\Button = 1
If FindMapElement(NoteMap(), "E")
ForEach NoteMap()\StringButtonList()
Debug MapKey(NoteMap()) + " - " + Str(NoteMap()\StringButtonList()\String) + " - " + Str(NoteMap()\StringButtonList()\Button)
Next
EndIf
Re: wat is the best way to store static data
Posted: Sat Mar 30, 2019 9:30 pm
by droadje
infratec wrote:
If you can not use this I would use a list or an array.
A map makes no sense, since you don't have a meaningfull key.
But I have to say that I not really understand what you want to achieve.
And your shown procedure set the text to "" when it is already "".
This makes no sense.
All the buttons show no text, when you push it, the note is shown in the button, then after 1 second, the text is cleared again.
Ok, i will try the examples, start with structure...
Re: wat is the best way to store static data
Posted: Sat Mar 30, 2019 9:49 pm
by droadje
So, like this?
Code: Select all
Structure Fretboard
String.i
Button.i
Note.s
EndStructure
Dim Guitar.Fretboard(60)
Guitar(0)\String = 1
Guitar(0)\Button = Button1_0
Guitar(0)\Note = "E"
Guitar(1)\String = 1
Guitar(1)\Button = Button1_1
Guitar(1)\Note = "F"
(edit , was wrong...)
Re: wat is the best way to store static data
Posted: Sat Mar 30, 2019 10:59 pm
by droadje
infratec wrote:Or, when it fits your problem, use a map with the note as key
and store the string and the button in a structure of a list below.
Then you can find the note element and use foreach for all pressed keys.
Code: Select all
Structure StringButtonStructure
String.i
Button.i
EndStructure
Structure NoteMapStructure
List StringButtonList.StringButtonStructure()
EndStructure
NewMap NoteMap.NoteMapStructure()
If Not FindMapElement(NoteMap(), "E")
AddMapElement(NoteMap(), "E")
EndIf
AddElement(NoteMap()\StringButtonList())
NoteMap()\StringButtonList()\String = 1
NoteMap()\StringButtonList()\Button = 1
AddElement(NoteMap()\StringButtonList())
NoteMap()\StringButtonList()\String = 3
NoteMap()\StringButtonList()\Button = 1
AddElement(NoteMap()\StringButtonList())
NoteMap()\StringButtonList()\String = 4
NoteMap()\StringButtonList()\Button = 1
If Not FindMapElement(NoteMap(), "F")
AddMapElement(NoteMap(), "F")
EndIf
AddElement(NoteMap()\StringButtonList())
NoteMap()\StringButtonList()\String = 2
NoteMap()\StringButtonList()\Button = 3
AddElement(NoteMap()\StringButtonList())
NoteMap()\StringButtonList()\String = 5
NoteMap()\StringButtonList()\Button = 1
AddElement(NoteMap()\StringButtonList())
NoteMap()\StringButtonList()\String = 6
NoteMap()\StringButtonList()\Button = 1
If FindMapElement(NoteMap(), "E")
ForEach NoteMap()\StringButtonList()
Debug MapKey(NoteMap()) + " - " + Str(NoteMap()\StringButtonList()\String) + " - " + Str(NoteMap()\StringButtonList()\Button)
Next
EndIf
Busy last hour to try to learn map, list, array and structure, but find it verry difficult.
I think your solutions does not work for me, because there are multiple same notes and i think the map element must be unique?.
Re: wat is the best way to store static data
Posted: Sat Mar 30, 2019 11:15 pm
by infratec
But now, I want to be able to show for example all E notes on the fretboard
With this map you can show all stuff for the note 'E'. As requested.
But as I told you, I don't know exactly what you want.
Re: wat is the best way to store static data
Posted: Sun Mar 31, 2019 12:18 am
by droadje
Ok, played with your examples, but find it complex for a beginner.
Think i go with this as i can find de string (1 to 6 ) in the name ( Buton1_4 = on string one)
Code: Select all
NewMap Fret.s()
#String1
Fret("Button1_0") = "E"
Fret("Button1_1") = "F"
Fret("Button1_2") = "F#"
Fret("Button1_3") = "G"
Fret("Button1_4") = "G#"
Fret("Button1_5") = "A"
Fret("Button1_6") = "A#"
Fret("Button1_7") = "B"
Fret("Button1_8") = "C"
Fret("Button1_9") = "C#"
Fret("Button1_10")= "D"
Fret("Button1_11")= "D#"
Fret("Button1_12")= "E"
#string2
Fret("Button2_0") = "B"
Fret("Button2_1") = "C"
Fret("Button2_2") = "C#"
Fret("Button2_3") = "D"
Fret("Button2_4") = "D#"
Fret("Button2_5") = "E"
Fret("Button2_6") = "F"
Fret("Button2_7") = "F#"
Fret("Button2_8") = "G"
Fret("Button2_9") = "G#"
Fret("Button2_10")= "A"
Fret("Button2_11")= "A#"
Fret("Button2_12")= "B"