wat is the best way to store static data

Just starting out? Need help? Post your questions and find answers here.
droadje
User
User
Posts: 12
Joined: Thu Mar 28, 2019 6:02 pm
Location: Netherlands, Ter Apel
Contact:

wat is the best way to store static data

Post 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 ?
infratec
Always Here
Always Here
Posts: 7777
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: wat is the best way to store static data

Post by infratec »

Code: Select all

GetGadgetText()
:?:

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.
infratec
Always Here
Always Here
Posts: 7777
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: wat is the best way to store static data

Post by infratec »

Maybe a structure like

Code: Select all

Structure
  String.i
  Button.i
  Note$
EndStructure
infratec
Always Here
Always Here
Posts: 7777
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: wat is the best way to store static data

Post 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
droadje
User
User
Posts: 12
Joined: Thu Mar 28, 2019 6:02 pm
Location: Netherlands, Ter Apel
Contact:

Re: wat is the best way to store static data

Post by droadje »

infratec wrote:

Code: Select all

GetGadgetText()
:?:

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...
droadje
User
User
Posts: 12
Joined: Thu Mar 28, 2019 6:02 pm
Location: Netherlands, Ter Apel
Contact:

Re: wat is the best way to store static data

Post 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...)
droadje
User
User
Posts: 12
Joined: Thu Mar 28, 2019 6:02 pm
Location: Netherlands, Ter Apel
Contact:

Re: wat is the best way to store static data

Post 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?.
infratec
Always Here
Always Here
Posts: 7777
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: wat is the best way to store static data

Post 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.
droadje
User
User
Posts: 12
Joined: Thu Mar 28, 2019 6:02 pm
Location: Netherlands, Ter Apel
Contact:

Re: wat is the best way to store static data

Post 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"
Post Reply