Jump to content

Convert OMN to OSC Data (to SuperCollider)


Recommended Posts

Hi everyone,


For the past two days I've been messing around with SuperCollider and OM.
I want to be able to write my score in OMN format and send it via OSC to SuperCollider.
So far I have this in OM:

(defparameter to-sc '(127.0.0.1 57120))
(setf thd1 (create-osc-thread "thread1" to-sc))
(send-osc-data thd1 '( 
                      (12 1/2) (2 1/2) (0 1/2) (3 1/2)
                      (14 1/2) (2 1/2) (0 1/2) (3 1/2)
                      (8 1/2) (2 1/2) (0 1/2) (3 1/2)
                      (7 1/2) (2 1/2) (0 1/2) (3 1/2)
                      ))

And this in SuperCollider

(OSCdef.new(
	\toggle,
	{
		arg msg, time, addr, port;
		[msg, time, addr, port].postln;
		Synth(\synth1, [pitch:msg[1]+60]);
	},
	'/thread1'
);
)
(
SynthDef('synth1', {
    arg pitch=60, amp=0.2, ffreq=15000;
	var linen, env, sig1, sig2;
    linen = Env.linen(0.01, sustainTime:0, releaseTime:1);
    env = EnvGen.kr(linen, doneAction:2);
	sig1 = Mix(VarSaw.ar([pitch.midicps], 0, 0.5));
	sig2 = LPF.ar(sig1, ffreq);
    Out.ar(0, sig2* env * amp);
}).add;
)

And this works great! However I would like to write my OM script in regular OMN format and then convert it to integers, which SuperCollider understands.

I've tried to do this like so:

(setf convert-test '(
                       (q a3 e4 c4 f4)
                       (q e3 b4 a3 c4)))

(setf data (gen-osc-data 16
                         (pitch-to-midi (omn :pitch convert-test))
                         :time (flatten (omn :length convert-test))
                         :min 0
                         :max 127))

However, it seems like "gen-osc-data" really wants to use floating values, adding the Min and Max does seem to convert these values in the range 0-127 but still I end up having the wrong notes:

(setf data (gen-osc-data 16
                         (pitch-to-midi (omn :pitch convert-test))
                         :time '(1/2 1/4 1/12 1/12 1/12)
                         :min 0
                         :max 127))

>> (((0 91 127) 1/2) ((27 127 0) 1/4) ((0 106 127) 1/12) ((0 127 64) 1/12) ((0 91 127) 1/12) ((27 127 0) 1/2) ((0 106 127) 1/4) ((0 127 118) 1/12) ((0 127 118) 1/12) ((0 127 118) 1/12)....

 

Any ideas on a straightforward method to deal with this? I hope my question is understandable, this is by far the most challenging project I've tried in OM, any help would be very appreciated!

NOTE: I know that I can just send MIDI notes to SC however I would like to control my Synth Parameters via OSC and I'm a big fan of consistency, therefor it would be great if the Pitch and Length information also could be converted and send via OSC messages.


Thanks very much in advance!

- Jor

Link to comment
Share on other sites

Yes but for this project I would love to use native SC language, and not write everything in Lisp. CL-Collider only uses the server side (synths & FX)of SC but not the language side, which has a lot of good stuff as well.
Following up on my previous question:
Is there a way to send multiple messages to one Thread? In SC it's great to be able to filter out messages like so [1], [2]. Wich will get the first and the second message send to a specific thread. Is this possible with the current OSC implementation? I tried sending multiple messages with send-osc-data but I can't figure out how to format the messages in that case.
 

Link to comment
Share on other sites

What would be the output (values) in your example, what you are looking for.

Is this what you are looking for: (<midi value> <time>)

(setf data (gen-osc-data 8
                         (flatten (pitch-to-midi (omn :pitch convert-test)))
                         :time '(1/2 1/4 1/12 1/12 1/12)
                         :min 1
                         :max 127))

=> ((34 1/2) (81 1/4) (54 1/12) (87 1/12) (1 1/12) (127 1/2) (34 1/4)
    (54 1/12) (54 1/12) (54 1/12) (54 1/2) (54 1/4) (54 1/12) (54 1/12)
    (54 1/12) (54 1/2) (54 1/4) (54 1/12) (54 1/12) (54 1/12) (54 1/2)
    (54 1/4) (54 1/12) (54 1/12) (54 1/12) (54 1/2) (54 1/4) (54 1/12)
    (54 1/12) (54 1/12) (54 1/2) (54 1/4) (54 1/12) (54 1/12) (54 1/12)
    (54 1/2) (54 1/4) (54 1/12) (54 1/12) (54 1/12))

 

Or I could add an extra keyword to allow send given values:

(setf midi-values '(57 64 60 65 52 71 57 60))
(setf data (gen-osc-data 8 midi-values
                         :time '(1/2 1/4 1/12 1/12 1/12)
                         :values :midi
                         :loop t))
=> ((57 1/2) (64 1/4) (60 1/12) (65 1/12) (52 1/12) (71 1/2) (57 1/4)
    (60 1/12) (57 1/12) (64 1/12) (60 1/2) (65 1/4) (52 1/12) (71 1/12)
    (57 1/12) (60 1/2) (57 1/4) (64 1/12) (60 1/12) (65 1/12) (52 1/2)
    (71 1/4) (57 1/12) (60 1/12) (57 1/12) (64 1/2) (60 1/4) (65 1/12)
    (52 1/12) (71 1/12) (57 1/2) (60 1/4) (57 1/12) (64 1/12) (60 1/12)
    (65 1/2) (52 1/4) (71 1/12) (57 1/12) (60 1/12))

 

Link to comment
Share on other sites

Those examples are very helpful, thank you!
Right now my output (SC input) is this:

[ [ /thread1, 3, 1 ], 666.1542108, a NetAddr(127.0.0.1, 57796), 57120 ]

Which I believe is, [[ ThreadName, Note Number, Gate], Time, Address, Port] 

Ideally what I want to be able to do is to send the Pitch/Gate and some other values (Filter Modulation, Pitchbend, etc.) to the same thread.

So for example [[/thread1, NoteNumber, 1, val1, val2, val3] etc.]]


In a perfect world they would also have independent Time values, they just should end up at the same Thread in SC.
Probably this is very simple, I would just need to combine the lists in OM before sending it with send-osc-data , I just can't really figure out how to do this.
Hope the example is clear enough 🙂

Thanks again!

Link to comment
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.

×
×
  • Create New...

Important Information

Terms of Use Privacy Policy