Menu

Does your "roadmap" include UserExits, Callbacks for some statements?

2016-05-31
2016-06-04
  • Kenneth Wayne Boyd

    By way of background, I've been looking at some of the "lost music" that was created in the early days of PC's by use of the BASIC PLAY statement. It's great to now have PC-BASIC available to listen to some of these tunes.

    I've experimented with some "conversion" programs that convert various text-based music formats into "ABC Notation". Once in ABC Notation, sheet music can be printed. One of those text-based music formats is obviously BASIC PLAY. Many BASIC PLAY strings are straightforward, however some PLAY strings are created programatically and are not represented by any constant string in the BASIC source code.

    One thing that would be very valuable would be to be able to programatically subscribe to PLAY statement strings, and also PRINT statement strings (with fully evaluated expressions.)

    Is perhaps such an extension in your roadmap for PC-BASIC?

    Thanks again for a great program.

    Ken

     
  • Rob Hagemans

    Rob Hagemans - 2016-05-31

    Hi Ken,

    I’m not sure I understand exactly what functionality you’re looking for – are you looking to output the PLAY strings to a text file? In that case I would suggest replacing the PLAY statements with PRINT statements; you can either use PRINT# to write to a file you open from BASIC, or you can capture the text output to the screen with the output option, either from the Windows command prompt or from the configuration file PCBASIC.INI (see the documentation for details).

    For example, you could run PC-BASIC from the C:\> prompt as follows:

    C:\Program Files\PC-BASIC\pcbasic.exe --output=notes.txt
    

    and all PRINTed strings will be recorded in notes.txt.

    Note that I’m generally not keen on extending the BASIC syntax – my focus with PC-BASIC is to be 100% compatible with GW-BASIC; building extensions deflects time from that and could even break compatibility with some programs. However, what I think you’re looking for can be done through the existing interface with some tweaks to your program.

    Hope this helps,
    Rob

     
  • Anonymous

    Anonymous - 2016-06-02

    Thanks Rob. I didn't do a good job of explaining the request, sorry about that.

    I agree with your view of not changing the BASIC syntax!!

    And I also agree that getting the PLAY strings by changing the BASIC source code is possible.

    The request is a different scenario:
    The user is not a progammer, but is a person interested in music, and sheet music.
    The user uses a program, such as "EasyABC" (A Python based GUI for managing and displaying music based on ABC formatted text files.)
    * The EasyABC program has been enhanced with a "plug-in" structure where specific conversion programs (Python) can be added to EasyABC that convert other text based music formats into ABC.
    * For Example [Menu-File-Import] EVRONWRD.PLAYSTRING
    * EasyABC calls a Python "plug-in" that Reads BASIC PLAY strings and converts them to ABC format, which are then edited as normal in EasyABC.
    * There are a lot of text based music notation schemes out there... Hypercard, gaming systems, etc.

    Hopefully I described the above in a sensible way.

    So one problem with the above scenario, is that the "EasyABC with Plun-ins" user is not a progammer, but knows (or remembers) various BASIC progams that played music.
    It might be neat if a EasyABC plug-in could be written that allowed something like:
    * [Menu-File-Import] EVRONWRD.BAS
    * The python plug in started PC-BASIC running ERVONWRD.BAS
    * As PCBASIC encountered BASIC PLAY strings it processed them as always and played the music
    * PCBASIC operates unmodified as it always does... BUT
    * An extenstion to PCBASIC allowed the EasyABC plug in to set up "callback" (or whatever is the right term) functions that called functions for specified BASIC instructions.
    * Conceptually the EasyABC Plugin Python code would ask PCBASIC to have exits/callbacks/intercepts for a few BASIC instructions:
    * PLAY
    * PRINT
    * SYSTEM?
    *After the user finished interacting with the BASIC program through PC-BASIC (everything as usual) then the EasyABC would convert the text strings provided in the call back into ABC music format with music, potentially as guess at lyrics, and comment fields with the original source data.
    * The EasyABC user does not have to be a programmer to convert BASIC music into ABC music.. and through EasyABC then convert the music to sheet music or MIDI files.

    This still may be an outlandish request, but hopefully it's more clear as to what I was asking about.

    Thanks for reading such a long post.

    Ken

     
    • Rob Hagemans

      Rob Hagemans - 2016-06-03

      Hi Ken, thanks for the explanation. I have to say it seems to be a rather large project to enable something like that and not something I'd currently want to focus on with PC-BASIC. Programs with menu interfaces and apps focussed on non-programmers tend to take a lot of developer and subsequent support effort, and I simply don't have the time at the moment - especially as PC-BASIC's implementation of BASIC itself still needs so many improvements...

      Of course, if someone else with a knowledge of Python wanted to build something like that, my code is open and perfectly free to use; I imagine they could start by trying to import the main class from the development source of PC-BASIC and build a child class implementing different behaviour for PLAY. If specific improvements are needed to PC-BASIC along the way then I could merge them back into the main source.

       
  • Kenneth Wayne Boyd

    Thanks Rob. Perfectly understandable.
    Again, thanks for a great program, I've been enjoying running some of the "oldies but goodies!" :)

     
    • Rob Hagemans

      Rob Hagemans - 2016-06-03

      I am wondering if perhaps it would be something to have a location for people to share GW-BASIC programs (music, graphics, games...). There's a lot to go around but it is not easy to find online, since at the time we had to rely on print magazines and swapping floppies rather than the internet. I get the impression that so many people have collections of BASIC code that aren't accessible to others (I do!) and it would somehow be cool to share all that. (Now most of it was never properly licensed even if the authors didn't mind it being copied, which is more of an issue in this copyright-crazy time, but it's hard to imagine that anyone would suddenly mind this being available)

       
  • Kenneth Wayne Boyd

    That's a great idea. And maybe a spot to consolidate links. As I'm collecting links in my search for BASIC music, I'll take some notes and check back in.

    Regarding the "call-backs" notion...

    These functions seem to be related concepts:

    • A programming IDE debugger that allows "break points" to be inserted in the code?
      • When the "Instructioni Pointer" points here, then intercept out....
        Did GWBASIC's IDE allow setting break points or did it just have "TR ON/OFF"
    • An event based object/programming model.
      For example a HTML DOM allows event based functions
      i.e. a jsquery function:
      // Do something when a "checkbox" is changed in the document
      $(document).on('change' , ':checkbox' , function() {
      // do stuff
      }

    So, in some way I'm thinking of the BASIC program as an object with a desire to call functions when events happen in managing that object... switching syntax from python to js for a moment, I'm wanting to write a function like this:
    // Do something when PLAY is encountered
    $(basicprogram).on('start', ":PLAY", function() {
    // the processor of the object keeps processing the object, the BASIC program
    // but it in parallel, calls this function
    var vbplaystring = $(PLAY).playstring();
    // do stuff with the play string
    }

    Maybe the hooks into an interpreter that provide "debugging" (i.e. break points, etc.) also set up an capability of calling other programs when those events happen.

    Anyway, just ruminating around my fringe PLAY music notions.

    Ken

     

    Last edit: Kenneth Wayne Boyd 2016-06-04
    • Rob Hagemans

      Rob Hagemans - 2016-06-04

      As to the question about the GW-BASIC environment: TRON and TROFF, EDIT and AUTO were about as good as it got when it came to "IDE" features. You could of course use STOP and CONT to set something like breakpoints.

      I'm currently going through a thorough refactoring of PC-BASIC's code - you'll notice that the master branch in the repository has much cleaner code than the release version. It's still quite buggy, though, and test coverage is not nearly where it should be. However, this design should make PC-BASIC easier to extend or incorporate in other projects. The public Python API that's emerging is basically something like this:

      import pcbasic
      
      with pcbasic.Session() as session:
          session.execute("A=5")
          session.execute("PRINT A")
          a = session.get_variable("A!")
      

      which should allow for integration into other Python programs. I don't have an extension API like you suggest though - to change behaviour you'd need to override methods like Session.parser.statements.exec_play, but I'm not ready to commit to that as a stable public API for now :)

      Rob

       

      Last edit: Rob Hagemans 2016-06-04
  • Wengier

    Wengier - 2016-06-04

    Hi Rob,

    I think it is a good idea to have a location for people to share GW-BASIC programs. With these programs available more people will be interested in the PC-BASIC project as well.

    Wengier

     
    • Rob Hagemans

      Rob Hagemans - 2016-06-04

      I agree - do you know a good way to set this up? It'll need some moderation to fend off the spammers, but on the other hand it shouldn't become a time sink...

      I think I might just set up a separate repository on GitHub with some sample BASIC files, and people who want to add programs can become a collaborator on that repo.

      Let me know your thoughts/ideas

      Rob

       
      • Wengier

        Wengier - 2016-06-04

        One approach that is in practical use is to make a sub-forum to share GW-BASIC programs. This approach is used by for example the QB64 project. However, personally I prefer a direct link on the top of the PC-BASIC main page (http://robhagemans.github.io/pcbasic/) for program sharing. Ideally the user will be able to share a GW-BASIC program either by uploading a GW-BASIC program file or by pasting the code of a GW-BASIC program directly. To fend off the spammers, I think it is relatively easy to be done for the purposes of GW-BASIC programs, since it is not really difficult to check the uploaded code is in fact a GW-BASIC program. For example, the system can simply reject an upload from the user if it finds that the code does not start with a line number in each line of the program, or if the program contains unknown commands. Even more can be done such as syntax checking to tell the user that the program he or she is uploading will not run correctly, so he/she should make necessary changes to the program and try to share it again. By doing this we probably don't need to spend too much time to manually check each program that has been upload either. Hope this will be useful.

        Wengier

         
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.