3

I need to easily select and swap full-width horizontal sections of an image, e.g.

aaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbb
ccccccccccccccccccccccccccccc
ddddddddddddddddddddddddddddd

after swapping sections 'b' and 'c' becomes

aaaaaaaaaaaaaaaaaaaaaaaaaaaaa
ccccccccccccccccccccccccccccc
bbbbbbbbbbbbbbbbbbbbbbbbbbbbb
ddddddddddddddddddddddddddddd

I realize that this can be done by selecting 'b', cutting it, selecting 'c', cutting and moving it up, then pasting 'b' below it, but that's really tedious and error-prone. Is there a better way? FWIW, the images I'm working with are B&W scans of musical scores.

EDIT: (More context and clarification) The scores I'm working with are part extractions created with the online tool at partifi.org. Partifi has a very well-designed interface that

  1. makes intelligent guesses about where to place the separations, and
  2. provides a nice UI for rapidly adjusting/creating/deleting them.

The problem I'm trying to solve arises with choral scores. One of the ways music publishers reduce the page count is by combining parts (e.g. Tenor and Bass) onto a single stave and placing the lyrics above rather than below the stave. Large scores often switch frequently between that representation and the conventional format with one voice per stave with lyrics underneath.

Singers are used to that sort of thing in the context of a complete score but it becomes distracting and hard to follow in the context of single stave extraction.

Partifi doesn't have a way to deal with that. Hence my interest in using Gimp for post-processing.

What I'm looking for:

A fast way to fix the places where the lyrics are above instead of below the staves. Ideally this would consist of

  1. Three mouse clicks to place separator lines to define the regions to be swapped.
  2. The possibility to drag the lines vertically for fine adjustment.
  3. A keyboard shortcut to trigger the swap.

I suspect this may require a custom script. If that's the case, I would accept an answer that points me to a public domain Python script that is close enough to what I want to be easily adapted. I'm trying to avoid having to study Gimp's scripting API in enough depth to do it from scratch.

3 Answers 3

2

See if ofn-swap-strips could help. Basically you indicate a vertical strip using the selection (only the vertical bounds are used):

before

And the script swaps it with the strip of same height immediately below it:

after

Alternate option, use the ofn-guillotine-layer script with guides to quickly slice your score into strips that you can move around. If you have multiple score pages to work with and the lines are at fairly constant places, you can even use the ofn-preset-guides to create a preset for the guides. To abutt the layers quickly see the arrange-layers script.

Edit: seen your edit. Can't tell if ofn-swap-strips does the job, but if it doesn't it would be a good start.

Edit#2: Updated ofn-swap-strips to work with guides:

Using guides

5
  • Looks like ofn-swap-strips is very close to what I need, so I'm accepting this answer. I'll need to modify it so that the swapStrips() function handles the case of different strip heights and figure out how to prompt for selecting the second region, etc, but that seems doable. When I get it working, I'll put it in a Gist and put a link in my question. Thanks!
    – Mike Ellis
    Commented Apr 30, 2017 at 13:48
  • Arrgh. StackExchange seems to confusing my identity and won't let me accept. Will do so when I figure out how to log in as the other 'me'.
    – Mike Ellis
    Commented Apr 30, 2017 at 13:57
  • If you need to specify two different heights then you should use guides like in ofn-guillotine-layers. Not hard to adapt but SO is a poor collaboration medium. Get in touch on gimp-forum.net to pursue the matter.
    – xenoid
    Commented Apr 30, 2017 at 14:37
  • @MikeEllis Edited the answer to show ofn-swap-strips with guides. Enjoy.
    – xenoid
    Commented Apr 30, 2017 at 19:30
  • The adaptation is very elegant -- and understandable even without knowing the Gimp API. Much appreciated.
    – Mike Ellis
    Commented May 2, 2017 at 13:06
2

Cut the score line by line into the clipboard. Paste every clipped line back as new layer.

No need to clip those lines that stay in their original places.

The layers can be shuffled freely back and forth. No need to switch between layers, any loose parts can be moved by the moving tool.

Lock those layers that must not move any more.

From the beginning rename the layers with line or bar numbers. If there are a lot of edits, use texts from your edit plan. Otherwise you can get lost.

A small score:

enter image description here

Line 1 and line 3 swapped, took about 40 seconds:

enter image description here

ADDENDUM: The question has evolved. Other answers cover the new requirements better. The questioner especially wants to avoid placing the snippets manually.

4
  • After pasting the distinct lines as different layers, you can make use of the "align and distribute" tool to actually achieve what the OP wants. That tool´s use is far from being intuitive - so, since you took the effort to compose this answer, you might want to check how it would apply here, and document it in the answer.
    – jsbueno
    Commented Apr 30, 2017 at 2:48
  • @jsbueno That tool does not speed placing a few cutouts onto holes. Very easily the holes have a little different sizes. NOTE: the lines need different amount of space in vertical direction.
    – user82991
    Commented Apr 30, 2017 at 6:38
  • I really appreciate the effort you put into this answer and hope there is a possibility of solution can be done in 4 seconds instead of 40. I'm going to edit my question to provide a little more context and clarify what I'm after.
    – Mike Ellis
    Commented Apr 30, 2017 at 11:53
  • @user287001 : Yeah - i 've done some attempts myself, and found out the distribute tool does not help in this case at all.
    – jsbueno
    Commented Apr 30, 2017 at 17:40
1

(After reading your update) Yeap - you will need a script. Marking the regions to be swapped can be done by using GIMP's built-in image-guides. Unfortunately scriptting API does not allow one to interact with the image itself within the script context - the script has to consume whatever you can build witht he program UI.

Fortunatelly, I think guides are close enough to what you want - check if placing 3 guides for start, end, target position of the regions to be swapped is fast enough for you. If so, we can put together a script that will:

Read the position of all horizontal guides, Make a rectangular selection from the top-most to the second one, with image width edit->cut, paste as new layer (tmplayer) make a rectangular selection, same height, on the third guide edit->cut, past on original layer, position at first guide, anchor position (tmplayer) on third guide, merge down clean up .

SO,it is a non trivial script - I can help you futher, but will have to do so later on.

1
  • Thanks for the offer of help and for outlining the script operations. It makes sense and helped me understand more quickly how Xenoid's script works.
    – Mike Ellis
    Commented May 2, 2017 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.