surge-tuning 0.2.12-alpha.0

surge synthesizer -- handle to the surge tuner, allowing microtunig. contains various tuning configurations
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
# surge-tuning

Surge-Tuning: Advanced Tuning and Mapping for
Surge Synthesizer

Surge-Tuning is a Rust crate designed to provide
advanced tuning and mapping functionality for the
Surge Synthesizer system. It offers a variety of
tuning and keyboard mapping capabilities, allowing
for a wide range of musical scales and
temperaments.

Tokens and Mathematical Ideas

  - Tone: Represents a musical tone with
    a specific frequency. The frequency can be
    calculated using the formula 
    f = 440 * 2^((n - 69)/12), where f is the
    frequency in Hz, and n is the MIDI note
    number.

  - TunerHandle and MaybeOwningTunerHandle:
    Handles for managing access to a SurgeTuner
    instance.

  - KeyboardMapping and Scale: These structures
    define custom keyboard mappings and musical
    scales for the synthesizer, allowing for
    alternative tuning systems and microtonal
    music.

  - n2p and n2pinv: Functions to convert between
    MIDI note numbers and pitch in a custom tuning
    system. The conversion between note numbers
    and pitch can be represented by a mapping
    function M(n), where n is the MIDI note number
    and M(n) is the pitch in a custom tuning
    system.

  - note_to_omega and pitch2omega: Functions for
    converting between pitch and angular frequency
    (omega). The angular frequency can be
    calculated as ω = 2 * π * f, where ω is the
    angular frequency and f is the frequency in
    Hz.

  - retune_to_scale and
    retune_to_standard_tuning: Functions for
    retuning the synthesizer to a custom scale or
    the standard 12-tone equal temperament.

  - remap_to_keyboard and
    remap_to_standard_keyboard: Functions for
    remapping the keyboard layout according to
    a custom keyboard mapping or the standard
    keyboard layout.

  - SurgeTuner: The main struct for managing
    tuning and keyboard mapping within the Surge
    Synthesizer system.

  - TuningTables: A struct that contains
    precomputed tables for tuning conversions.

 - SurgeTuning: A high-level wrapper around the
   SurgeTuner, providing a simplified interface
   for managing tuning within the Surge
   Synthesizer system.

By implementing the Surge-Tuning crate, the Surge
Synthesizer system gains a powerful and flexible
set of tools for working with custom tuning
systems and keyboard mappings, enabling a wide
range of musical possibilities beyond the standard
12-tone equal temperament.

User:

could you teach me more about custom tunings in
the context of electronic music?

Assistant:

Certainly! Custom tunings, also known as
alternative tunings or microtonal tunings, are
tuning systems that differ from the standard
12-tone equal temperament (12-TET) commonly used
in Western music. In electronic music, custom
tunings can be used to explore a variety of
musical expressions, including exotic scales,
unique harmonic relationships, and alternative
musical structures.

Electronic music provides a fertile ground for
experimenting with custom tunings because
synthesizers and digital audio workstations (DAWs)
offer a high degree of control over pitch and
tuning. Here are some key concepts related to
custom tunings in electronic music:

 - Microtonal scales: Microtonal scales are
   scales that use intervals smaller than
   a semitone, which is the smallest interval in
   12-TET. These scales can feature any number of
   notes per octave and can be used to create
   unique harmonic and melodic
   structures. Examples include the 19-tone equal
   temperament, 31-tone equal temperament, and the
   Bohlen-Pierce scale.

 - Just intonation: Just intonation is a tuning
   system based on whole number ratios, which
   creates pure-sounding intervals and
   harmonies. It is often used in electronic music
   to create lush and consonant chords or explore
   alternative harmonic relationships. Just
   intonation can be achieved by tuning the
   intervals between notes using simple frequency
   ratios, such as 3:2 for a perfect fifth or 5:4
   for a major third.

 - Non-octave scales: Most Western music is
   based on the octave, where pitches are repeated
   at double or half the frequency. However,
   custom tunings can also explore non-octave
   scales, where the interval between the lowest
   and highest notes is not an octave. Examples
   include the Bohlen-Pierce scale, which uses
   a 3:1 frequency ratio instead of the 2:1 octave
   ratio.

 - Dynamic tuning: In electronic music, custom
   tunings can be applied dynamically, allowing
   for real-time modulation of the tuning
   system. This can be used for expressive
   effects, such as gliding between different
   tuning systems, or creating evolving harmonic
   landscapes.

To work with custom tunings in electronic music,
you'll need synthesizers or software that support
alternative tuning systems. Some popular
synthesizers and DAWs that support custom tunings
include Surge, Serum, Kontakt, Ableton Live, and
Logic Pro. These tools typically allow you to
import or create custom tuning files, such as
Scala files (.scl), to define your desired tuning
system. You can then assign these tunings to your
instruments and explore the creative possibilities
of alternative tuning systems in your music.

User:

thanks! could you teach me some more about the
various tunings we know about? how many of them
are there? what are their use cases? how are they
structured mathematically?

Assistant:

There are countless tuning systems, as they can be
created and customized according to different
criteria, mathematical relationships, or cultural
contexts. Here, I'll describe some of the more
well-known tunings, their use cases, and their
mathematical structure.

 - 12-tone equal temperament (12-TET): This is
   the most common tuning system in Western
   music. It divides the octave into 12 equal
   parts, with each note's frequency being
   a multiple of the twelfth root of 2 (2^(1/12))
   times the frequency of the previous note. It
   allows for easy transposition and modulation
   between keys, but some intervals are not
   perfectly consonant due to the approximations
   required for equal division.

 - Just intonation: As mentioned earlier, just
   intonation is based on whole number ratios
   between frequencies, such as 3:2 (perfect
   fifth) and 5:4 (major third). The use of simple
   ratios results in pure-sounding intervals and
   harmonies. It is often used in early music,
   Indian classical music, and contemporary
   compositions that explore alternative harmonic
   relationships.

 - Meantone temperament: This tuning system is
   a compromise between just intonation and equal
   temperament. It aims to provide more accurate
   approximations of pure intervals, particularly
   the major third (5:4 ratio). Meantone
   temperament is used in various historical
   keyboard instruments like harpsichords and
   organs, and can be found in music from the
   Renaissance and Baroque periods.

 - Pythagorean tuning: Based on the work of the
   ancient Greek mathematician Pythagoras, this
   tuning system uses the 3:2 ratio (perfect
   fifth) to generate all other pitches. While it
   results in pure-sounding perfect fifths, it
   creates less consonant thirds, making it more
   suitable for certain types of music like
   monophonic chants and modal melodies.

 - 19-tone equal temperament (19-TET): This system
   divides the octave into 19 equal parts,
   resulting in smaller intervals than 12-TET. It
   provides a closer approximation to just
   intonation intervals and allows for more
   complex and exotic scales. The 19-TET has been
   used in some experimental and contemporary
   music compositions.

 - 31-tone equal temperament (31-TET): Similar to
   19-TET, this system divides the octave into 31
   equal parts. It provides even better
   approximations to just intonation intervals and
   allows for a greater variety of microtonal
   scales. Some composers, like Adriaan Fokker,
   have explored the possibilities of 31-TET in
   their work.

 - Bohlen-Pierce scale: As mentioned earlier, this
   is a non-octave scale based on a 3:1 frequency
   ratio instead of the 2:1 octave ratio. It
   divides the "tritave" (3:1 ratio) into 13 equal
   parts and has been used in some experimental
   and electronic music compositions.

These are just a few examples of the numerous
tuning systems that exist. The use cases and
mathematical structures vary, depending on the
goals and aesthetics of the composers or musicians
using them. The exploration of alternative tunings
can open up new sonic possibilities and enrich the
musical experience for both creators and
listeners.

User:

how do these tunings change the possible scales
within each tuning? am i correct that a tuning is
a higher level of abstraction than a scale?

Assistant:

Yes, you are correct that a tuning is a higher
level of abstraction than a scale. A tuning system
defines the relationships between the pitches
within an octave or other interval, while a scale
is a specific selection of pitches from that
tuning system, usually ordered by ascending or
descending pitch.

Different tuning systems can lead to different
possible scales within each tuning. For instance,
in the 12-tone equal temperament (12-TET) system,
there are many different scales, such as the major
scale, natural minor scale, and various modes like
Dorian, Mixolydian, and Phrygian. These scales all
share the same underlying tuning system but have
different patterns of whole and half steps.

When you switch to a different tuning system, like
just intonation, the scales within that tuning
will have different interval structures and
relationships between pitches compared to those in
the 12-TET system. This can lead to new scales
with unique sonic qualities.

For example, in just intonation, you might create
a scale based on the harmonic series, where the
frequencies of the pitches are integer multiples
of a fundamental frequency.

This would result in different interval sizes than
those found in the 12-TET system, leading to
a distinct harmonic and melodic character.

In microtonal tuning systems, such as 19-TET or
31-TET, the scales can be even more diverse, as
the smaller intervals allow for a greater variety
of pitch combinations. This can lead to new and
exotic scales that aren't possible within the
12-TET system.

In summary, the tuning system sets the foundation
for the possible scales within each
tuning. Changing the tuning system will change the
possible scales and their properties, opening up
new musical possibilities and textures.

2> could you describe for me 5 different scales
for each tuning?

Certainly! Here's a brief description of five
different scales for each of the following tuning
systems: 12-TET (12-tone equal temperament), just
intonation, 19-TET, and 31-TET. Please note that
some of these scales might not be as common or
well-known as others, especially in microtonal
tuning systems.

**12-TET:**

1. Major Scale: The most common scale in Western
   music, consisting of whole, whole, half, whole,
   whole, whole, half steps (e.g., C, D, E, F, G,
   A, B, C).

2. Natural Minor Scale: A scale that has a minor
   quality, consisting of whole, half, whole,
   whole, half, whole, whole steps (e.g., A, B, C,
   D, E, F, G, A).

3. Dorian Mode: A minor scale with a raised sixth
   degree, consisting of whole, half, whole,
   whole, whole, half, whole steps (e.g., D, E, F,
   G, A, B, C, D).

4. Mixolydian Mode: A major scale with a lowered
   seventh degree, consisting of whole, whole,
   half, whole, whole, half, whole steps (e.g., G,
   A, B, C, D, E, F, G).

5. Pentatonic Scale: A five-note scale, often used
   in various musical traditions around the world,
   consisting of the major scale without the
   fourth and seventh degrees (e.g., C, D, E, G,
   A, C).

**Just Intonation:**

1. Pythagorean Diatonic Scale: A scale based on
   the Pythagorean tuning system, which uses a 3:2
   perfect fifth as the basis for generating other
   pitches (e.g., C, D, E, F, G, A, B, C).

2. Ptolemy's Intense Diatonic Scale: A just
   intonation scale that uses the 5-limit tuning,
   creating pure major thirds (e.g., C, D, E, F,
   G, A, B, C).

3. Harmonic Series Scale: A scale based on the
   natural harmonic series, with pitches as
   integer multiples of the fundamental frequency.

4. 5-Limit Just Major Pentatonic: A five-note
   scale in just intonation, similar to the 12-TET
   major pentatonic scale, but with pure intervals
   (e.g., C, D, E, G, A, C).

5. Partch's 11-Limit Tonality Diamond: A scale
   based on the tuning system created by Harry
   Partch, which uses 11-limit just intonation to
   generate pitches.

**19-TET:**

1. 19-TET Major Scale: A major scale in 19-TET
   tuning, with slightly different interval sizes
   than the 12-TET major scale (e.g., C, D, E, F,
   G, A, B, C).

2. 19-TET Harmonic Minor Scale: A harmonic minor
   scale in 19-TET tuning, featuring a raised
   seventh degree (e.g., A, B, C, D, E, F, G#, A).

3. 19-TET Double Harmonic Scale: A scale in 19-TET
   tuning that features augmented seconds and
   a raised seventh degree (e.g., C, Db, E, F, G,
   Ab, B, C).

4. 19-TET Diminished Scale: A symmetrical scale in
   19-TET tuning that alternates whole and half
   steps (e.g., C, D, Eb, F, Gb, Ab, A, B, C).

3> thanks! which tunings are considered the most
useful for electronic music?

In electronic music, the most commonly used tuning
is the 12-tone equal temperament (12-TET) system,
as it is the standard tuning system for most
modern synthesizers, MIDI controllers, and digital
audio workstations (DAWs). However, electronic
musicians who want to explore alternative tuning
systems or incorporate microtonality in their work
may find the following tunings particularly
useful:

1. Just Intonation: This tuning system is based on
   simple whole number ratios and provides purer,
   more consonant intervals. It can be used to
   create more harmonically rich electronic music,
   especially when working with drones or ambient
   textures.

2. 19-TET (19-tone equal temperament): This tuning
   system divides the octave into 19 equal steps,
   offering a closer approximation of just
   intonation than 12-TET while still being
   relatively accessible. It can be used to create
   more exotic and unique harmonic progressions
   and melodic lines.

3. 31-TET (31-tone equal temperament): With 31
   equal divisions of the octave, this tuning
   system provides an even better approximation of
   just intonation and offers a wide range of
   microtonal intervals. It can be useful for
   electronic musicians who want to delve deeper
   into microtonal music.

4. 24-TET (quarter-tone system): This tuning
   system divides the octave into 24 equal parts,
   effectively halving the step size of 12-TET. It
   offers a range of quarter-tone intervals, which
   can be used to create unusual and innovative
   harmonies and melodies.

5. Bohlen–Pierce tuning: This tuning system is
   based on a 3:1 frequency ratio instead of the
   traditional 2:1 octave. It can be used to
   create electronic music with a distinct and
   unconventional harmonic structure.

These tuning systems are by no means exhaustive,
and there are many more options to explore. The
choice of tuning system ultimately depends on the
musician's artistic goals and the specific sound
they are trying to achieve.

4> could you show me as many others as you can?

There are numerous tuning systems and scales that
have been developed throughout history and across
cultures. Here are some additional examples:

1. Pythagorean tuning: This ancient Greek tuning
   system is based on the pure 3:2 ratio (perfect
   fifth) and 2:1 ratio (octave). It can create
   interesting harmonies and melodic structures,
   especially for electronic music with a focus on
   drones or modal melodies.

2. Meantone temperament: This historical tuning
   system attempts to achieve pure 5:4 major
   thirds. It was used in Western music from the
   Renaissance to the Baroque period and offers
   a distinctive and expressive harmonic
   character.

3. 22-TET (22-tone equal temperament): This tuning
   system divides the octave into 22 equal steps,
   offering a unique set of intervals and
   harmonies. It is used in some Indian classical
   music traditions and can be employed in
   electronic music to create exotic sounds.

4. 17-TET (17-tone equal temperament): With 17
   equal divisions of the octave, this tuning
   system provides an interesting set of
   microtonal intervals and harmonies. It can be
   used for electronic music that seeks to explore
   unusual melodic and harmonic possibilities.

5. 53-TET (53-tone equal temperament): This highly
   precise tuning system closely approximates just
   intonation and offers a large number of
   microtonal intervals. It can be used in
   electronic music that aims for extreme
   precision and a wide variety of tonal colors.

6. Wendy Carlos' Alpha, Beta, and Gamma scales:
   These scales are based on non-octave-repeating
   scales with unique interval structures. They
   offer unconventional harmonic possibilities and
   can be used for electronic music that seeks to
   break away from traditional tonal systems.

7. Hexany: A six-note scale derived from the
   harmonic series, based on the work of American
   composer and music theorist Harry Partch. It
   can be used for electronic music that
   incorporates just intonation and alternative
   harmonies.

8. Pelog and Slendro: Traditional Indonesian
   gamelan scales that offer unique and
   non-Western interval structures. They can be
   used for electronic music that incorporates
   world music elements and non-Western harmony.

These are just a few examples of the many tuning
systems and scales available to electronic
musicians. The choice of tuning system and scale
ultimately depends on the desired musical effect
and the specific sounds the composer or producer
wishes to explore.

5> thanks! from an engineering perspective, how do
we design a tool which can handle the wide variety
of tunings we have available to us?

To design a tool that can handle a wide variety of
tunings, you'll want to make sure it's flexible,
modular, and user-friendly. Here are some key
considerations for building such a tool:

1. **Flexible data structures**: Use data
   structures that can store and manipulate
   various tunings and scales. For example,
   a tuning could be represented as an array or
   list of frequency ratios or cent values, and
   a scale could be a list of indices or steps
   within a tuning.

2. **Tuning and scale import/export**: Provide
   import and export functionality for common
   tuning and scale file formats like Scala
   (.scl), TUN (.tun), and MIDI Tuning Standard
   (.mts). This will enable users to work with
   a wide variety of pre-existing tunings and
   scales, as well as share their custom tunings
   with others.

3. **User interface**: Create a user interface
   that allows users to easily select, modify, and
   create tunings and scales. This may include
   options for selecting from a list of presets,
   entering frequency ratios or cent values
   manually, or importing and exporting custom
   tunings and scales.

4. **Real-time pitch adjustment**: Implement
   real-time pitch adjustment algorithms that can
   retune the output of your tool according to the
   selected tuning and scale. This can be done
   using various techniques, such as
   pitch-shifting, granular synthesis, or
   wavetable synthesis.

5. **MIDI integration**: Provide MIDI integration
   so that the tool can be used with a wide range
   of hardware and software synthesizers,
   samplers, and sequencers. This may involve
   sending MIDI messages for pitch bend or
   implementing the MIDI Tuning Standard.

6. **Modularity**: Design the tool in a modular
   way, so that it can be easily integrated with
   other audio processing tools, DAWs, or
   synthesizers. This can be achieved by
   developing the tool as a plugin (VST, AU, AAX,
   etc.) or using a modular programming
   environment like Max/MSP, Pure Data, or
   Reaktor.

7. **Documentation and tutorials**: Provide clear
   documentation and tutorials for users to
   understand the capabilities of the tool and how
   to use it effectively. This may include
   information on the available tunings and
   scales, how to create custom tunings, and how
   to integrate the tool with other software and
   hardware.

By following these guidelines, you can develop
a tool that supports a wide variety of tunings and
scales, opening up new possibilities for
electronic musicians and composers to explore
alternative tuning systems and create unique sonic
landscapes.

6> what about for an individual tuning? how do we
design it from a mathematical/programming
perspective?

Designing an individual tuning from a mathematical
and programming perspective involves defining the
frequency ratios or cent values that determine the
relationships between the pitches in the tuning
system. Here are some steps to guide you through
this process:

1. **Choose the number of notes per octave**:
   Decide how many notes you want to have in your
   tuning system within an octave. For example,
   you might choose 12 notes for an equal
   temperament system, or a different number for
   alternative tuning systems like 19-tone equal
   temperament or just intonation-based systems.

2. **Define the frequency ratios or cent values**:
   Determine the frequency ratios or cent values
   that define the relationships between the
   pitches in your tuning system. For equal
   temperament systems, you can calculate the
   frequency ratios using the following formula:

   - Frequency ratio = 2^(n/N), where 'n' is the
     note index (0 to N-1) and 'N' is the number
     of notes per octave.

   Alternatively, you can define the relationships
   in cents, where 1 cent represents 1/1200 of an
   octave. In this case, the cent value for each
   note can be calculated as:

   - Cent value = 1200 * (n/N), where 'n' is the
     note index (0 to N-1) and 'N' is the number
     of notes per octave.

   For just intonation or other non-equal
   temperament systems, you'll need to define the
   frequency ratios or cent values based on the
   specific harmonic relationships you want to
   achieve.

3. **Create a data structure to store the
   tuning**: Store the frequency ratios or cent
   values in a data structure, such as an array or
   list. This will allow you to easily access and
   manipulate the tuning data in your program.

4. **Implement pitch conversion functions**:
   Develop functions that can convert between note
   numbers (e.g., MIDI note numbers) and
   frequencies, based on the tuning system you've
   defined. These functions should take into
   account the reference frequency (e.g., A4 = 440
   Hz) and the frequency ratios or cent values
   you've defined for your tuning system. For
   example:

   - Note number to frequency: Given a note
     number, calculate its frequency using the
     reference frequency and the tuning data
     (frequency ratios or cent values).

   - Frequency to note number: Given a frequency,
     calculate the closest note number using the
     reference frequency and the tuning data.

5. **Handle octave transpositions**: Implement
   functions that can handle octave
   transpositions, making sure to preserve the
   relationships between pitches as defined by
   your tuning system. This can be done by
   multiplying or dividing the frequency ratios by
   2, or adding or subtracting 1200 cents for each
   octave transposed.

By following these steps, you can design and
implement an individual tuning system from
a mathematical and programming perspective,
providing a solid foundation for creating music
that uses alternative tuning systems.

7> how do we make sure our tuning corresponds to
the audio samples we have selected for our song?

To ensure that your tuning corresponds to the
audio samples you've selected for your song,
you'll need to retune the samples according to the
tuning system you've chosen. Here are the steps to
follow:

1. **Determine the original pitch of each
   sample**: Identify the original pitch or note
   of each audio sample. You may find this
   information in the sample's metadata, or you
   might need to analyze the sample using a pitch
   detection algorithm.

2. **Implement pitch-shifting**: Develop or
   integrate a pitch-shifting algorithm into your
   program that allows you to change the pitch of
   the audio samples without affecting their
   duration. There are several pitch-shifting
   techniques available, such as granular
   synthesis, phase vocoder, or the SOLA
   (Synchronous Overlap and Add) method.

3. **Calculate the target pitch**: For each audio
   sample, determine the target pitch based on the
   original pitch and the desired tuning
   system. Use the pitch conversion functions
   you've implemented for the tuning system (e.g.,
   note number to frequency) to calculate the
   target frequency.

4. **Retune the samples**: Apply the
   pitch-shifting algorithm to each audio sample,
   adjusting its pitch to match the target
   frequency determined in the previous step. This
   will ensure that the sample's pitch aligns with
   the tuning system you've chosen for your song.

5. **Verify the tuning**: Check that the retuned
   samples correspond to the desired tuning by
   analyzing their pitches after the
   pitch-shifting process. This can be done using
   a pitch detection algorithm or by comparing the
   retuned samples' frequencies to the target
   frequencies.

6. **Integrate the retuned samples**: Use the
   retuned audio samples in your song or audio
   project, making sure to preserve the
   relationships between pitches as defined by
   your tuning system. When playing back the
   samples, the playback engine should take into
   account the tuning system and any additional
   pitch adjustments (e.g., MIDI note events) to
   ensure the correct pitches are played.

By following these steps, you can make sure your
chosen tuning system corresponds to the audio
samples you've selected for your song, creating
a coherent and harmonically consistent musical
piece.

8> could you show me how to do each of these steps
in detail? is there a way to do the whole process
automatically?