# Using cP

**URL:** <https://uzu.lurk.org/t/using-cp/1319>\
**Category:** TidalCycles\
**Tags:** innards\
**Created:** [3 June 2020 02:00 UTC](https://uzu.lurk.org/t/using-cp/1319 "2020-06-03T02:00:36Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![eris](https://uzu.lurk.org/user_avatar/uzu.lurk.org/eris/32/233_2.png) [@eris](https://uzu.lurk.org/u/eris)\
**Post date:** [3 June 2020 02:00 UTC](https://uzu.lurk.org/t/using-cp/1319/1 "2020-06-03T02:00:36Z")

</div>

At the very least, I'd love to see `cP` make a comeback so that it's possible to send `Pattern` data from SuperDirt. The old implementation looked like this:

```haskell
_cP :: (Enumerable a, Parseable a) => [Pattern a] -> String -> Pattern a
_cP ds s = innerJoin $ _cX f ds s
  where f a (VI v) = [Event a a (parseBP_E $ show v)]
        f a (VF v) = [Event a a (parseBP_E $ show v)]
        f a (VS v) = [Event a a (parseBP_E v)]
cP :: (Enumerable a, Parseable a) => Pattern a -> String -> Pattern a
cP d = _cP [d]
cP_ :: (Enumerable a, Parseable a) => String -> Pattern a
cP_ = _cP []

```

I've been looking at the new implementation of `cF` and trying to figure out how to port this to modern TidalCycles, but so far no dice.

Once upon a time I used a keyboard, along with the following code, to create arp `Pattern`s and chords in TidalCycles based on the keys that were held down. Would be nice to be able to do that again- it seems my TidalCycle MIDI video is a bit out of date.

```smalltalk
	(
		// here's the bit that sends MIDI data from all controllers to TidalCycles via OSC
		MIDIClient.init;
		MIDIIn.connectAll;
		~tidalSocket = NetAddr("127.0.0.1", 6010);
		e.notes=[];
		MIDIFunc.cc({|val, num, chan, src| ~tidalSocket.sendMsg('/ctrl', num, val/127.0);}, nil, nil, nil);
		MIDIFunc.noteOn({|veloc, num, chan, src| e.notes=e.notes.add(num); e.notes=e.notes.sort({|a,b| a>b}).reverse; ~tidalSocket.sendMsg('/ctrl', "notes", format("%", e.notes-60)); e.notes.postln;});
		MIDIFunc.noteOff({|veloc, num, chan, src| e.notes=e.notes.takeThese({|x| x==num}); ~tidalSocket.sendMsg('/ctrl', "notes", format("%", e.notes-60)); e.notes.postln;});
	);

```

---

<div class="post-metadata">

**Author:** ![yaxu](https://uzu.lurk.org/user_avatar/uzu.lurk.org/yaxu/32/2_2.png) [@yaxu](https://uzu.lurk.org/u/yaxu)\
**Post date:** [3 June 2020 08:02 UTC](https://uzu.lurk.org/t/using-cp/1319/2 "2020-06-03T08:02:00Z")

</div>

Hey @eris, I moved this to innards..

As far as I know `cP` is still there.. Is there a problem with it?

---

<div class="post-metadata">

**Author:** ![eris](https://uzu.lurk.org/user_avatar/uzu.lurk.org/eris/32/233_2.png) [@eris](https://uzu.lurk.org/u/eris)\
**Post date:** [6 June 2020 06:07 UTC](https://uzu.lurk.org/t/using-cp/1319/3 "2020-06-06T06:07:39Z")

</div>

Actually...no! _(I'm so embarrassed!)_ I don't know what I was doing, but for some reason I couldn't locate it and I thought it'd gone missing. Went to go look for it after seeing your reply, and it's there and just fine! Sorry about that \>.\>

Could probably just trash this topic honestly. I don't want to create confusion, especially since it seems the tutorial content I have posted on the matter should work just fine.

_(thank you!)_

---

<div class="post-metadata">

**Author:** ![yaxu](https://uzu.lurk.org/user_avatar/uzu.lurk.org/yaxu/32/2_2.png) [@yaxu](https://uzu.lurk.org/u/yaxu)\
**Post date:** [6 June 2020 07:51 UTC](https://uzu.lurk.org/t/using-cp/1319/4 "2020-06-06T07:51:52Z")

</div>

Heh no worries!

---

<div class="post-metadata">

**Author:** ![abertier64](https://uzu.lurk.org/letter_avatar_proxy/v4/letter/a/838e76/32.png) [@abertier64](https://uzu.lurk.org/u/abertier64)\
**Post date:** [9 August 2020 10:20 UTC](https://uzu.lurk.org/t/using-cp/1319/5 "2020-08-09T10:20:11Z")

</div>

Hi,

I could get the tutorial at [http://ericfairbanks.org/2018/12/17/tidal-tutorial-part-4.html](http://ericfairbanks.org/2018/12/17/tidal-tutorial-part-4.html) to run if I do  
let chord = cP "notes"  
instead of  
let chord = cP "[]" "notes"

am I doing anything wrong ?

---

<div class="post-metadata">

**Author:** ![John\_Murphy](https://uzu.lurk.org/user_avatar/uzu.lurk.org/john_murphy/32/579_2.png) [@John\_Murphy](https://uzu.lurk.org/u/John_Murphy)\
**Post date:** [9 August 2020 22:41 UTC](https://uzu.lurk.org/t/using-cp/1319/6 "2020-08-09T22:41:10Z")

</div>

@eris  
Am I right in understanding that "cP" is a pattern that's sent over OSC to a specific path that TidalCycles is listening to ?

If that's the case, are there any gotchas ? Like escaping quotes / etc. ?

---

<div class="post-metadata">

**Author:** ![John\_Murphy](https://uzu.lurk.org/user_avatar/uzu.lurk.org/john_murphy/32/579_2.png) [@John\_Murphy](https://uzu.lurk.org/u/John_Murphy)\
**Post date:** [10 August 2020 01:09 UTC](https://uzu.lurk.org/t/using-cp/1319/7 "2020-08-10T01:09:08Z")

</div>

I was playing with this a little bit - it looks like this lets you send over anything in mini-notation, but you're still limited to anything within that notation.

Does a function or translator exist that'll let you send over something like "slow 2 $ s 'bd\*4'" over the pipe and then expand that string for evaluation ? If not, how could I go about building it ? What are the key functions I'd need to learn about to glue that together ? (obviously you could do something where you build the function and then put it into a buffer somewhere and then evaluate _that_, but that seems uncomfortable and clumsy - I'd rather build the pattern and then send that over to be evaluated.)

---

<div class="post-metadata">

**Author:** ![yaxu](https://uzu.lurk.org/user_avatar/uzu.lurk.org/yaxu/32/2_2.png) [@yaxu](https://uzu.lurk.org/u/yaxu)\
**Post date:** [10 August 2020 09:07 UTC](https://uzu.lurk.org/t/using-cp/1319/8 "2020-08-10T09:07:27Z")

</div>

Hi @abertier64, yes that's right, the interface simplified a little bit since @eris wrote that tutorial. Part of the reason why some bits aren't well documented is that they're experimental and subject to change. If anything confusing/unexpected happens please post here and we can straighten things out.

---

<div class="post-metadata">

**Author:** ![yaxu](https://uzu.lurk.org/user_avatar/uzu.lurk.org/yaxu/32/2_2.png) [@yaxu](https://uzu.lurk.org/u/yaxu)\
**Post date:** [10 August 2020 09:13 UTC](https://uzu.lurk.org/t/using-cp/1319/9 "2020-08-10T09:13:56Z")

</div>

@john_murphy Loosely speaking, currently Tidal can parse and evaluate the mini-notation, but not Haskell. However @lwlsn and I are looking at making an OSC api that might make this possible. What is it that you'd like to do?

---

<div class="post-metadata">

**Author:** ![abertier64](https://uzu.lurk.org/letter_avatar_proxy/v4/letter/a/838e76/32.png) [@abertier64](https://uzu.lurk.org/u/abertier64)\
**Post date:** [10 August 2020 09:59 UTC](https://uzu.lurk.org/t/using-cp/1319/10 "2020-08-10T09:59:17Z")

</div>

Thanks @yaxu I was puzzled because the `cF` part worked right away but I could not get the `cP` part to work until I stumbled on the solution. I have yet to learn how to read Haskell signatures...

---

<div class="post-metadata">

**Author:** ![John\_Murphy](https://uzu.lurk.org/user_avatar/uzu.lurk.org/john_murphy/32/579_2.png) [@John\_Murphy](https://uzu.lurk.org/u/John_Murphy)\
**Post date:** [10 August 2020 10:51 UTC](https://uzu.lurk.org/t/using-cp/1319/11 "2020-08-10T10:51:29Z")

</div>

@yaxu There's a few things I would like to do with this - but let's take a few simple examples:

1. We have a bank of 10 patterns.
2. Each of these patterns is mapped to a button on apc mini controller and can be ON or OFF.
3. When we put a button into an ON state, that pattern is added to a "cat" containing all the patterns currently in the ON state. When we put the button into an OFF state, it is removed from the "cat" containing all the patterns currently in the ON state.

or:

1. I do some editing for a sequence by entering midi notes into a pseq in Supercollider, and I'm happy with the result. I save that value into a list, and I send the pattern over to Tidal with a slow / fast to indicate how many cycles it's going to take to run.

A lot of the state management is easier to do in Supercollider, so having bi-directional communication to take advantage of the strengths of each language would be very useful.

---

<div class="post-metadata">

**Author:** ![yaxu](https://uzu.lurk.org/user_avatar/uzu.lurk.org/yaxu/32/2_2.png) [@yaxu](https://uzu.lurk.org/u/yaxu)\
**Post date:** [10 August 2020 21:55 UTC](https://uzu.lurk.org/t/using-cp/1319/12 "2020-08-10T21:55:23Z")

</div>

I see, I think this work-in-progress might already do want you want:

> **[GitHub - yaxu/tidal-listener: Experimental tidal OSC listener](https://github.com/yaxu/tidal-listener)**
>
> Experimental tidal OSC listener. Contribute to yaxu/tidal-listener development by creating an account on GitHub.

> <https://github.com/tidalcycles/Tidal/issues/682>
>
> Closely related to #627, but going beyond a ghci-style REPL.. It'd be good to ha…ve an API for interacting with Tidal.
> 
> Motivations would be
> \- Support for feedforward's behaviour (flashing notations, UI control over individual patterns) for editors not written in haskell
> \- Additional support for UI for showing/manipulating cps, current cycle and so on
> \- Interaction with code-generating agents
> \- More?
> 
> Well maybe this is still a REPL, just a featureful one.. This could build on #627 but with an UDP OSC and/or websocket interface.

It's very experimental at this stage, though.

---

<div class="post-metadata">

**Author:** ![John\_Murphy](https://uzu.lurk.org/user_avatar/uzu.lurk.org/john_murphy/32/579_2.png) [@John\_Murphy](https://uzu.lurk.org/u/John_Murphy)\
**Post date:** [10 August 2020 23:06 UTC](https://uzu.lurk.org/t/using-cp/1319/13 "2020-08-10T23:06:29Z")

</div>

I expected that there would be something with the "hint" package, but I didn't want to go too far down that path without knowing that it was the right way to proceed (and I got laughed out of the #haskell channel on irc for asking about this!)

This seems great - it's a small enough set of code that I can wrap my head around it and hopefully put in a PR or two as I work my way through it.

Seems like every time I ask a question, there's already a project started for it! 🙂
