New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Copy-paste patch objects using system clipboard text buffer #2086
base: master
Are you sure you want to change the base?
Changes from 6 commits
de783d1
7df8951
4b7099c
ebc00a1
7b58595
5ba626b
c6ebf7e
d3f3799
bdfaf68
8424fb7
7f9e4e3
f4b6395
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include "m_pd.h" | ||
#include "m_imp.h" | ||
#include "s_stuff.h" | ||
|
@@ -37,6 +38,11 @@ struct _instanceeditor | |
|
||
/* positional offset for duplicated items */ | ||
#define PASTE_OFFSET 10 | ||
#define CLIPBOARD_PATCH_TEXT_START 0 | ||
#define CLIPBOARD_PATCH_TEXT_LINE_END 1 | ||
#define CLIPBOARD_PATCH_TEXT_END 2 | ||
#define CLIPBOARD_PATCH_TEXT_LINE_PARTIAL 3 | ||
#define CLIPBOARD_PATCH_TEXT_LINE_END_APPENDIX 4 | ||
|
||
void glist_readfrombinbuf(t_glist *x, const t_binbuf *b, const char *filename, | ||
int selectem); | ||
|
@@ -3718,6 +3724,17 @@ static void canvas_copy(t_canvas *x) | |
} | ||
} | ||
|
||
static void canvas_copy_to_clipboard_as_text(t_canvas *x) | ||
{ | ||
t_binbuf *bb = canvas_docopy(x); | ||
if (!bb) | ||
return; | ||
t_atom *atoms = binbuf_getvec(bb); | ||
int num_atoms = binbuf_getnatom(bb); | ||
pdgui_vmess("pdtk_copy_to_clipboard_as_text", "ca", x, num_atoms, atoms); | ||
binbuf_free(bb); | ||
} | ||
|
||
static void canvas_clearline(t_canvas *x) | ||
{ | ||
if (x->gl_editor->e_selectedline) | ||
|
@@ -4123,6 +4140,53 @@ static void canvas_paste(t_canvas *x) | |
} | ||
} | ||
|
||
static t_binbuf *clipboard_patch_bb = NULL; | ||
|
||
void canvas_got_clipboard_contents(t_canvas *x, t_floatarg flagf, t_symbol *s) { | ||
int flag = flagf; | ||
switch (flag) { | ||
case CLIPBOARD_PATCH_TEXT_START: | ||
if (clipboard_patch_bb) { | ||
binbuf_free(clipboard_patch_bb); | ||
} | ||
clipboard_patch_bb = binbuf_new(); | ||
break; | ||
case CLIPBOARD_PATCH_TEXT_LINE_PARTIAL: | ||
case CLIPBOARD_PATCH_TEXT_LINE_END: | ||
case CLIPBOARD_PATCH_TEXT_LINE_END_APPENDIX: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm not exactly sure about this.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (and sorry for not saying that before you started to implement it) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heh no worries. I'm just having trouble transmitting the comma with pdsend, i.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Works just fine, but I can't get it transmitted via pdsend properly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's because a plain comma in a message is a message separator in Pd lingo.
is really equivalent to
this is currently not handled correctly, and i get:
iirc, miller's suggestion was:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here's a super stupid (and simple idea): There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's stupid :-) it's like, stream of pure data... (eh) will try. Would love this to take as few lines as possible and maximize utilizing existing functionality. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see eeropic-forks#1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great stuff!! Just need to implement the chunking, so it doesn't cut off the data in pdsend There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. It's just a poc. I'm pretty sure there is some memory overallocation and what not. |
||
if (clipboard_patch_bb) { | ||
t_binbuf *line_bb = binbuf_new(); | ||
t_binbuf *temp_bb = binbuf_new(); | ||
if (flag == CLIPBOARD_PATCH_TEXT_LINE_END_APPENDIX) { | ||
t_atom a; | ||
SETCOMMA(&a); | ||
binbuf_add(line_bb, 1, &a); | ||
} | ||
binbuf_text(temp_bb, s->s_name, strlen(s->s_name)); | ||
if (flag == CLIPBOARD_PATCH_TEXT_LINE_END || flag == CLIPBOARD_PATCH_TEXT_LINE_END_APPENDIX) { | ||
binbuf_addsemi(temp_bb); | ||
} | ||
binbuf_add(line_bb, binbuf_getnatom(temp_bb), binbuf_getvec(temp_bb)); | ||
binbuf_add(clipboard_patch_bb, binbuf_getnatom(line_bb), binbuf_getvec(line_bb)); | ||
binbuf_clear(line_bb); | ||
binbuf_clear(temp_bb); | ||
binbuf_free(line_bb); | ||
binbuf_free(temp_bb); | ||
} | ||
break; | ||
case CLIPBOARD_PATCH_TEXT_END: | ||
if (clipboard_patch_bb) { | ||
canvas_dopaste(x, clipboard_patch_bb); | ||
binbuf_free(clipboard_patch_bb); | ||
clipboard_patch_bb = NULL; | ||
} | ||
break; | ||
default: | ||
post("Invalid flag received in canvas_got_clipboard_contents."); | ||
break; | ||
} | ||
} | ||
|
||
static void canvas_duplicate(t_canvas *x) | ||
{ | ||
if (!x->gl_editor) | ||
|
@@ -4924,6 +4988,10 @@ void g_editor_setup(void) | |
gensym("cut"), A_NULL); | ||
class_addmethod(canvas_class, (t_method)canvas_copy, | ||
gensym("copy"), A_NULL); | ||
class_addmethod(canvas_class, (t_method)canvas_copy_to_clipboard_as_text, | ||
gensym("copy-to-clipboard-as-text"), A_NULL); | ||
class_addmethod(canvas_class, (t_method)canvas_got_clipboard_contents, | ||
gensym("got-clipboard-contents"), A_FLOAT, A_DEFSYMBOL, A_NULL); | ||
class_addmethod(canvas_class, (t_method)canvas_paste, | ||
gensym("paste"), A_NULL); | ||
class_addmethod(canvas_class, (t_method)canvas_paste_replace, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should go into
(t_glist*)->gl_privatedata