2 months ago

# Build a bell ringing simulator

Once, when writing a Raspberry Pi book, your author used a section heading of ‘Ringing the changes’, to signify that the section was going to look at variations on what went before. He was astonished when his American editor had no idea what that term meant.

In fact, the question ‘what is the term for a bell ringer?’, if asked on the popular TV quiz QI, would provoke the klaxon if you gave the answer ‘campanologist’, as that is what the study of bells is called. The correct answer would be ‘bell ringer’.

Bell ringing has a lot more to do with mathematics than you might first think and, despite its ancient origin, it is an ideal topic to computerise.

This feature was written by Mike Cook and first appeared in The MagPi 65. Click here to download a free digital PDF edition of the magazine.

### Ways of bell ringing

While there are many different methods of ringing a set of bells, the two basic ones are change ringing and method ringing. In short, all the bells are rung in turn; this is known as a round. With change ringing, two of the bells in a round swap places for the next round. These bells must be adjacent in the current sequence, because of the very high mass of the bells which results in a limited ability to delay or advance the ringing position in a sequence. Method ringing is similar, but more than one pair of bells can change between any one round. In both systems they start and end with a round going from the highest bell, called the Treble, to the lowest, the Tenor. The bells are numbered, starting with 1 for the Treble. Note that this is the reverse of many systems in music, where the lowest number is reserved for the lowest note.

Normally, there are anything between four and twelve bells, with eight being popular. If tuned, they are usually in the key of C. There are many hundreds of different methods, but the basic rule is that the round starts with the sequence 1 to the highest bell number and ends on that sequence as well, but no other sequence is permitted to repeat. Ideally, all possible sequences must be used; this is called an ‘extent’.

But, for twelve bells there will be 12! (12×11×10×9×8×7×6×5×4×3×2×1) combinations, and that would take over 35 years to ring. The record currently stands at 21 216 changes on the twelve bells of South Petherton Church, near Yeovil, which took 14 hours 26 minutes to complete.

It might come as a surprise, but the dedicated bell ringer is not interested so much in how it sounds, but in learning how to ring a specific pattern. In fact, a lot of the sequences are musically unremarkable and sound a bit like random ringing, even to the trained ear. The real appeal is in the physicality and discipline in getting it right. However, our curiosity got the better of us and we wanted to hear what it sounded like, so we wrote this simulator/player. It simulates change ringing, in that you can direct which bells to swap, but it will also play preprogrammed sequences where ‘one man and his mouse’ would be hard put to keep up any live determination of sequences. These sequences delight in names like Plain Bob Major, Bristol S Maximus, and Grandsire Cinques, to name but three.

### Documenting a ring

These rings are documented by writing each successive sequence of bells, with lines connecting the bell numbers so you can see how they change. However, normally there is only one line for one bell to follow, and not all bells are numbered, as shown in Figure 1.

Figure 1 Normally there is only one line for one bell to follow, and not all bells are numbered

This is understandable, because it is meant for one bell/player, and they just need to know if they have to keep their ringing position the same, or move up or down in the sequence. This shorthand, however, often makes it difficult for a beginner to follow. The full diagrams are normally shown as a vertical list; a full list, resembling braid, is shown in Figure 2.

Figure 2 A full ringing diagram resembles an intricate braid

Alternatively, these lists of sequences can be shown horizontally, known as a roller, Figure 3,

Figure 3 Sequences can be shown horizontally, known as a roller

Or even circularly as a ring, Figure 4.

Figure 4 Sequences can also be shown as a ring

All these pictures were generated by the free-to-use Change Ringing Toolkit and reproduced here by kind permission of the author Steve Scanlon.

### Preparing the resources

The first thing we did was to prepare the graphics. We found a royalty-free image of a bell on the internet and rotated it through 90° in eleven stages. At each stage, we used a photo editing package to move the bell’s clapper; the results are shown in Figure 5.

Figure 5 An array of frames of the bells in motion

The thing to note here is that we want the bell to swing about the pivot point at the top, in order for it to look like a realistic swing. So we have to plot each bell, in the animation, at a different position in the x direction, so that the pivot point ends up in the same spot.

These images were named b0.png to b10.png and put in a folder called swing. The software would then scale this set of images so that each bell had its own sized animation sequence.

Then the sound of eight bells were put in a folder called sounds and named 0.wav to 7.wav. We started with bells recorded from a MIDI sound generator, but eventually replaced these with live recordings, done by a friend, of the bells in St Matthias Church, Leeds.

Finally, we prepared some method files based on classic methods. These are simple text files and consist of the sequence of each round, with a row of ‘-’ signs being used as a comment or blank line to break things up and make it easer to see what is going on. The two methods we have encoded like this are ‘Plain Bob Minor’ and ‘New Year Delight Minor’ and can be found along with the software in the GitHub repository.

### The software

The program, bells_play.py, uses the Pygame framework (you can find the code at the end of this article). Most of the parameters – like colour, speed, and the control variables – are defined at the start of the code, just before the main function. The loadResources function does the scaling of each animation sequence and, as this takes some time, when each bell has been processed it is displayed on the screen, to prevent having a long time where nothing seems to happen. It is important to the visual effect that the bell goes through an animated sequence and doesn’t just flip from a bell on one side to a bell on the other, even though each image spends very little time on the screen. The handleMouse function sees if any of the ‘swap icons’ has been clicked and the checkForEvent function is where most of the other control takes place in response to keyboard presses. The drawSequence function displays the current order of the bells, and the showRing function points to the bell currently being rung.

### Using the software

The software starts up in the stopped mode; pressing the R key will start it ringing, with the S key stopping the ringing at the end of the current round. It can use four to eight bells, selected by simply pressing the number keys on the keyboard. The + and – keys control the speed of the ringing and the F file key brings up a dialogue box to allow you to load in a specific ring. The A key will turn on and off the automatic swap mode; this is where the swap position is generated at random. When the bells are running, clicking on one of the Swap boxes between two bells will swap then at the end of that round. All the time, the map or documentation of the sequence history is displayed scrolling along the bottom of the window. We liked to turn on the automatic swap mode for a time, then turn it off and manually swap bells to get the sequence back to the start.

### Taking it further

For a start, the bell sounds are all mono – it would be interesting to space these out in a stereo field. Also, we have not implemented the ‘calling’ of the bells; that is, calling out the two that need swapping in a round with change ringing. Calling is done in two ways: calling up and calling down. The latter is the simplest, a call of ‘Six to Seven’ will swap bell numbers six and seven; the only complication is that the highest and lowest bells are called ‘Treble’ and ‘Tenor’. Such a list could be taken to any tower and called. Finally, we urge you to have a good look at the toolkit from Steve’s website. If that piques your interest, why not see if there is a bell ringing group in your area and try the real thing?