Recent

Author Topic: How to start? Building Music Tablature notation (text\font based)  (Read 6911 times)

itblumi

  • New Member
  • *
  • Posts: 29
Re: How to start? Building Music Tablature notation (text\font based)
« Reply #15 on: November 05, 2022, 02:29:56 am »
Quote
I understand for example that a «string» is something like a one dimensional «array» [«vector»?!] of «objects» or «class»(?) called character\s (code table), represented by glyphs (graphical sub‑objects, assigned to that code table), loaded from PAM (permanent access memory) residing somewhere in RAM (random access memory).

You are right that a <string> is an <array of Char>(dyn array implementation in pascal). The Char is not an object! The Char represent a part of a character set in a codepage like ASCI, ANSI, UTF-8, UTF-16.
This codepage provides the byte length of one character. For Example: ASCII a Char has everytime the length of 1 Byte. UTF-8 a Char can be between 1 and 2 Bytes long.
That's why Mark asked you for this, because it is not easy to convert in such formats with special sets or it can be difficult.
For this reason FPC uses different Char implementatons, like a Char(synonym for AnsiChar) is only 1 Byte long and a WideChar is a UTF-16 char and is 2 Bytes long.
For clearifing the Char or WideChar specify his own simple data type and when a Char in the codepage ASCII has the value 10 then its an "A". Have a look at https://tools.piex.at/ascii-tabelle/

I assume you will write your own Font(-Family), which you will be load and show the notes like a music character set. The font in each programming language is like the visual style to show your character set, but I think you know this. For the developer means it, when you paint this characters on a control/component the Draw function will paint the character-set with the given font-set at this component/control. Each operating system have pre defined functions for this and they are cross-platform availible with FPC.

Objects and Classes

A class is structure defined by the developer. This structure is build to let the envoirment know, how much memory is needed to store all this informations.
In such a class you can define multiple data elements like the duration or a name or whatever you need and you can define methods (procedure or function) todo something with this data. As an Example: a Clear procedure to clear all the data in this class.
With this information you can create an object. The object is the pointer to the memory where all the information is stored.

Simple class example:
Code: Pascal  [Select][+][-]
  1. unit MusicNote;
  2.  
  3. {$mode ObjFPC}{$H+}
  4.  
  5. interface
  6.  
  7. // the uses refere to other classes and implementations which are usefull for us
  8. uses
  9.   Classes, SysUtils, Generics.Collections;
  10.  
  11. type
  12.  
  13.   { TPitch }
  14.  
  15.   TPitch = class(TObject)
  16.     procedure Clear;
  17.   end;
  18.  
  19.   TPitchList = array of TPitch;
  20.   // we can't inherit from an array so we have todo all the work in functions and I think
  21.   // that's not really helpfull, only when we have really large lists to optimize the performance
  22.  
  23.   // we define the class/structure of an object
  24.   TMusicNote = class(TObject)
  25.   public
  26. // How to define a var in a class  
  27. //[Name]: [DataType];  
  28.     Duration: Cardinal;
  29.     Name: string;
  30.     Pitch: TPitchList;
  31.     procedure Clear;
  32.   end;
  33.  
  34.   // define an array of our object with an extra data type to make it easier for the future
  35.   TArrayMusicNote = array of TMusicNote;
  36.  
  37.   // define a generic list of TMusicNote
  38.   TSMusicNoteList = specialize TObjectList<TMusicNote>;
  39.  
  40.   //with the generic list we can inherite from it and write extra functions and more data elements if needed
  41.   TMusicNoteList = class(TSMusicNoteList)
  42.   public
  43.     // we use our clear example again
  44.    procedure ClearData;
  45.    // you can also define a methode to calc your pitch (I hope I understood it right)  
  46.    procedure CalcPitch;
  47.   end;
  48.  
  49.  
  50.   procedure Example;
  51.  
  52. implementation
  53.  
  54. procedure Example;
  55. var
  56.   ANoteList: TMusicNoteList;
  57.   ANote: TMusicNote;
  58. begin
  59.   // lets create in the first an object of our music notes
  60.   // we use True as a parameter so the generic list will free the memory of our objects
  61.   // when we clear or destroy(free) it
  62.   ANoteList := TMusicNoteList.Create(True);
  63.   try
  64.     // now our list of objects is initialized and we can do something with it
  65.     // here I will show to create an element of our list and put it in the list
  66.     ANote := TMusicNote.Create;
  67.     ANote.Duration := 5;
  68.     ANote.Name := 'example_name';
  69.     ANoteList.Add(ANote);
  70.   finally
  71.     // at the end of the example we have to clear the memory to avoid memory leaks
  72.     // we don't have to free each object in the generic list, because the list
  73.     // will do it for us
  74.     FreeAndNil(ANoteList);
  75.   end;
  76. end;
  77.  
  78. // here are the implemntation of methods of our classes
  79.  
  80. { TPitch }
  81.  
  82. procedure TPitch.Clear;
  83. begin
  84.   // do something usefull
  85. end;
  86.  
  87. procedure TMusicNote.CalcPitch;
  88. begin
  89.   // do what you need todo
  90. end;
  91.  
  92. procedure TMusicNote.Clear;
  93. var
  94.   i: Integer;
  95. begin
  96.   //lets clear all data
  97.   Duration := 0;
  98.   Name := '';
  99.   // the array doesnt have a clear function so we need todo it here or define it
  100.   // in a helper class
  101.   for i := 0 to High(Pitch) do
  102.     Pitch[i].Clear;
  103. end;
  104.  
  105. procedure TMusicNoteList.ClearData;
  106. var
  107.   i: Integer;
  108. begin
  109.   // we need to clear each element in the list, so we use a for loop.
  110.   // Each list will start with the element index 0 and we need to stop before the count is reached (Count - 1)
  111.   // Self is used to to show that we use our own object data. In some cases you don't need to use Self, but in other cases you have
  112.   // to use Self for this example I will use everytime Self so its easier
  113.   for i := 0 to Self.Count - 1 do
  114.   begin
  115.     // we need to call the Clear function of each object in the list Self[INDEX] will give us this object
  116.     Self[i].Clear;
  117.   end;
  118. end;
  119.  
  120.  
  121.  
  122. end.
  123.  

You described your pitch like a list of another class, so you have many options to create such a list.
As an <Array of TPitch> = dynamic array of a class or
as a generic list "TObjectList<TPitch>" the generic list have allready implementations of several functions which the array doesn't have and makes it easier to handle them,
but is it slower as an array. As long as you don't have more then 1000 objects in such a list you will not notice so much of a difference and you should have less to implement by your self.

I hope this will help you geting started
« Last Edit: November 05, 2022, 05:06:49 am by itblumi »
Jan

Delphi XE6, Lazarus 2.2.4, Visual Studio, Eclipse
Platforms: Ubuntu 22.10, Windows 7, 10
Progarmming languages: Pascal, C, C++, C#, Java

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12571
  • FPC developer.
Re: How to start? Building Music Tablature notation (text\font based)
« Reply #16 on: November 05, 2022, 09:58:43 am »
In short, the Pascal char (char which can be ansichar or wide/unicodechar) is the granularity of the encoding. (a one byte or a two byte encoding).

But printable characters can be multiple such units. On systems with denormalized notation, that can happen for all non trivial letters including basic Western European accents, so it can't be ignored.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8515
Re: How to start?
« Reply #17 on: November 05, 2022, 10:03:56 am »
I don't really know where to start here. I think that there's a real problem that the broader Pascal community now comprises people who've been using it for years, and it might even be that the language and tools are basically impenetrable for an absolute beginner.

Pascal was invented by Niklaus Wirth in the 1970s, after some unpleasant political wrangling related to the "grandfather of most current languages", ALGOL. It was popularised by implementations called UCSD Pascal and Turbo Pascal, both of which left their marks in the syntax and library routines. The Turbo Pascal dialect later became Object Pascal.

FPC is a compiler for Object Pascal (plus support for alternative modes). Lazarus is a RAD (Rapid Application Development) IDE (Integrated Development Environment), and is a open-source mimic of Delphi which was a successor product to Turbo Pascal.

While comparatively little used these days, Pascal has contributed features adopted by most other ALGOL-derived languages: even where the practitioners of those languages have been openly dismissive of Pascal as a language. The gradual loss of influence that Pascal has experienced has been painful, but that pain has been miniscule compared with that experienced by- in particular- the C community which has been forced to retrofit features and coding practices that should have been designed into them in the first place.

Pascal is what is known as a block structured language. All code is in a block, all variables etc. that it uses must be declared before the start of that block:

Code: Pascal  [Select][+][-]
  1. program something;
  2.  
  3. var
  4.   fred: integer;
  5.  
  6. begin
  7.   fred := 42;
  8.   WriteLn('Hello, World!');
  9.   WriteLn('Today fred is ', fred)
  10. end.
  11.  

The variable fred is an integer, which means that it may be assigned numbers from an implementation-defined range. The example above should compile, as should the one below:

Code: Pascal  [Select][+][-]
  1. program something;
  2.  
  3. var
  4.   fred: integer;
  5.   message: string;
  6.  
  7. begin
  8.   fred := 42;
  9.   message := 'Hello, World!';
  10.   WriteLn(message);
  11.   WriteLn('Today fred is ', fred)
  12. end.
  13.  

However this won't compile:

Code: Pascal  [Select][+][-]
  1. program something;
  2.  
  3. var
  4.   fred: integer;
  5.   message: string;
  6.  
  7. begin
  8.   message := 42;
  9.   fred := 'Hello, World!';
  10.   WriteLn(message);
  11.   WriteLn('Today fred is ', fred)
  12. end.
  13.  

The problem there is that message has been declared as a string but you're assigning a number to it, and fred has been declared as an integer but you're assigning literal text to it. The reason that won't work is that Pascal has always had strong type checking, and while it might not look like it that can, in fact, save you a great deal of work: not so much when coding, but definitely when debugging and testing.

Clear so far?

MarkMLl
« Last Edit: November 05, 2022, 10:20:12 am by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Emptyself

  • New Member
  • *
  • Posts: 39
Re: How to start? Building Music Tablature notation (text\font based)
« Reply #18 on: November 05, 2022, 10:19:57 am »
You described your pitch like a list of another class, so you have many options to create such a list.
As an <Array of TPitch> = dynamic array of a class or
as a generic list "TObjectList<TPitch>" the generic list have already implementations of several functions which the array doesn't have and makes it easier to handle them,
but is it slower as an array. As long as you don't have more then 1000 objects in such a list you will not notice so much of a difference and you should have less to implement by your self.

I hope this will help you getting started.

Thank you for taking time to explain all this. It might take me a few weeks to decipher its meaning.
How was I supposed to figure this out from tutorials about indexing arrays, "moving" circle on the screen, etc.

Actually, it does not need to be a «font family». I use a Font Editor solely because of that «anchor marks» functionality, where the user can combine\attach two (or more) glyphs together → useful for attaching stems, flags, beams to the base symbol (glyph), which represents the name of the note (at least in my Music notation).

Somehow, my ignorant mind assumed that I could simply «open» this font in Lazarus and it will fall in perfect 1:1 communication with the code about moving\typing the «notes» across the screen. Yes, I really thought in such a way!

I an really not sure what you refer to by saying:
Quote
As long as you don't have more then 1000 objects…
Is this the count of the symbols on the screen when I use the «program» i.e. English alphabet has 26 letters, but when I open a browser I can see hundreds of them on a web page (well, depends on the «zoom» factor) or is it about the «objects» defined in the code in Pascal\LazarusIDE?

Most likely you "facepalm" reading this, but that is how ignorant am I, despite the fact I have seen a few tutorials abut coding and repeated some of the "simple" exercises.  :-\

Emptyself

  • New Member
  • *
  • Posts: 39
Re: How to start?
« Reply #19 on: November 05, 2022, 10:45:18 am »
However this won't compile:

Code: Pascal  [Select][+][-]
  1. program something;
  2.  
  3. var
  4.   fred: integer;
  5.   message: string;
  6.  
  7. begin
  8.   message := 42;
  9.   fred := 'Hello, World!';
  10.   WriteLn(message);
  11.   WriteLn('Today fred is ', fred)
  12. end.
  13.  

The problem there is that message has been declared as a string but you're assigning a number to it, and fred has been declared as an integer but you're assigning literal text to it.
Clear so far?

MarkMLl

Yes, I think I understand those concepts. I think my general problem with learning 'computer languages' is that I am notoriously bad at following instructions and at the same time giving (proper) instructions… that is to people, co‑workers, etc. because I always ask "why in such a way?", "who says so?", etc. and this has been a problem since… childhood.
My thinking (as a process) is hardly ever methodical. I think logically (I hope so) but would not say 'abstract' and they say coding is mostly layered sets of abstractions like a «russian doll» but in 4D and above.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8515
Re: How to start? Building Music Tablature notation (text\font based)
« Reply #20 on: November 05, 2022, 11:37:19 am »
Somehow, my ignorant mind assumed that I could simply «open» this font in Lazarus and it will fall in perfect 1:1 communication with the code about moving\typing the «notes» across the screen. Yes, I really thought in such a way!

That's a point I tried to make earlier: the font has to be compatible with the OS (Operating System) you're using, and I suspect that the anchor point facility that you're using is either intended for the use of the font editor you've got or alternatively that it might not be supported across all possible OSes.

Quote
I an really not sure what you refer to by saying:
Quote
As long as you don't have more then 1000 objects…

Assume for the moment that he means an implementation detail. Over the century-long history of computing (i.e. from the Hollerith card era onwards) there have been a lot of data structures developed, and they are almost all applicable to some optimal number of elements and some relative number of writes and reads.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

MarkMLl

  • Hero Member
  • *****
  • Posts: 8515
Re: How to start?
« Reply #21 on: November 05, 2022, 11:41:58 am »
Yes, I think I understand those concepts. I think my general problem with learning 'computer languages' is that I am notoriously bad at following instructions and at the same time giving (proper) instructions… that is to people, co‑workers, etc. because I always ask "why in such a way?", "who says so?", etc. and this has been a problem since… childhood.
My thinking (as a process) is hardly ever methodical. I think logically (I hope so) but would not say 'abstract' and they say coding is mostly layered sets of abstractions like a «russian doll» but in 4D and above.

Right, I'll try to continue that later. However you have to assume that there is a "right sequence" to understand this sort of thing, and that that sequence has been arrived at largely by trial and error over an extended period.

I warn you in advance: I'm busy, and while I'm prepared to play the "who says so?" game I'm likely to do so by pointing you at reference material and universally-agreed authorities: if you don't do your homework by following up references and then demonstrating that you understand what you've read I'll walk. Understand? :-)

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

440bx

  • Hero Member
  • *****
  • Posts: 5896
Re: How to start? Building Music Tablature notation (text\font based)
« Reply #22 on: November 05, 2022, 12:11:11 pm »
My computer programming competency is just between "Hello, World!" and the «;» at the end (at least in most coding languages… not Python).
From what you describe, I'd say the program you want to write is no "beginner project", therefore programming skills that can be sandwiched between a closing quote and a semicolon are unlikely to be sufficient.

I suggest that the first thing for you to do is to acquire a reasonably good command of the Pascal language. Personally, for pure Pascal, I recommend Doug Cooper's "Oh! Pascal", the explanations about Pascal are excellent and they are topped with excellent programming-in-general advice.  That would be "step 1."  The book is old and can usually be had for just a few bucks including shipping.

Step 2. would be for you to identify any other areas where your knowledge needs to be improved and proceed accordingly.

I understand the above is very generic "advice" but, you will need a reasonably good Pascal foundation to be able to understand the solutions that forum members offer to you.  Without it, success is not a likely outcome.

HTH.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Emptyself

  • New Member
  • *
  • Posts: 39
Re: How to start? Building Music Tablature notation (text\font based)
« Reply #23 on: November 05, 2022, 12:19:45 pm »
I can promise, I will at least try to understand.

I also have found some tutorials on YouTube, where programmers make pseudo‑3D objects rotate, scaled etc. using ASCII characters… the so called «ASCII art». To me those seems more like a 'show off' exercise, but I have found them more "comprehendible" in terms of abstract logic.

But at the end of the day coding is another form of art. The same way I can not 'paint a drawing' or 'break dancing', 'cook or decorate food' or 'play harp'… the same way I might not be gifted at coding.
Or get way below 'mediocre' at it.  :'(

440bx

  • Hero Member
  • *****
  • Posts: 5896
Re: How to start? Building Music Tablature notation (text\font based)
« Reply #24 on: November 05, 2022, 01:08:53 pm »
But at the end of the day coding is another form of art. The same way I can not 'paint a drawing' or 'break dancing', 'cook or decorate food' or 'play harp'… the same way I might not be gifted at coding.
Or get way below 'mediocre' at it.  :'(
Careful... don't make that assumption.  I have found that quite a few people who thought they were terrible in math were actually reasonably good at it... the  problem wasn't them... the problem was the source of the "explanations" they were getting.

Ask a lot of "mathematicians" why - 1 * - 1 = + 1 and you often get some rather "peculiar" answers but, the mathematicians who know why can give you an answer you will instantly understand and never forget (because you understand why too and, it is not possible to forget something you understand.)

That's why I recommended that book... if you read that book and you find that you're not understanding then maybe you're right, but, don't reach that conclusion from pure speculation.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Emptyself

  • New Member
  • *
  • Posts: 39
Re: How to start? Building Music Tablature notation (text\font based)
« Reply #25 on: November 05, 2022, 01:41:34 pm »
That's why I recommended that book... if you read that book and you find that you're not understanding then maybe you're right, but, don't reach that conclusion from pure speculation.

I found 2nd edition of that book you recommend online as a 'scanned to pdf'. Hope it could be helpful and relevant.
And just ordered the 3rd Edition:
Quote
"Oh! PASCAL" by Doug Cooper, Michael Clancy
W.W.Norton & Co Ltd, 03/19/1993. Paperback. Used (Good condition);
£3.99


Thank you for the recommendation.  :)I downloaded some other books I found online as well regarding Pascal.

Emptyself

  • New Member
  • *
  • Posts: 39
Re: How to start? Building Music Tablature notation (text\font based)
« Reply #26 on: November 05, 2022, 02:09:09 pm »
I've got my own view on why -1 * -1 = +1 (oops, technically it is +1²)
I think of it as orientation. Negative numbers do not exist, as negative space does not either.
Thus -1 is just a real length but in opposite orientation to my current orientation of measurement.
But still multiplying it will result in a real area "just right behind my back".
There is no 0 point in Space. 0 is just the arbitrary origin of the «current partial space system».

In a similar way I think about the "space" between 0~1 on one hand and 1~∞ on the other.
They are the same, but the scale factor is my unit of "1" «whole».
It has nothing to do with "01" counting system (binary), where those are just marks, tags, index of condition.
The same way I could put a label "0" to any of my real items. That item won't vanish because of it all of a sudden.
« Last Edit: November 05, 2022, 05:19:33 pm by Emptyself »

440bx

  • Hero Member
  • *****
  • Posts: 5896
Re: How to start? Building Music Tablature notation (text\font based)
« Reply #27 on: November 05, 2022, 03:09:05 pm »
I've got my own view on why -1 * -1 = +1 (oops, technically it is +1²)
I think of it as orientation. Negative numbers do not exist, as negative space does not either.
Thus -1 is just a real length but in opposite orientation to my current orientation of measurement.
But still multiplying it will result in a real area "just right behind my back".
There is no 0 point in Space. 0 is just the arbitrary origin of the «current partial space system».

In a similar way I think about the "space" between 0~1 on one hand and 1~∞ on the other.
They are the same, but the scale factor is my unit of "1" «whole».
It has nothing to do with "01" counting system (binary), where those are just marks, tags, index of condition.
The same way I could put a label "0" to any of my real items. It won't vanish because of it all of a sudden.
Fortunately, it's a lot simpler than all that and, - 1 * - 1 is definitely not +1², even though numerically it is but, geometrically, it definitely isn't.

The 5th Chapter of the videos found at http://www.dimensions-math.org/Dim_tour_E.htm will show you exactly why and once you see it, it will be obvious.  I highly recommend watching that Chapter (not that the other chapters aren't excellent too.)

If you're inclined, you can watch the other Chapters, lots of very interesting stuff and, if you like M.C Escher's work, you'll find the math that flowed out of his imagination onto paper.  Great stuff.

The math presented in one of the episodes was used by Swedish (if memory serves) mathematicians to complete M.C Escher's Print Gallery. 

Anyway... I pleased you found a copy of Oh! Pascal... I believe it's quite likely you'll enjoy it.


FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Emptyself

  • New Member
  • *
  • Posts: 39
Re: How to start? Building Music Tablature notation (text\font based)
« Reply #28 on: November 05, 2022, 04:45:21 pm »
The 5th Chapter of the videos found at http://www.dimensions-math.org/Dim_tour_E.htm will show you exactly why and once you see it, it will be obvious.  I highly recommend watching that Chapter (not that the other chapters aren't excellent too.)

Oddly enough, I've had all those videos on my old computer hard drive… Great explanations indeed!
I am also regular visitor to Mathologer and 3Blue1Brown channels on YouTube, although many of the subjects are way above my logic's level.
Glad to have found you also have seen those videos!  8-)
Have to refresh my memory and watch them again this evening. Thank you for reminding me!

I will start to read the 2nd Edition of "Oh! Pascal." (.pdf) on the monitor.

440bx

  • Hero Member
  • *****
  • Posts: 5896
Re: How to start? Building Music Tablature notation (text\font based)
« Reply #29 on: November 05, 2022, 11:30:35 pm »
I am also regular visitor to Mathologer and 3Blue1Brown channels on YouTube, although many of the subjects are way above my logic's level.
Those are good :)  I also recommend checking out James Tanton's work on YouTube, if you haven't already.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018