Examples Please?

Where can I find useful examples of functions and the scripting language in general?

There is this blog post:
https://gigperformer.com/the-gpscript-programming-language/

On the online manual:
https://gigperformer.com/docs/Userguide36/gpscriptintro.html

1 Like

I have read the documentation and only a few of the functions come with examples. Each GP function should have at least one example of how to use the function.

For example, I see on the following statement ā€œon NoteEvent(m : NoteMessage) from M1ā€ where ā€œmā€ is the notes that were just played on the NoteEvent Callback ā€¦ what I would like to see in the documentation is an example: how I can:

1)  grab the individual notes out of "m" and place them into an array so I can - 
1) manipulate and add to them and then send them back out.
1 Like

Most of my learning of gp script came from simply reviewing the function list:
https://gigperformer.com/downloads/GPScript/SystemFunctionList.html

For example, the ā€˜MIDIā€™ and ā€˜Systemā€™ sections should include everything relevant for processing the midi message you receive in the On NoteEvent callback.

Otherwise, searching one of these functions in the forum will usually bring up a lot of nice examples.

Thatā€™s probably not going to happen, certainly not in the short term. GP Script is intended for advanced users who are already familiar with programming concepts (e.g, variables, types, statements, functions) and the documentation is intended to be a reference manual, it is not intended to be a tutorial or to teach people programming. Our assumption is that anyone familiar with these concepts will be able to browse the list of system functions to find what they need so as to create a solution for their particular needs, as @rank13 already observed.

There are arbitrary possible examples, and no matter what we might include, someone will want something else. For example, if I was going to include an example of how to use the NoteEvent callback, I would have probably just shown how to transpose an incoming message. That would provide absolutely no help to someone wanting to know how to put messages into an array.

The whole purpose of this ā€œScripting with Gig Performerā€ category is so that people can help each other with particular problems that need to be solved.

ā€œmā€ represents a single message as described in the documentation. There canā€™t be more than one note message in such a callback.

screenshot_4869

1 Like

By the way, there are quite a few built in objects such as the NoteTracker which might be useful.

Also, there are significant improvements in the GP4 version of GP script which will be helpful as well.

Really? :stuck_out_tongue_winking_eye:

2 Likes

I meant to GP Script

I can respect you saying, ā€œit is not intended to be a tutorialā€¦ā€. No one expects you to teach programming nor write scripts. Just a one or two-line example for each function placed right below the syntax would be nice and clear up a lot of questions. If you were to add more code template blocks accessible in the editor in addition to the very basic ones you have now, it would be greatly appreciated.

As for my example regarding ā€œm(NoteMessage)ā€ ā€¦ I would just like clarification of what the primitive ā€œmā€ is? Is ā€œmā€ a string, array[1], array[2], vcar, etc. ā€¦ also maybe just two lines of code showing how to use ā€œmā€ or how to cast it to another useful object.

If you canā€™t afford the time to do short examples for functions, would you consider reserving a searchable file section where people can place their scripts. For the most part, I feel guilty about asking for help on my scripts ā€¦ but as long as the community can tolerate my questions, I will go this route. :slight_smile:

2 Likes

ā€¦ For the most part, I feel guilty about asking for help on my scripts ā€¦ but as long as the community can tolerate my questions, I will go this route.

Just go ahead and askā€¦ the worst case could be that you wonā€™t get an answer - which i honestly doubt! :slight_smile:

2 Likes

There is already:

And there will be some moreā€¦

Edit: thatā€™s is you can do a search in this categorie.

To be honest, i am missing those ā€œshort examplesā€ too in the docs, but i can also see the point of our devsā€¦
I could imagine that maybe a ā€œWikiā€ system could be helpful for thisā€¦ so the users could write their own examples and maybe one day, those code snippets could become part of the ā€œrealā€ manualā€¦ just thinking. :slight_smile:

4 Likes

Me too! :nerd_face:

1 Like

Did you notice that when you do a right click (Win) when in the script editor, you can choose among many code templates and example? With this and the documentation there are a lot of possibilitiesā€¦

Donā€™t feel guilty, and ask, thatā€™s the purpose of a community forum :wink:

If you refer to e.g. this in the manual:

It means that the type of m is NoteMessage. So what is a NoteMessage, wellā€¦ as you can imagine, it is a MIDI message representing a single note.

3 Likes

Yeah, weā€™ve tried hard to use clear names (even if theyā€™re long) for types and functions so as to make them be self-documenting.

ā€œGP Script is intended for advanced users who are already familiar with programming conceptsā€

I would be grateful for someone to point me in the direction of what programming concepts are required and what to learn to become an advanced user.

Thatā€™s a great question. There are so many online tutorials as well as books out thereā€¦and while many languages are technically similar under the covers, the ones you must frequently see today are (IMO) far more complicated to learn than they ought to be.

For what itā€™s worth, I used the concepts in languages like Pascal, Algol when I designed GP Script. These are really old languages (from the '60s and '70s) but Pascal in particular was originally designed as a teaching language so following a beginning tutorial on Pascal might be easier than dealing with languages like Javascript or C/C++ etc.

Perhaps take a look perhaps at this:

The basic concepts such as data types, variables, decision making, loops, functions are extremely similar to what you see in GP Script.

2 Likes

I know m is a NoteMessage ā€¦ and I know what a NoteMessage should contain. I just donā€™t know how to parse it because itā€™s properties are not discussed and defined in the language syntax. EG: How does one access and/or change the velocity, channel, aftertouch or note value in the NoteMessage?

1 Like

As I mentioned above, I was able to look through the function list to find what I needed. The MIDI section is the exhaustive list of everything thatā€™s available:
https://gigperformer.com/downloads/GPScript/SystemFunctionList.html

e.g. to extract the channel number:

GetChannel : Returns the MIDI channel number (between 1 and 16) of any MIDI message

  • Declaration: function GetChannel (m : MidiMessage) Autotype returns Integer

To edit the channel number:

WithChannel : Changes the channel number of any MIDI event.

  • Declaration: function WithChannel (m : MidiMessage, channel : int) autotype returns MidiMessage

This is good to know, however following the syntax of ā€œOn NoteOnEvent(m) From SomeMidiInBlockā€ there should be a ā€œsee alsoā€ reference to related functions. This is the proper way to document a language rather than have the user search all the documentation in hopes he will find the specific function he needs.

1 Like