(provide 'various.scm) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Editor: Zoom exponentially ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (line-zoom-out-exponentially) (define curr ( :get-line-zoom-block)) ;;(c-display "z1" curr) (cond ((< curr 0 ) ( :line-zoom-block (- (floor (/ curr 2))))) (else (if (< curr 40) ( :line-zoom-block curr))))) (define (line-zoom-in-exponentially) (define curr ( :get-line-zoom-block)) ;;(c-display "z2" curr) (cond ((= 1 curr) ( :line-zoom-block -1)) ((< curr 0 ) (if (> curr -32) ( :line-zoom-block curr))) (else ( :line-zoom-block (- (floor (/ curr 2))))))) #!! (line-zoom-out-exponentially) (line-zoom-in-exponentially) !!# #|| (define (FROM_C-apply-block-track-onoff-to-seqblock) (define blocknum ( :current-block)) (define seqtracknum ( :get-curr-seqtrack)) (define is-playing-song ( :is-playing-song)) ) ||# ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Modulator GUI ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (FROM_C-create-modulator-gui instrument-id) (define gui ( :ui ( :get-path "modulatorgui.ui"))) ( :set-window-title gui (<-> "GUI for " ( :get-instrument-name instrument-id))) (let ((width (floor (* 3 ( :text-width "Instrument name, and an effect name, Enabled, Delete"))))) ( :set-size gui width (floor (/ width 3)))) (define table (create-table-gui (list (make-table-row "Instrument" "Long name of an instrument" #t) (make-table-row "Effect" "Long name of an effect" #t) (make-table-row "Enabled" #f #f) (make-table-row "Delete" #f #f)) :selected-row-callback (lambda (table row-num row-content) (c-display "row num" row-num "selected. Content:" row-content)) :hide-callback (lambda (table) ( :close gui)))) (let ((table-parent ( :child gui "tableParent"))) ;;( :set-layout-spacing table-parent 2 0 2 0 2) ;; ( :set-layout-spacing gui 2 2 2 2 2) ( :add table-parent table)) (define doit #f) (define (create-enabled target-id effect-name) ( :checkbox "" ( :get-modulator-enabled target-id effect-name) (lambda (enabled) (if (and doit ( :instrument-is-open-and-audio instrument-id) ( :has-modulator target-id effect-name)) ( :set-modulator-enabled target-id effect-name enabled))))) (define (create-delete target-id effect-name) ( :button "Delete" (lambda () (when (and ( :instrument-is-open-and-audio instrument-id) ( :has-modulator target-id effect-name)) ( :remove-modulator target-id effect-name) (update-rows!))))) (define (create-row! n target-id effect-num effect-name) ( :add-table-string-cell table ( :get-instrument-name target-id) 0 n) ( :add-table-string-cell table effect-name 1 n) (define onoff (create-enabled target-id effect-name)) ( :add-table-gui-cell table onoff 2 n) (define delete (create-delete target-id effect-name)) ( :add-table-gui-cell table delete 3 n) ) (define curr-targets #f) (define (update-rows!) (define targets ( :get-modulator-targets instrument-id)) (when (not (morally-equal? targets curr-targets)) (set! curr-targets targets) ;;(c-display "NEW TARGETS:" (pp targets)) ( :enable-table-sorting table #f) (define num-rows ( :get-num-table-rows table)) ( :add-table-rows table 0 (- (length targets) num-rows)) (set! doit #f) (for-each (lambda (n target) (define target-id (target :instrument-id)) (define target-effect-num (target :effect-num)) (define effect-name (target :effect-name)) (create-row! n target-id target-effect-num effect-name)) (iota (length targets)) targets) (set! doit #t) ( :enable-table-sorting table #t))) ( :add-deleted-callback gui (lambda (radium-runs-custom-exec) ( :internal_instrument-gui-has-been-hidden instrument-id))) ;;( :add-close-callback gui ;; (lambda (radium-runs-custom-exec) ;; (if ( :instrument-is-open-and-audio instrument-id) ;; (begin ;; ( :hide gui) ;; ( :internal_instrument-gui-has-been-hidden instrument-id) ;; #f) ;; #t))) ( :schedule 0 (lambda () (cond ((not ( :instrument-is-open-and-audio instrument-id)) ( :close gui) #f) ((not ( :is-open gui)) #f) (else (update-rows!) 200)))) (for-each (lambda (phasenum) (define button ( :child gui (<-> "phase_" phasenum "4"))) ( :add-callback button (lambda () (when ( :instrument-is-open-and-audio instrument-id) ( :undo-instrument-effect instrument-id "Phase shift") ( :set-instrument-effect instrument-id "Phase shift" (/ phasenum 4)))))) (list 0 1 2 3)) (define close-button ( :child gui "close_button")) ( :add-callback close-button (lambda () ( :close gui))) ( :set-takes-keyboard-focus gui #f) ( :enable-table-sorting table #t) ;;( :set-parent gui -1) ;; Set parent to the main window. (caller are responsible for doing this, if needed) gui) #! (let ((gui (FROM_C-create-modulator-gui (first ( :get-modulator-instruments))))) ( :show gui)) !# ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Blocks table GUI ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (create-blocks-table-gui) (define gui ( :ui ( :get-path "blocks.ui"))) ( :set-window-title gui "Blocks") (define doit #f) (define search-string "") (define search-text ( :child gui "search_text")) ( :hide ( :child gui "search_button")) ( :add-realtime-callback search-text (lambda (new-text) (when doit (set! search-string new-text) ;;(c-display "SETTING search to" new-text) (update-rows!)))) ( :set-layout-spacing ( :child gui "searchWidget") 0 0 0 0 2) (let ((width (floor (* 3 ( :text-width "Block # Long name LInes Tracks Delete"))))) ( :set-size gui width (floor (* width 0.7)))) (define table (create-table-gui (list (make-table-row "Block #" "Block #" #f) (make-table-row "Usage #" "Usage #" #f) (make-table-row "Name" "Long name of a block" #t) (make-table-row "Lines" "Tracks9" #f) (make-table-row "Tracks" "Tracks9" #f) (make-table-row "Delete" #f #f)) :hide-callback (lambda (table) ( :close table)) :curr-selected-row-changed-callback (lambda (table row-num row-content) (when doit ;;(c-display "ROW_CONTENT:" row-content row-num) (define blocknum (to-integer (string->number (first row-content)))) (when (not (= blocknum ( :current-block))) (when (not ( :is-playing-song)) ( :select-block blocknum) (update-rows!)) ;;(c-display (integer? blocknum) blocknum "row num" row-num "selected. Content:" row-content) ))))) (let ((table-parent ( :child gui "tableParent"))) ( :set-layout-spacing table-parent 0 0 0 0 2) ( :set-layout-spacing gui 0 2 2 2 2) ( :add table-parent table)) (define (create-name blocknum curr rownum) (define ret ( :line curr "black" (lambda (value) (when doit ;;(c-display "BLOCKNAME. New VALUE:" value) (when (not (string=? value ( :get-block-name blocknum))) ( :add-undo-block blocknum) ( :set-block-name value blocknum) (update-rows!)))))) ( :add-focus-in-callback ret (lambda () (if (not ( :is-playing-song)) (begin ( :select-block blocknum) (update-rows!)) (begin ( :enable-table-sorting table #f) ( :set-value table rownum) ( :enable-table-sorting table #t))))) (define color ( :mix-colors ( :get-block-color blocknum) ( :get-background-color -1) 0.9)) ( :set-background-color ret color) (define layout ( :vertical-layout)) ( :add layout ret) ( :set-layout-spacing layout 2 2 2 2 2) layout) (define (create-num-lines blocknum curr) ( :int-text 2 curr (max curr 9999) (lambda (value) (when doit ;;(c-display "VALUE:" value) ( :add-undo-block blocknum) ( :schedule 10 (lambda () ( :set-num-lines value blocknum) #f)) ;;(update-rows!) )))) (define (create-num-tracks blocknum curr) ( :int-text 1 curr (max curr 999) (lambda (value) (when doit ( :add-undo-block blocknum) ( :set-num-tracks value blocknum) (update-rows!))))) (define (create-delete blocknum) ( :button "Delete" (lambda () ( :delete-block blocknum) (update-rows!)))) (define last-time 0) (define start-time 0) (define (create-row! blockinfo rownum curr-blocknum blockusage) (define blocknum (car blockinfo)) (define usage (blockusage blocknum)) (define blockname (cadr blockinfo)) (define num-lines (caddr blockinfo)) (define num-tracks (cadddr blockinfo)) (define time1 (time)) ( :add-table-int-cell table blocknum 0 rownum) (define time2 (time)) ( :add-table-int-cell table usage 1 rownum) (define blocknamegui (create-name blocknum blockname rownum)) ( :add-table-gui-cell table blocknamegui 2 rownum) (define time3 (time)) ( :add-table-gui-cell table (create-num-lines blocknum num-lines) 3 rownum) (define time4 (time)) ( :add-table-gui-cell table (create-num-tracks blocknum num-tracks) 4 rownum) (define time5 (time)) (define delete (create-delete blocknum)) (define time6 (time)) ( :add-table-gui-cell table delete 5 rownum) (define time7 (time)) (if (= blocknum curr-blocknum) ( :set-value table rownum)) (define time8 (time)) (c-display "Created " blocknum blockname (- time8 last-time) "-" (- time8 start-time) ":" (- time2 time1) (- time3 time2) (- time4 time3) (- time5 time4) (- time6 time5) (- time7 time6) (- time8 time7)) (set! last-time time8) ) (define curr-data #f) (define (get-data) (list ( :current-block) ( :get-block-usage-in-sequencer) (keep identity (map (lambda (blocknum) (define blockname ( :get-block-name blocknum)) ;;(c-display "BLOCKNAME" blocknum "\"" blockname "\"") (and (or (string=? search-string "") (string-case-insensitive-contains? blockname search-string)) (list blocknum blockname ( :get-num-lines blocknum) ( :get-num-tracks blocknum)))) (iota ( :get-num-blocks)))))) (define (update-rows!) (define data (get-data)) (when (not (morally-equal? data curr-data)) (set! curr-data data) (define curr-blocknum (car data)) (define blockusage (cadr data)) (define blockdata (caddr data)) ;;(c-display "DATA:" (pp data)) ( :enable-table-sorting table #f) (define num-rows ( :get-num-table-rows table)) (set! doit #f) (set! start-time (time)) (disable-gui-updates-block ;; Speed up. table (lambda () ( :add-table-rows table 0 (- (length blockdata) num-rows)) ;; Hiding the table is a major speedup when the block list is updated due to user interaction in the gui. ;; It's mainly a workaround for very bad qt performance on Qt 5.4.1. (I hadn't discovered it on newer Qt versions) ;; On Qt 5.9.0, it only increases performance with around 20-30%. ( :hide table) ( :set-value table -1) ;; unselect current row. (for-each (lambda (rowdata rownum) (create-row! rowdata rownum curr-blocknum blockusage)) blockdata (iota (length blockdata))) ;; show it again. ( :show table) ( :enable-table-sorting table #t) )) (set! doit #t))) (update-rows!) ( :schedule 1100 (lambda () (cond ((not ( :is-open gui)) #f) (else (update-rows!) 200)))) (define close-button ( :child gui "close_button")) ( :add-callback close-button (lambda () ( :close gui))) ( :set-takes-keyboard-focus gui #f) ( :enable-table-sorting table #t) ( :set-parent gui -1) ;; Set parent to the main window. ( :show gui) gui) ;(if (not *is-initializing*) ; (create-blocks-table-gui)) (define *blocks-table-gui* #f) (define (FROM_C-create-blocks-table-gui) (if (or (not *blocks-table-gui*) (not ( :is-open *blocks-table-gui*))) (set! *blocks-table-gui* (create-blocks-table-gui)) ( :raise *blocks-table-gui*))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Instruments table GUI ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (create-instruments-table-gui) (define gui ( :ui ( :get-path "blocks.ui"))) ( :set-window-title gui "Instruments") (define doit #f) (define search-string "") (define search-text ( :child gui "search_text")) ( :hide ( :child gui "search_button")) ( :add-realtime-callback search-text (lambda (new-text) (when doit (set! search-string new-text) ;;(c-display "SETTING search to" new-text) (update-rows!)))) ( :set-layout-spacing ( :child gui "searchWidget") 0 0 0 0 2) (let ((width (floor (* 3 ( :text-width "Instrument # Long name LInes Tracks Delete"))))) ( :set-size gui width (floor (* width 0.7)))) (define table (create-table-gui (list (make-table-row "#" "123" #f) (make-table-row "# Conn." "# Conn." #f) (make-table-row "Name" "Long name of a instrument" #t) (make-table-row "# in" "# in" #f) (make-table-row "# out" "# out" #f) (make-table-row "Type" "GAkk gkkakkg kakkg / asdf" #t) (make-table-row "Recv. ext. MIDI" "Recv. ext. MIDI" #f) (make-table-row "GUI" "GUI" #f) (make-table-row "Delete" #f #f)) :hide-callback (lambda (table) ( :close gui)) :curr-selected-row-changed-callback (lambda (table row-num row-content) (when doit ;;(c-display "ROW_CONTENT:" row-content row-num) (define instrument-id ( :get-audio-instrument-id (to-integer (string->number (first row-content))))) (when (not (equal? instrument-id ( :get-current-instrument))) ( :set-current-instrument instrument-id) (update-rows!) ;;(c-display (integer? instrumentnum) instrumentnum "row num" row-num "selected. Content:" row-content) ))))) (let ((table-parent ( :child gui "tableParent"))) ( :set-layout-spacing table-parent 0 0 0 0 2) ( :set-layout-spacing gui 0 2 2 2 2) ( :add table-parent table)) (define (create-name instrument-id curr) (define ret ( :line curr (lambda (value) (when doit ;;(c-display "VALUE:" value) (when (not (string=? value curr)) ( :set-instrument-name value instrument-id) (update-rows!)))))) ( :add-focus-in-callback ret (lambda () ( :set-current-instrument instrument-id) (update-rows!) )) (define color ( :mix-colors ( :get-instrument-color instrument-id) ( :get-background-color -1) 0.9)) ( :set-background-color ret color) (define layout ( :vertical-layout)) ( :add layout ret) ( :set-layout-spacing layout 2 2 2 2 2) ( :set-size-policy layout #t #f) layout) (define (create-gui-onoff instrument-id) (define has-gui ( :has-native-instrument-gui instrument-id)) (if (not has-gui) #f (mid-horizontal-layout ( :checkbox "" ( :instrument-gui-is-visible instrument-id table) (lambda (onoff) (if onoff ( :show-instrument-gui instrument-id gui) ( :hide-instrument-gui instrument-id))))))) (define (create-delete instrument-id) ( :button "Delete" (lambda () ( :delete-instrument instrument-id) (update-rows!)))) (define last-time 0) (define start-time 0) (define (create-row! instrumentinfo rownum curr-instrument-id) (define instrument-id (car instrumentinfo)) (define usage (cadr instrumentinfo)) (define instrumentname (caddr instrumentinfo)) (define num-inputs ( :get-num-input-channels instrument-id)) (define num-outputs ( :get-num-output-channels instrument-id)) (define type (cadddr instrumentinfo)) (define time1 (time)) ( :add-table-int-cell table ( :get-audio-instrument-num instrument-id) 0 rownum) (define time2 (time)) ( :add-table-int-cell table usage 1 rownum) (define instrumentnamegui (create-name instrument-id instrumentname)) ( :add-table-gui-cell table instrumentnamegui 2 rownum) (define time3 (time)) ( :add-table-int-cell table num-inputs 3 rownum) (define time4 (time)) ( :add-table-int-cell table num-outputs 4 rownum) (define time5 (time)) ( :add-table-string-cell table type 5 rownum) (define midienabledgui ( :checkbox "" ( :instrument-always-receive-midi-input instrument-id) (lambda (onoff) ( :set-instrument-always-receive-midi-input instrument-id onoff)))) ( :set-tool-tip midienabledgui "Receive MIDI from external input") ( :add-table-gui-cell table (mid-horizontal-layout midienabledgui) 6 rownum) (define onoffgui (create-gui-onoff instrument-id)) (if onoffgui ( :add-table-gui-cell table onoffgui 7 rownum) ( :add-table-string-cell table "" 7 rownum)) ;; clear the cell. TODO: create a clear-cell function. (define delete (create-delete instrument-id)) (define time6 (time)) ( :add-table-gui-cell table delete 8 rownum) (define time7 (time)) (if (equal? instrument-id curr-instrument-id) ( :set-value table rownum)) (define time8 (time)) (c-display "Created " instrument-id instrumentname (- time8 last-time) "-" (- time8 start-time) ":" (- time2 time1) (- time3 time2) (- time4 time3) (- time5 time4) (- time6 time5) (- time7 time6) (- time8 time7)) (set! last-time time8) ) (define curr-data #f) (define (get-data) (list ( :get-current-instrument) (keep identity (map (lambda (instrument-id) (define instrumentname ( :get-instrument-name instrument-id)) (define type (<-> ( :get-instrument-type-name instrument-id) " / " ( :get-instrument-plugin-name instrument-id))) (and (or (string=? search-string "") (string-case-insensitive-contains? instrumentname search-string) (string-case-insensitive-contains? type search-string)) (list instrument-id (+ ( :get-num-in-audio-connections instrument-id) ( :get-num-out-audio-connections instrument-id) ( :get-num-in-event-connections instrument-id) ( :get-num-out-event-connections instrument-id)) instrumentname type ( :instrument-always-receive-midi-input instrument-id) ;; Commented out since instrument-gui-is-visible only returns true if the supplied gui argument is the same as the parent of the instrument gui. Should probably make an is-visible-on-any-gui function. ;;(and ( :has-native-instrument-gui instrument-id) ;; ( :instrument-gui-is-visible instrument-id table)) ))) (append ;;(get-all-midi-instruments) (get-all-audio-instruments)))))) (define (update-rows!) (define data (get-data)) (when (not (morally-equal? data curr-data)) (set! curr-data data) (define curr-instrument-id (car data)) (define instrumentdata (cadr data)) ;;(c-display "DATA:" (pp data)) ( :enable-table-sorting table #f) (define num-rows ( :get-num-table-rows table)) (set! doit #f) (set! start-time (time)) (disable-gui-updates-block ;; Speed up. table (lambda () ( :add-table-rows table 0 (- (length instrumentdata) num-rows)) ;; Hiding the table is a major speedup when the instrument list is updated due to user interaction in the gui. ;; It's mainly a workaround for very bad qt performance on Qt 5.4.1. (I hadn't discovered it on newer Qt versions) ;; On Qt 5.9.0, it only increases performance with around 20-30%. ( :hide table) ( :set-value table -1) ;; unselect current row. (for-each (lambda (rowdata rownum) (create-row! rowdata rownum curr-instrument-id)) instrumentdata (iota (length instrumentdata))) ;; show it again. ( :show table) ( :enable-table-sorting table #t) )) (set! doit #t))) (update-rows!) ( :schedule 1100 (lambda () (cond ((not ( :is-open gui)) #f) (else (update-rows!) 200)))) (define close-button ( :child gui "close_button")) ( :add-callback close-button (lambda () ( :close gui))) ( :set-takes-keyboard-focus gui #f) ( :enable-table-sorting table #t) ( :sort-table-by table 0 #t) ( :set-parent gui -1) ;; Set parent to the main window. ( :show gui) gui) (if (not *is-initializing*) (create-instruments-table-gui)) (define *instruments-table-gui* #f) (define (FROM_C-create-instruments-table-gui) (if (or (not *instruments-table-gui*) (not ( :is-open *instruments-table-gui*))) (set! *instruments-table-gui* (create-instruments-table-gui)) ( :raise *instruments-table-gui*))) ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Blocklist / Playlist ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Note: may be used for keybinding (define (show-set-current-seqtrack-menu) (popup-menu (map (lambda (seqtracknum) (list ( :get-seqtrack-name seqtracknum) (lambda () ( :set-curr-seqtrack seqtracknum)))) (iota ( :get-num-seqtracks))))) ( get-delete-all-pauses-menu-entry) ;; in sequencer.scm (define (get-blocklist/playlist-common-entries) (list (get-delete-all-pauses-menu-entry ( :get-curr-seqtrack)) "Set current seqtrack..." show-set-current-seqtrack-menu "Show blocklist" ra:show-blocklist-gui)) (define (get-blocklist-popup-menu-entries) (define blocknum ( :current-block)) (define (get-block-entries) (list (<-> "-------" blocknum ": \"" ( :get-block-name blocknum) "\"") (list "Rename..." (lambda () (define old-name ( :get-block-name blocknum)) (define new-name ( :request-string "New name:" #t old-name)) (c-display "NEWNAME" (<-> "-" new-name "-")) (when (and (not (string=? new-name "")) (not (string=? new-name old-name))) ( :add-undo-block blocknum) ( :set-block-name new-name blocknum)))) (list "Configure color..." (lambda () (if blocknum ( :color-dialog ( :get-block-color blocknum -1 #f) -1 (lambda (color) ( :set-block-color color blocknum)))))) (list "Generate new color" :shortcut ra:generate-new-color-for-all-selected-seqblocks (lambda () (let ((color ( :generate-new-block-color 1.0))) ( :set-block-color color blocknum)))) "Delete" ra:delete-block "-------Editor blocks" "Insert new block" ra:insert-block "Append new block" ra:append-block "---------------" "Load Block... (BETA!)" ra:load-block "Save Block..." ra:save-block "---------------" )) (get-block-entries)) (define (show-blocklist-popup-menu) (popup-menu (get-blocklist-popup-menu-entries) (get-blocklist/playlist-common-entries))) (define (get-audiofile-entries filename) (list "Add new audio file(s)..." (lambda () (create-file-requester "Choose audio file(s)" ( :create-illegal-filepath) "audio files" ( :get-audiofile-postfixes) #t "" #t #f -1 (lambda (filenames) (c-display "FILENAMES:" filenames) (for-each (lambda (filename) (c-display "ADDING" filename) ( :add-audiofile filename)) filenames)))) (list "Configure color..." :enabled filename (lambda () ( :color-dialog ( :get-audiofile-color filename #f) -1 (lambda (color) ( :set-audiofile-color color filename))))) (list "Generate new color" :enabled filename :shortcut ra:generate-new-color-for-all-selected-seqblocks (lambda () (let ((color ( :generate-new-block-color 1.0))) ( :set-audiofile-color color filename)))) )) (define (show-audiolist-popup-menu filename) (popup-menu (get-audiofile-entries filename))) (define (FROM_C-show-blocklist-popup-menu) (define seqtracknum ( :get-curr-seqtrack)) (define for-audiofiles ( :seqtrack-for-audiofiles seqtracknum)) (define for-blocks (not for-audiofiles)) (popup-menu (if for-blocks (get-blocklist-popup-menu-entries) (get-audiofile-entries #f)) "---------------Playlist" (get-blocklist/playlist-common-entries) "Hide" (lambda () ( :show-hide-playlist -1) ))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Load song, "are you sure?" requester ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;(define (create-are-you-sure?-loading-song-requester callback) ;; (define gui ( :vertical-layout)) ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Bottom bar CPU / XRUNS ;;;;;;;;;;;;;;;;;;;;;;;;;;; #!! ( :get-num-xruns) !!# (define (get-xruns-area-X-width) (* 1.2 ( :text-width "X:"))) (define (get-xruns-area-number-width) (* 1.2 ( :text-width "00"))) (define (get-xruns-area-width) (+ (get-xruns-area-X-width) (get-xruns-area-number-width))) (define (get-cpu-area-single-width) (* 1.2 ( :text-width "00"))) (define (get-cpu-area-dash-width) (* 1.2 ( :text-width "-"))) (define (get-cpu-area-width) (+ (* 3 (get-cpu-area-single-width)) (* 2 (get-cpu-area-dash-width)))) (define *zero-num-xruns* ( :get-num-xruns)) (define *num-xruns* 0) (define *cpu-usage-guis* '()) (define *cpu-usage* ( :get-cpu-usage)) (define (reset-cpu-usage!) (set! *zero-num-xruns* ( :get-num-xruns)) (set! *num-xruns* 0)) (define *cpu-usage-poller-has-started #f) (define (maybe-start-cpu-usage-poller) (when (not *cpu-usage-poller-has-started) (set! *cpu-usage-poller-has-started #t) (reset-cpu-usage!) ( :schedule 1000 (lambda () ;;(c-display "..update") (set! *num-xruns* (max 0 (- ( :get-num-xruns) *zero-num-xruns*))) (set! *cpu-usage* ( :get-cpu-usage)) (set! *cpu-usage-guis* (keep (lambda (area) (if ( :is-open area) (begin ( :update area) #t) #f)) *cpu-usage-guis*)) 1000)))) (def-area-subclass ( :gui :x1 :y1 :x2 :y2) (define dash-width (get-cpu-area-dash-width)) (define single-width (get-cpu-area-single-width)) (define c1-x1 0) (define d1-x1 single-width) (define c2-x1 (+ d1-x1 dash-width)) (define d2-x1 (+ c2-x1 single-width)) (define c3-x1 (+ d2-x1 dash-width)) (define c3-x2 (+ c3-x1 single-width)) (define xruns-X-x1 (+ c3-x2 2)) (define xruns-X-x2 (+ xruns-X-x1 (get-xruns-area-X-width))) (define xruns-number-x1 xruns-X-x2) (define xruns-number-x2 (+ xruns-X-x2 (get-xruns-area-number-width))) ( :schedule 0 (lambda () (if ( :is-open gui) (set-fixed-width gui (ceiling xruns-number-x2))) #f)) (c-display " CREATING") (define cpu-area-x2 (get-cpu-area-width)) (add-mouse-cycle! :press-func (lambda (button x* y*) (reset-cpu-usage!) (update-me!) #f )) (add-raw-mouse-cycle! :enter-func (lambda (button x* y*) ( :tool-tip (<->"

The first three numbers, from left to right, show:

" "

1. The lowest amount of CPU measured for processing an audio block during the last second. (%)

" "

2. The average amount of CPU measured for processing audio blocks during the last second. (%)

" "

3. The highest amount of CPU measured for processing an audio block during the last second. (%)

" "

Note that the sum of average numbers for all instruments is likely to be higher than the average CPU you see in the bottom bar due to processing instruments in parallel.

" "

The last number shows number of soundcard Xruns. Click to reset.

" "") ))) (define dascolor ( :mix-colors "green" *text-color* 0.5)) (define-override (paint) ;; workaround for osx. ;;(c-display "GAKK") ( :filled-box gui "high_background" x1 y1 x2 y2 0 0) (define (draw-text text color x1 x2 scale-font-size) ( :draw-text gui color text x1 y1 x2 y2 #f ;; wrap-lines #f ;; align-top #f ;; align-left 0 ;; rotate #f ;;cut-text-to-fit scale-font-size ;;scale-font-size )) ;; cpu usage ;;;;;;;;;;;;;;;;; (define (draw-number i x1 x2) (define n (round (*cpu-usage* i))) (define text (if (< n 10) (<-> "0" (number->string n)) (number->string n))) (define color (cond ((>= n 90) "red") ((>= n 60) "yellow") (else dascolor))) (draw-text text color x1 x2 (> n 99))) (define (draw-dash x1 x2) (draw-text "-" *text-color* x1 x2 #f)) (draw-number 0 c1-x1 d1-x1) (draw-dash d1-x1 c2-x1) (draw-number 1 c2-x1 d2-x1) (draw-dash d2-x1 c3-x1) ;;(c-display d1-x1 c2-x1 d2-x1 c3-x1) (draw-number 2 c3-x1 c3-x2) ;; xruns ;;;;;;;;;;;;;;;;; (draw-text "X:" dascolor xruns-X-x1 xruns-X-x2 #f) (let ((xruns *num-xruns*)) (draw-text (if (< xruns 10) (<-> "0" xruns) (number->string xruns)) (if (> xruns 0) "red" dascolor) xruns-number-x1 xruns-number-x2 (> xruns 99))) ) ) (define (FROM_C-create-cpu-usage-widget) (maybe-start-cpu-usage-poller) (define testarea (make-qtarea :width 160 :height 20 :sub-area-creation-callback (lambda (gui width height state) ( :cpu-usage-area gui 0 0 width height)))) (push-back! *cpu-usage-guis* (testarea :get-gui)) (testarea :get-gui)) #!! (let () (define gui (FROM_C-create-cpu-usage-widget)) ( :set-parent gui -1) ( :show gui)) !!# ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Various popup menus ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Instruments ;;(define (FROM_C-show-lock-instrument-popup-menu) ;; (popup-menu ;; (get-keybinding-configuration-popup-menu-entries "ra:switch-set-current-instrument-locked" ;; '() ;; "") ;; "-------------" ;; "Set current instrument..." show-set-current-instrument-popup-menu ;; "-------------" ;; "Help keybindings" show-keybinding-help-window ;; )) ;;; Bottom bar (define (FROM_C-show-bottom-bar-octave-down-popup-menu) (popup-menu (get-keybinding-configuration-popup-menu-entries "ra:dec-key-add" '(12) "FOCUS_EDITOR") "-------------" "Help keybindings" show-keybinding-help-window )) (define (FROM_C-show-bottom-bar-octave-up-popup-menu) (popup-menu (get-keybinding-configuration-popup-menu-entries "ra:inc-key-add" '(12) "FOCUS_EDITOR") "-------------" "Help keybindings" show-keybinding-help-window )) (define (FROM_C-show-bottom-bar-undo-popup-menu) (popup-menu (get-keybinding-configuration-popup-menu-entries "ra:undo" '() "") "-------------" "Help keybindings" show-keybinding-help-window )) (define (FROM_C-show-bottom-bar-redo-popup-menu) (popup-menu (get-keybinding-configuration-popup-menu-entries "ra:redo" '() "") "-------------" "Help keybindings" show-keybinding-help-window )) (define (FROM_C-show-bottom-bar-switch-drunk_velocity-popup-menu) (popup-menu (get-keybinding-configuration-popup-menu-entries "ra:switch-drunk-velocity-on-off" '() "FOCUS_EDITOR") "-------------" "Help keybindings" show-keybinding-help-window )) (define (FROM_C-show-bottom-bar-switch-edit-popup-menu) (popup-menu (get-keybinding-configuration-popup-menu-entries "ra:switch-edit-on-off" '() "FOCUS_EDITOR") "-------------" "Help keybindings" show-keybinding-help-window )) (define (FROM_C-show-bottom-bar-switch-click-popup-menu) (popup-menu (get-keybinding-configuration-popup-menu-entries "ra:switch-metronome" '() "") "-------------" "Help keybindings" show-keybinding-help-window )) (define (FROM_C-show-bottom-bar-switch-play-cursor-popup-menu) (popup-menu (get-keybinding-configuration-popup-menu-entries "ra:switch-play-cursor-on-off" '() "FOCUS_EDITOR") "-------------" "Help keybindings" show-keybinding-help-window )) (define (FROM_C-show-bottom-bar-switch-editor-follows-play-cursor-popup-menu) (popup-menu (get-keybinding-configuration-popup-menu-entries "ra:switch-editor-follows-play-cursor" '() "FOCUS_EDITOR") "-------------" "Help keybindings" show-keybinding-help-window )) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Various ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (place-to-string place) (if (eq? 'same-place place) 'same-place (<-> (* 1.0 place))))