Jump to content
Sign in to follow this  
Yuichi Yamamoto

Multi-thread Programming?

Recommended Posts

Hi, I'm really in love with Opusmodus and first of all, thank you so much for your great app!

Well, though I already enjoy the whole functions and stuff that already exist in the basic Opusmodus, I'm starting to crave for something more advanced: one of such is multi-thread programming. (or is it already supported?) 


So I looked up through the internet and found the "bordeaux-threads" library(https://common-lisp.net/project/bordeaux-threads/), and I did (ql:quickload "bordeaux-threads") and it loads successfully. At least it prompts just like when I load any other no-problem libraries like Drakma.

However, although I DID load the library when I try to use some of the functions from them, it says "undefined function ~" thing. So the loading thing did not go well, I guess.

 

=> So here, I changed my plan.

There was an article in which someone was wrapping the bordeaux-threads in a "defpackage" and then after an "in-package" use the funcitons of them. And actually this works fine in my computer.

But I discovered that inside the package that only contains bordeaux-threads, I cannot use the Opusmodus functions. So I included "Opusmodus" in the package as well.

 

Case closed, I thought.

But though now I get most of the Opusmodus-functions working well, there were still some functions and symbols that weren't acknowledged such as "display-musicxml" and "'atonal" (inside a def-score). I'm guessing this is due to the packaging that I probably did not do correctly?
 

For you information, here is the code.
––––––––––––––––––––––––––––––––––––––

 

(require :bordeaux-threads)

(defpackage :threads-test-pkg
  (:use :cl
        :bordeaux-threads
        :opusmodus
))

(in-package :threads-test-pkg)

(progn
  (format t "# start thread test~%")

  (let* ((test-counter #'(lambda (thread-identifier-num count interval)
                           (let ((*standard-output* #.*standard-output*))
                             (format t "## start-thread: ~s~%" thread-identifier-num)
                             (dotimes (i count)
                               (sleep interval)
                               (format t "### thread ~s --- ~s~%" thread-identifier-num i))
                             (format t "## end-thread: ~s~%" thread-identifier-num))))
         (test-thread-alive-p #'(lambda (thread)
                                  (let ((*standard-output* #.*standard-output*))
                                    (format t "~a: ~a~%" (thread-name thread) (thread-alive-p thread)))))

         ;; Make Threads and Start
         (thd1 (make-thread #'(lambda ()
                                (funcall test-counter 1 5 3))
                            :name "thread 1"))
         (thd2 (make-thread #'(lambda ()
                                (funcall test-counter 2 5 2))
                            :name "thread 2"))
         (thd3 (make-thread #'(lambda ()
                                (funcall test-counter 3 5 1))
                            :name "thread 3")))

    ;; Check the threads
    (funcall test-thread-alive-p thd1)
    (funcall test-thread-alive-p thd2)
    (funcall test-thread-alive-p thd3)

    ;; Wait for the threads to end
    (join-thread thd1)
    (join-thread thd2)
    (join-thread thd3)

    ;; Threads Status
    (funcall test-thread-alive-p thd1)
    (funcall test-thread-alive-p thd2)
    (funcall test-thread-alive-p thd3))

  (format t "# end thread test~%"))

;;Things that works
(gen-integer 10)
(display-midi 'hoge)
;;Things that do not work
(display-musicxml 'hoge)
'atonal ;this symbol was somehow not undefined
 

––––––––––––––––––––––––––––––––––––––

 

I might be doing something way too unnecessary, but please forgive me for all the ignorance.

All I want to do is just to get multi-thread capability along with Opusmodus, in order to achieve some real-time programming.


Thank you,

Yuichi Yogo

 

Share this post


Link to post
Share on other sites

> there were still some functions and symbols that weren't acknowledged such as "display-musicxml" and "'atonal" (inside a def-score)

 

I am not a Opusmodus user (Just a Common Lisper) but IMHO, I think there is Common Lisp PACKAGE and SYMBOL related things like a described below link.

http://www.gigamonkeys.com/book/programming-in-the-large-packages-and-symbols.html


If "display-musicxml" and "atonal" symbols are not exported, You may IMPORT them, like

 

(defpackage :threads-test-pkg
  (:use :cl :bordeaux-threads :opusmodus)
  (:import-from ??? :display-musicxml :atonal))

 

If "display-musicxml" and "atonal" symbols are exported, You may USE-PACKAGE, like

 

(defpackage :threads-test-pkg
  (:use :cl :bordeaux-threads :opusmodus ???))

 

;; How to find the ??? package => (find-all-symbols (string '#:display-musicxml))

 

-- g000001

https://github.com/g000001

Share this post


Link to post
Share on other sites

g000001, Thank you so much for your precise information!
I was reading through a lot of references about the lisp package thing, but actually what I really wanted to know was how to figure out which package a symbol / function belongs to; so "find-all-symbols" was exactly what I needed. I really appreciate it.


Though when I referenced the 'display-musicXML' and 'atonal (symbol), these both belonged to the Opusmodus package itself, but thank you very much to the developers, after updating the app, it all fixed peacefully!

Share this post


Link to post
Share on other sites

Sorry to bring this topic back, but it seems that those symbols for the tone names (such as 'c4, 'ds5 etc.) don't get loaded correctly when I include the Opusmodus package?
Is it only me?
 

P.S. It happend when I tried to evaluate "vector-to-pitch" or "ambitus" with the arguments of '(c4 c6) and it did not recognize the symbols.

Share this post


Link to post
Share on other sites

Maybe you should try to add the library to OM package and not the other way round.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Similar Topics

    • By Wim Dijkgraaf
      Hi all,
       
      I've had some excellent classes with Stephane related to Parametric Composition using Opusmodus. I had hoped that with my professional background as a programmer I would be able to get up-and-running quickly but I find myself struggling too much. Not so much with the Common Lisp language itself (have found some books that really help me a lot) but more with the workflow and Common Lisp technical issues that prevent me from using the main part of my time studying Lisp.
       
      Those issues are:
       
      - TDD (Test Driven Development). I'm used to do TDD and continuous testing on the .NET platform using NCrunch. I'm also used to do testing on unit, integration and functional level. Would like to get some help choosing the right Common Lisp testing framework as well as on setting it up.
      - Package Management: I'm used to Nuget based package management (.NET platform). Need help to have a good understanding of Quicklisp/ASDF as well as how to integrate libraries that are not available through package managers.
      - Guidance in creating own functions. Good understanding of Opusmodus specific types and wether to use them or to avoid them. What I mean is related to the basic fundamental question: is it wise to "lock in" to the Opusmodus product when writing my own functions and using the Opusmodus function library. Or should I consider Opusmodus more like a rich Common Lisp IDE (MIDI playback and music score integration) but base my own function as much as possible on standard Common Lisp functions.
      - Good understanding of OMN "under the hood". What is it exactly that I'm using when I write OMN pitches, velocities etc.
      - When to use a functional approach and when to use an object oriented approach
      - How to structure your project
       
      I would also like to find someone to do some periodic reviewing and refactoring of my own code in order to learn to write good Common Lisp code.
       
      Please let me know who is able to help me on this wonderful journey!
       
      Big hug,
       
      Wim Dijkgraaf
       
      p.s. the books I'm using right now are:
      - Practical Common Lisp (Peter Seibel)
      - Let over Lambda (Doug Hoyte)
      - On Lisp (Paul Graham)
    • By Wim Dijkgraaf
      Anyone using this or similar library to do 'Extempore-like' With Time Programming in Opusmodus?
       
      https://github.com/byulparan/scheduler
       
      Big hug
    • By Rangarajan
      Hi,
      In today's blog post, I have shared some basic ideas about the Screamer Lisp library, with examples of how to start using it for constraint programming. The inspiration came from some earlier posts in OM forum on this topic. It was an exciting exercise and learnt a few interesting things!
       
      Regards,
      Rangarajan
×
×
  • Create New...