Composer

Composer preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

(This model has yet to be categorized with any tags)
Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 345 times • Downloaded 70 times • Run 2 times
Download the 'Composer' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Click to Run Model

extensions [ sound ]

breed [ players player ] ;; the players move across the world and play notes
breed [ notes note ]     ;; half or quarter notes
breed [ cursors cursor ]         ;; the gray note places notes on the staff
breed [ marks mark ]     ;; vertical lines break up measures

players-own [ tone ]
notes-own [ duration ]
globals [ current-note current-beat x-offset y-offset scale note-names ]

to setup
  clear-all
  set scale (list 60 62 64 65 67 69 71 72)
  set note-names (list "C" "D" "E" "F" "G" "A" "B" "C")
  set x-offset -12
  set y-offset -3

  ;; create the players
  create-players 8 [
    ht
    set xcor x-offset
    set ycor who + y-offset
    set tone item who scale
    set heading 0
    set color black
    set shape "line left"
    set plabel item who note-names
    st
  ]

  ask turtles [ rt 90 ]

  ask patches [ set plabel-color gray ]

  ;; alternate white and gray lines
  ask patches with [ pycor mod 2 = 1 ] [ set pcolor white ]
  ask patches with [ pycor mod 2 = 0 ] [ set pcolor 9 ]

  ;; create marks to indicate measures
  ask patches[
    if pxcor mod 4 = 0 [
      sprout-marks 1 [ set shape "line left" set color gray ]
    ]
  ]

  ;; create the cursor
  create-cursors 1 [
    set heading 0
    set color gray
    set label-color gray
    hide-turtle
  ]
  reset-ticks
end 

to play
  every quarter-note-length [
    if metronome? [ sound:play-drum "Hi Wood Block" 80 ]
    ask players [
      if ( any? notes-here )  [
        sound:play-note
          (item instrument-number sound:instruments)
          tone
          120
          ( quarter-note-length * [duration] of one-of notes-here) ]
      fd 1
    ]
    tick
  ]
end 

to draw-notes
  carefully [ ;; we use carefully so we don't have to check for every possible
              ;; out of bounds condition
    ask cursors [
        show-turtle
        setxy mouse-xcor mouse-ycor
        set shape note-shape
      ]
      set current-note item ( round mouse-ycor - y-offset ) note-names
      set current-beat round mouse-xcor - x-offset
      ask patches [ set plabel-color gray ]
      ask patches with [ plabel = item ( round mouse-ycor - y-offset ) note-names ]
        [ set plabel-color black ] ;; highlight the note name label

    if mouse-down? [
      if not any? notes-on patch mouse-xcor mouse-ycor [
        ask patch mouse-xcor mouse-ycor [
          sprout-notes 1 [
            set heading 0  ;; upright
            set color black
            set shape note-shape
            if note-length = "1/4" [ set duration 1 ]
            if note-length = "1/2" [ set duration 2 ]
          ]
        ]
      ]
    ]
  ]
  [
    ;; ignore errors
  ]
  if not mouse-inside?
    [ ask cursors [ hide-turtle ] ]
  display
end 

to erase-notes
 ask cursors [
      st
      setxy mouse-xcor mouse-ycor
      set shape "X"
      set current-note item ( round mouse-ycor - y-offset ) note-names
      set current-beat round mouse-xcor - x-offset
  ]
  if mouse-down? [
    ask notes-on patch mouse-xcor mouse-ycor [
      die
    ]
  ]
  if not mouse-inside?
    [ ask cursors [ hide-turtle ] ]
  display
end 

to-report note-shape
  if note-length = "1/4" [ report "quarter note" ]
  if note-length = "1/2" [ report "half note" ]
end 


; Public Domain:
; To the extent possible under law, Uri Wilensky has waived all
; copyright and related or neighboring rights to this model.

There are 10 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky about 12 years ago Updated version tag Download this version
Uri Wilensky almost 13 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago Composer Download this version
Uri Wilensky over 14 years ago Composer Download this version

Attached files

File Type Description Last updated
Composer.png preview Preview for 'Composer' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.