How to xor and xnor clocks?

dibek's icon

Hi,

i have two streams of clocks running and i would like to perform a xor and xnor (both for different outputs) on them.

i have no idea where to start, i searched the forum and there is not much to be found on this topic, so thanks for any help.

cheers!

dibek's icon

{
    "boxes" : [         {
            "box" :             {
                "maxclass" : "button",
                "outlettype" : [ "bang" ],
                "style" : "",
                "numinlets" : 1,
                "patching_rect" : [ 246.0, 226.0, 24.0, 24.0 ],
                "numoutlets" : 1,
                "id" : "obj-82"
            }

        }
,         {
            "box" :             {
                "maxclass" : "live.dial",
                "varname" : "live.dial[1]",
                "parameter_enable" : 1,
                "outlettype" : [ "", "float" ],
                "presentation_rect" : [ 503.0, 70.0, 44.0, 47.0 ],
                "numinlets" : 1,
                "patching_rect" : [ 246.0, 27.0, 44.0, 47.0 ],
                "numoutlets" : 2,
                "presentation" : 1,
                "id" : "obj-5",
                "saved_attribute_attributes" :                 {
                    "valueof" :                     {
                        "parameter_longname" : "live.dial[1]",
                        "parameter_shortname" : "live.dial",
                        "parameter_type" : 0,
                        "parameter_mmax" : 10.0,
                        "parameter_unitstyle" : 0
                    }

                }

            }

        }
,         {
            "box" :             {
                "maxclass" : "newobj",
                "text" : "p detect_edge",
                "fontname" : "Arial",
                "outlettype" : [ "bang" ],
                "style" : "",
                "fontsize" : 13.0,
                "presentation_rect" : [ 507.0, 223.0, 95.0, 23.0 ],
                "numinlets" : 1,
                "patching_rect" : [ 246.0, 159.0, 95.0, 23.0 ],
                "numoutlets" : 1,
                "presentation" : 1,
                "id" : "obj-6",
                "patcher" :                 {
                    "fileversion" : 1,
                    "appversion" :                     {
                        "major" : 7,
                        "minor" : 1,
                        "revision" : 0,
                        "architecture" : "x86",
                        "modernui" : 1
                    }
,
                    "rect" : [ 59.0, 104.0, 640.0, 480.0 ],
                    "bglocked" : 0,
                    "openinpresentation" : 0,
                    "default_fontsize" : 12.0,
                    "default_fontface" : 0,
                    "default_fontname" : "Arial",
                    "gridonopen" : 1,
                    "gridsize" : [ 15.0, 15.0 ],
                    "gridsnaponopen" : 1,
                    "objectsnaponopen" : 1,
                    "statusbarvisible" : 2,
                    "toolbarvisible" : 1,
                    "lefttoolbarpinned" : 0,
                    "toptoolbarpinned" : 0,
                    "righttoolbarpinned" : 0,
                    "bottomtoolbarpinned" : 0,
                    "toolbars_unpinned_last_save" : 0,
                    "tallnewobj" : 0,
                    "boxanimatetime" : 200,
                    "enablehscroll" : 1,
                    "enablevscroll" : 1,
                    "devicewidth" : 0.0,
                    "description" : "",
                    "digest" : "",
                    "tags" : "",
                    "style" : "",
                    "subpatcher_template" : "",
                    "boxes" : [                         {
                            "box" :                             {
                                "maxclass" : "newobj",
                                "text" : "edge~",
                                "fontname" : "Arial",
                                "outlettype" : [ "bang", "bang" ],
                                "style" : "",
                                "fontsize" : 13.0,
                                "numinlets" : 1,
                                "patching_rect" : [ 50.0, 150.0, 48.0, 23.0 ],
                                "numoutlets" : 2,
                                "id" : "obj-19"
                            }

                        }
,                         {
                            "box" :                             {
                                "maxclass" : "newobj",
                                "text" : "
                                "fontname" : "Arial",
                                "outlettype" : [ "signal" ],
                                "style" : "",
                                "fontsize" : 13.0,
                                "numinlets" : 2,
                                "patching_rect" : [ 50.0, 125.0, 53.0, 23.0 ],
                                "numoutlets" : 1,
                                "id" : "obj-18"
                            }

                        }
,                         {
                            "box" :                             {
                                "maxclass" : "newobj",
                                "text" : "delta~",
                                "fontname" : "Arial",
                                "outlettype" : [ "signal" ],
                                "style" : "",
                                "fontsize" : 13.0,
                                "numinlets" : 1,
                                "patching_rect" : [ 50.0, 100.0, 47.0, 23.0 ],
                                "numoutlets" : 1,
                                "id" : "obj-17"
                            }

                        }
,                         {
                            "box" :                             {
                                "maxclass" : "inlet",
                                "outlettype" : [ "signal" ],
                                "style" : "",
                                "numinlets" : 0,
                                "patching_rect" : [ 50.0, 40.0, 25.0, 25.0 ],
                                "numoutlets" : 1,
                                "id" : "obj-27",
                                "comment" : ""
                            }

                        }
,                         {
                            "box" :                             {
                                "maxclass" : "outlet",
                                "style" : "",
                                "numinlets" : 1,
                                "patching_rect" : [ 50.0, 231.0, 25.0, 25.0 ],
                                "numoutlets" : 0,
                                "id" : "obj-28",
                                "comment" : ""
                            }

                        }
],
                    "lines" : [                         {
                            "patchline" :                             {
                                "source" : [ "obj-27", 0 ],
                                "destination" : [ "obj-17", 0 ],
                                "hidden" : 0,
                                "disabled" : 0
                            }

                        }
,                         {
                            "patchline" :                             {
                                "source" : [ "obj-19", 0 ],
                                "destination" : [ "obj-28", 0 ],
                                "hidden" : 0,
                                "disabled" : 0
                            }

                        }
,                         {
                            "patchline" :                             {
                                "source" : [ "obj-18", 0 ],
                                "destination" : [ "obj-19", 0 ],
                                "hidden" : 0,
                                "disabled" : 0
                            }

                        }
,                         {
                            "patchline" :                             {
                                "source" : [ "obj-17", 0 ],
                                "destination" : [ "obj-18", 0 ],
                                "hidden" : 0,
                                "disabled" : 0
                            }

                        }
],
                    "bgfillcolor_type" : "gradient",
                    "bgfillcolor_color1" : [ 0.435294, 0.462745, 0.498039, 1.0 ],
                    "bgfillcolor_color2" : [ 0.290196, 0.309804, 0.301961, 1.0 ],
                    "bgfillcolor_color" : [ 0.290196, 0.309804, 0.301961, 1.0 ],
                    "bgfillcolor_angle" : 270.0,
                    "bgfillcolor_proportion" : 0.39
                }
,
                "saved_object_attributes" :                 {
                    "description" : "",
                    "digest" : "",
                    "globalpatchername" : "",
                    "style" : "",
                    "tags" : ""
                }

            }

        }
,         {
            "box" :             {
                "maxclass" : "newobj",
                "text" : "phasor~ 0.5",
                "fontname" : "Arial",
                "outlettype" : [ "signal" ],
                "style" : "",
                "fontsize" : 13.0,
                "presentation_rect" : [ 389.0, 163.0, 130.0, 23.0 ],
                "numinlets" : 2,
                "patching_rect" : [ 246.0, 99.0, 80.0, 23.0 ],
                "numoutlets" : 1,
                "presentation" : 1,
                "id" : "obj-10"
            }

        }
,         {
            "box" :             {
                "maxclass" : "live.dial",
                "varname" : "live.dial",
                "parameter_enable" : 1,
                "outlettype" : [ "", "float" ],
                "presentation_rect" : [ 319.0, 64.0, 44.0, 47.0 ],
                "numinlets" : 1,
                "patching_rect" : [ 61.0, 27.0, 44.0, 47.0 ],
                "numoutlets" : 2,
                "presentation" : 1,
                "id" : "obj-2",
                "saved_attribute_attributes" :                 {
                    "valueof" :                     {
                        "parameter_longname" : "live.dial",
                        "parameter_shortname" : "live.dial",
                        "parameter_type" : 0,
                        "parameter_mmax" : 10.0,
                        "parameter_unitstyle" : 0
                    }

                }

            }

        }
,         {
            "box" :             {
                "maxclass" : "newobj",
                "text" : "p detect_edge",
                "fontname" : "Arial",
                "outlettype" : [ "bang" ],
                "style" : "",
                "fontsize" : 13.0,
                "presentation_rect" : [ 151.0, 76.0, 95.0, 23.0 ],
                "numinlets" : 1,
                "patching_rect" : [ 61.0, 163.0, 95.0, 23.0 ],
                "numoutlets" : 1,
                "presentation" : 1,
                "id" : "obj-29",
                "patcher" :                 {
                    "fileversion" : 1,
                    "appversion" :                     {
                        "major" : 7,
                        "minor" : 1,
                        "revision" : 0,
                        "architecture" : "x86",
                        "modernui" : 1
                    }
,
                    "rect" : [ 59.0, 104.0, 640.0, 480.0 ],
                    "bglocked" : 0,
                    "openinpresentation" : 0,
                    "default_fontsize" : 12.0,
                    "default_fontface" : 0,
                    "default_fontname" : "Arial",
                    "gridonopen" : 1,
                    "gridsize" : [ 15.0, 15.0 ],
                    "gridsnaponopen" : 1,
                    "objectsnaponopen" : 1,
                    "statusbarvisible" : 2,
                    "toolbarvisible" : 1,
                    "lefttoolbarpinned" : 0,
                    "toptoolbarpinned" : 0,
                    "righttoolbarpinned" : 0,
                    "bottomtoolbarpinned" : 0,
                    "toolbars_unpinned_last_save" : 0,
                    "tallnewobj" : 0,
                    "boxanimatetime" : 200,
                    "enablehscroll" : 1,
                    "enablevscroll" : 1,
                    "devicewidth" : 0.0,
                    "description" : "",
                    "digest" : "",
                    "tags" : "",
                    "style" : "",
                    "subpatcher_template" : "",
                    "boxes" : [                         {
                            "box" :                             {
                                "maxclass" : "newobj",
                                "text" : "edge~",
                                "fontname" : "Arial",
                                "outlettype" : [ "bang", "bang" ],
                                "style" : "",
                                "fontsize" : 13.0,
                                "numinlets" : 1,
                                "patching_rect" : [ 50.0, 150.0, 48.0, 23.0 ],
                                "numoutlets" : 2,
                                "id" : "obj-19"
                            }

                        }
,                         {
                            "box" :                             {
                                "maxclass" : "newobj",
                                "text" : "
                                "fontname" : "Arial",
                                "outlettype" : [ "signal" ],
                                "style" : "",
                                "fontsize" : 13.0,
                                "numinlets" : 2,
                                "patching_rect" : [ 50.0, 125.0, 53.0, 23.0 ],
                                "numoutlets" : 1,
                                "id" : "obj-18"
                            }

                        }
,                         {
                            "box" :                             {
                                "maxclass" : "newobj",
                                "text" : "delta~",
                                "fontname" : "Arial",
                                "outlettype" : [ "signal" ],
                                "style" : "",
                                "fontsize" : 13.0,
                                "numinlets" : 1,
                                "patching_rect" : [ 50.0, 100.0, 47.0, 23.0 ],
                                "numoutlets" : 1,
                                "id" : "obj-17"
                            }

                        }
,                         {
                            "box" :                             {
                                "maxclass" : "inlet",
                                "outlettype" : [ "signal" ],
                                "style" : "",
                                "numinlets" : 0,
                                "patching_rect" : [ 50.0, 40.0, 25.0, 25.0 ],
                                "numoutlets" : 1,
                                "id" : "obj-27",
                                "comment" : ""
                            }

                        }
,                         {
                            "box" :                             {
                                "maxclass" : "outlet",
                                "style" : "",
                                "numinlets" : 1,
                                "patching_rect" : [ 50.0, 231.0, 25.0, 25.0 ],
                                "numoutlets" : 0,
                                "id" : "obj-28",
                                "comment" : ""
                            }

                        }
],
                    "lines" : [                         {
                            "patchline" :                             {
                                "source" : [ "obj-27", 0 ],
                                "destination" : [ "obj-17", 0 ],
                                "hidden" : 0,
                                "disabled" : 0
                            }

                        }
,                         {
                            "patchline" :                             {
                                "source" : [ "obj-19", 0 ],
                                "destination" : [ "obj-28", 0 ],
                                "hidden" : 0,
                                "disabled" : 0
                            }

                        }
,                         {
                            "patchline" :                             {
                                "source" : [ "obj-18", 0 ],
                                "destination" : [ "obj-19", 0 ],
                                "hidden" : 0,
                                "disabled" : 0
                            }

                        }
,                         {
                            "patchline" :                             {
                                "source" : [ "obj-17", 0 ],
                                "destination" : [ "obj-18", 0 ],
                                "hidden" : 0,
                                "disabled" : 0
                            }

                        }
],
                    "bgfillcolor_type" : "gradient",
                    "bgfillcolor_color1" : [ 0.435294, 0.462745, 0.498039, 1.0 ],
                    "bgfillcolor_color2" : [ 0.290196, 0.309804, 0.301961, 1.0 ],
                    "bgfillcolor_color" : [ 0.290196, 0.309804, 0.301961, 1.0 ],
                    "bgfillcolor_angle" : 270.0,
                    "bgfillcolor_proportion" : 0.39
                }
,
                "saved_object_attributes" :                 {
                    "description" : "",
                    "digest" : "",
                    "globalpatchername" : "",
                    "style" : "",
                    "tags" : ""
                }

            }

        }
,         {
            "box" :             {
                "maxclass" : "button",
                "outlettype" : [ "bang" ],
                "style" : "",
                "presentation_rect" : [ 163.0, 123.0, 24.0, 24.0 ],
                "numinlets" : 1,
                "patching_rect" : [ 61.0, 226.0, 24.0, 24.0 ],
                "numoutlets" : 1,
                "presentation" : 1,
                "id" : "obj-22"
            }

        }
,         {
            "box" :             {
                "maxclass" : "newobj",
                "text" : "phasor~ 0.5",
                "fontname" : "Arial",
                "outlettype" : [ "signal" ],
                "style" : "",
                "fontsize" : 13.0,
                "presentation_rect" : [ 100.0, 21.0, 130.0, 23.0 ],
                "numinlets" : 2,
                "patching_rect" : [ 61.0, 99.0, 80.0, 23.0 ],
                "numoutlets" : 1,
                "presentation" : 1,
                "id" : "obj-1"
            }

        }
],
    "lines" : [         {
            "patchline" :             {
                "source" : [ "obj-29", 0 ],
                "destination" : [ "obj-22", 0 ],
                "hidden" : 0,
                "disabled" : 0
            }

        }
,         {
            "patchline" :             {
                "source" : [ "obj-6", 0 ],
                "destination" : [ "obj-82", 0 ],
                "hidden" : 0,
                "disabled" : 0
            }

        }
,         {
            "patchline" :             {
                "source" : [ "obj-5", 0 ],
                "destination" : [ "obj-10", 0 ],
                "hidden" : 0,
                "disabled" : 0
            }

        }
,         {
            "patchline" :             {
                "source" : [ "obj-2", 0 ],
                "destination" : [ "obj-1", 0 ],
                "hidden" : 0,
                "disabled" : 0
            }

        }
,         {
            "patchline" :             {
                "source" : [ "obj-10", 0 ],
                "destination" : [ "obj-6", 0 ],
                "hidden" : 0,
                "disabled" : 0
            }

        }
,         {
            "patchline" :             {
                "source" : [ "obj-1", 0 ],
                "destination" : [ "obj-29", 0 ],
                "hidden" : 0,
                "disabled" : 0
            }

        }
],
    "appversion" :     {
        "major" : 7,
        "minor" : 1,
        "revision" : 0,
        "architecture" : "x86",
        "modernui" : 1
    }

}

dibek's icon

i´m sorry my internetconnection acted funny and i can´t edit my posting anymore :(

i tried to AND the two clocks with this:

if $i1 == $i2 then bang

but for some reason the first bang always gets through

Roman Thilenius's icon

the time limit how long you can edit our own post seems to be very short since a few days.

if $i1 == $i2 then bang is not wrong, but of course you must include an option to initialize - and eventually an option to re-initialize on user request (the latter an get tricky)

when 0 does not work for you, you could initialize stuff to -2147483648. if you are 100% sure you will only work with positive numbers, you could initialize stuff to -1.

dibek's icon

Hi, thanks for the reply, i attached my very simple patch of two independent clockstreams, the idea is to create varying rythms out of xnor-ing and AND-ing them, so this would make four streams in the end.

Max Patch
Copy patch and select New From Clipboard in Max.

the thing is, that i work with bangs and for some reason i thought, that it would be a trivial task, obviously it isn´t.
i tried the codesnippets from the other recent thread on this topic but can´t get them to work, one clock always comes through, where, from my understanding, it should only fire a trigger if both clocks meet at the same time.

ak's icon

It's maybe not a very useful remark, but "bang" isn't a logical value. It's a point in time. And if you want to compare these points in time you have to assume what means they are equal, ie. what makes them happen "at the same time".

Max Patch
Copy patch and select New From Clipboard in Max.

An example solution adapted form another thread:

dibek's icon

AK, thanks a lot, your example seems to work, now i need to figure out what you did there :)
cheers!