Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lucretiomsp committed Oct 23, 2024
1 parent 6fe7689 commit b397d38
Show file tree
Hide file tree
Showing 12 changed files with 436 additions and 38 deletions.
22 changes: 18 additions & 4 deletions src/Coypu/MIDIReceiver.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Class {
#superclass : 'Object',
#instVars : [
'midiIn',
'defaultInput'
'defaultInput',
'receivinProcess'
],
#category : 'Coypu-MIDI',
#package : 'Coypu',
Expand Down Expand Up @@ -97,24 +98,37 @@ MIDIReceiver >> readIncomingMessageSize: aNumberOfEvents [
fork
]

{ #category : 'accessing' }
MIDIReceiver >> receivinProcess [

^ receivinProcess
]

{ #category : 'accessing' }
MIDIReceiver >> receivinProcess: aProcess [

receivinProcess := aProcess
]

{ #category : 'as yet unclassified' }
MIDIReceiver >> traceIncomingMessage [

| instance buffer proc |
| instance buffer |
instance := PortMidiLibrary uniqueInstance.
buffer := PortMidiEvent new.
proc := [ [
receivinProcess := [ [
instance
advancedReadOn: self midiInput value
inBuffer: buffer
withSize: 512.
('I am the buffer message' , buffer message asString )traceCr.
(instance portMidiGetStatusFromMessage: buffer message)
traceCr.
(instance portMidiGetFirstDataFromMessage: buffer message)
traceCr.
(instance portMidiGetSecondDataFromMessage: buffer message)
traceCr ] repeat ] fork.
^ proc
^ receivinProcess
]

{ #category : 'as yet unclassified' }
Expand Down
19 changes: 19 additions & 0 deletions src/Coypu/Number.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ Number >> asDirtArray [
^ Array with: self
]

{ #category : '*Coypu' }
Number >> asMidiData1 [
"Gets the first byte of the MIDI message aMessage."
^ ((self >> 8) & 16rFF)
]

{ #category : '*Coypu' }
Number >> asMidiData2 [
"Gets the second byte of the MIDI message aMessage."
^ (self >> 16) & 16rFF
]

{ #category : '*Coypu' }
Number >> asMidiStatusByte [
"Gets the status of the MIDI message aMessage."

^ (self & 16rFF)
]

{ #category : '*Coypu' }
Number >> bars: aNumber [
"use it with anInteger bpm to have a cycle of the Iteration of a duration of aNumber of bars(or a fraction)"
Expand Down
89 changes: 60 additions & 29 deletions src/Coypu/Performance.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,26 @@ Performance class >> reset [
Performance class >> uniqueInstance [

self orbit: 0.

^ uniqueInstance ifNil: [ uniqueInstance := super new . self performanceType: PerfType new. ]
]

^ uniqueInstance ifNil: [
uniqueInstance := super new.
self performanceType: PerfType new.
uniqueInstance ]
{ #category : 'as yet unclassified' }
Performance >> Dictionary [ Variable or expression expected -><< #Performance
layout: VariableLayout;
slots: {
#visualization .
#performer .
#canvas .
#rsGroupDictionary .
#freq .
#backup .
#bpm .
#transportStep .
#activeProcess.
};
tag: 'Performance';
package: 'LiveCoding'
]

{ #category : 'accessing' }
Expand Down Expand Up @@ -99,8 +114,8 @@ Performance >> activeProcess: anObject [
{ #category : 'performance - adding' }
Performance >> add: aSequencer channel: anIntegerBetween1And16 [

aSequencer midiChannel: anIntegerBetween1And16.
self add: aSequencer
aSequencer midiChannel: anIntegerBetween1And16.
super add: aSequencer.
]

{ #category : 'accessing' }
Expand Down Expand Up @@ -153,23 +168,29 @@ Performance >> dirtMIDIDevice: aString [
dirtMIDIDevice := aString
]

{ #category : 'modifying' }
Performance >> doBackup [
{ #category : 'as yet unclassified' }
Performance >> forDsp: aDsp [

backup := self asDictionary
| p |

p := self class uniqueInstance .
p performer: PerformerPhaust new.
p activeDSP: aDsp.

^ p
]

{ #category : 'accessing' }
Performance >> freq [
"better to convert it to Float to avoid OSC sending issues"
^ freq asFloat

^ freq
]

{ #category : 'accessing' }
Performance >> freq: aDurationInSeconds [
"use for playback speed"

freq := aDurationInSeconds asFloat
freq := aDurationInSeconds
]

{ #category : 'LiveCoding - Performance' }
Expand Down Expand Up @@ -197,7 +218,8 @@ Performance >> length [
"return the number of steps of the largest array contained in the performance values"

| valuesSizes maxLength |
valuesSizes := (1 to: self values size) collect: [ :i | ((self values at: i) at: 1) size ].
valuesSizes := (1 to: self values size) collect: [ :i |
((self values at: i) at: 1) size ].
maxLength := valuesSizes inject: 0 into: [ :a :c | a max: c ].
^ maxLength
]
Expand All @@ -209,20 +231,25 @@ Performance >> mute: aKeyOrAnArrayOfKeys [
| tracks |
tracks := #( #Kick #TpSampler #Fm2Op #PsgPlus #Chordy ).

aKeyOrAnArrayOfKeys isArray ifTrue: [
aKeyOrAnArrayOfKeys isArray
ifTrue: [
aKeyOrAnArrayOfKeys do: [ :i | self removeKey: i ifAbsent: [ ] ] ]
ifFalse: [
self removeKey: aKeyOrAnArrayOfKeys.
self performanceType class = PerfTypeMooflod ifTrue: [
self performanceType visualizer cleanRow: (tracks indexOf: aKeyOrAnArrayOfKeys) ] ]
self performanceType visualizer cleanRow:
(tracks indexOf: aKeyOrAnArrayOfKeys) ] ]
]

{ #category : 'muting and soloing' }
Performance >> muteAll [
"remove all keys from the Performance"
" remove all keys from the Performance"

| anArrayOfKeys |
backup := self asDictionary.
self keysDo: [ :i | self removeKey: i ifAbsent: [ nil ] ].


self doBackup.
self keysDo: [ :i | self removeKey: i ifAbsent: [ nil ] ]
]

{ #category : 'LiveCoding - satelliteEvent' }
Expand Down Expand Up @@ -318,23 +345,27 @@ Performance >> performer [

{ #category : 'accessing' }
Performance >> performer: aPerformer [
"choose a Performer for the Performance"
"to be safe, it clear the performance"

self muteAll.
performer := aPerformer.
self muteAll
"choose a Performer for the Performance"
" to be safe, it clear the performance"
Performance uniqueInstance muteAll.
performer := aPerformer.
Performance uniqueInstance muteAll.
]

{ #category : 'playing' }
Performance >> play [
"reset all the Sequencers"

" reset all the Sequencers"
self resetAllSequencers.

"just on performance at once"
self activeProcess ifNil: [ self performer play ]
ifNotNil: [ self activeProcess isTerminated ifTrue: [ self performer play ] ]
self activeProcess
ifNil: [ self performer play ]
ifNotNil: [ (self activeProcess isTerminated )
ifTrue: [ self performer play ] ]
.



]

{ #category : 'playing' }
Expand Down Expand Up @@ -589,7 +620,7 @@ Performance >> solo: aKeyOrAnArrayOfKeys [
" remove all keys from the Performance except aKey or anArrayOfKeys"

| anArrayOfKeys |
self doBackup.
backup := self asDictionary. "do the backup"
anArrayOfKeys := self keys.
aKeyOrAnArrayOfKeys isArray
ifTrue: [
Expand Down
4 changes: 2 additions & 2 deletions src/Coypu/PerformerMIDI.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ PerformerMIDI >> play [

{ #category : 'playing' }
PerformerMIDI >> playFor: aNumberOfSteps [
"play the performance to SuperDIrt/SuperCollider audio engine - default freq is 132 bpm
"play the performance with an external MIDI devices - default freq is 132 bpm
Performance speed can be changed with p freq: a bpm"

performance bpm: 60 / (performance freq * 4).
Expand All @@ -47,7 +47,7 @@ PerformerMIDI >> playFor: aNumberOfSteps [
seq playMIDIEventAt: seq noteIndex. "delta!!!!"
"increment note Index"
seq noteIndex: seq noteIndex + 1 ]
] ] forkAt: Processor timingPriority.
] ] forkAt: Processor highIOPriority .

"step is incremented anyway"
performance incrementTransportStep ] ] forkAt:
Expand Down
2 changes: 1 addition & 1 deletion src/Coypu/PerformerPhaust.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ PerformerPhaust >> playFor: aNumberOfSteps [
seq playPhaustEventAt: seq noteIndex. "delta!!!!"
"increment note Index"
seq noteIndex: seq noteIndex + 1 ]
] ] forkAt: Processor timingPriority.
] ] forkAt: Processor highIOPriority .

"step is incremented anyway"
performance incrementTransportStep ] ] forkAt:
Expand Down
6 changes: 6 additions & 0 deletions src/Coypu/PortMidi.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ PortMidi >> initialize [
outStream := 99.
]

{ #category : 'accessing - platform' }
PortMidi >> macLibraryName [

^ FFIMacLibraryFinder findLibrary: 'libportmidi.2.0.3.dylib'
]

{ #category : 'accessing - platform' }
PortMidi >> macModuleName [
"Returns the name of the PortMidi library for Mac."
Expand Down
2 changes: 1 addition & 1 deletion src/Coypu/Sequencer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ Sequencer >> sounds: aStringForDirt [
'Pharo-11.0.0+build.688.sha.cf3d3fd1805673a058ddf99229edb72ef062c890 (64 Bit)'.
soundsAndIndexs := aStringForDirt findBetweenSubstrings: ' '.
sounds := OrderedCollection new.
1 to: soundsAndIndexs size do: [ :i |
(1 to: soundsAndIndexs size) do: [ :i |
sounds add:
(((soundsAndIndexs at: i) findBetweenSubstrings: ':') at: 1) ].
indexes := OrderedCollection new.
Expand Down
24 changes: 24 additions & 0 deletions src/Mooflod/MfPianoBlackNoteElement.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Class {
#name : 'MfPianoBlackNoteElement',
#superclass : 'ToElement',
#category : 'Mooflod-PianoKeyboardWidget',
#package : 'Mooflod',
#tag : 'PianoKeyboardWidget'
}

{ #category : 'instance creation' }
MfPianoBlackNoteElement class >> newWithColor: aColor [

^ self new
background: aColor;
yourself
]

{ #category : 'initialization' }
MfPianoBlackNoteElement >> initialize [

super initialize.
self size: 20 @ 75.
self geometry: BlRectangleGeometry new.
self constraintsDo: [ :e | e frame vertical alignTop ]
]
Loading

0 comments on commit b397d38

Please sign in to comment.