Python MIDI tone generator to generate samples

Share and download User samples and project files (*.nsmp, *.nsmp3, *.nsmp4, *.nsmproj)"
Forum rules
How to get the MP3-Player:
Upload a MP3 file where you play some notes using your sample.
Click the "PLACE INLINE" button after uploading the MP3 sample in order to automatically create a Flash MP3 player in your post!
Also check the Forum Rules, in particular rule #6 about the sharing of patches and samples.
Post Reply
Antilles
Posts: 9
Joined: 17 Feb 2022, 11:56
2
Your Nord Gear #1: Nord Piano 5
Has thanked: 1 time
Been thanked: 4 times

Python MIDI tone generator to generate samples

Post by Antilles »

Hi All,

I needed to grab a few sounds from my aging ESQ-1 as I may retire it soon, and want some of the sounds to survive. I shall post a few as soon as it's done.

I had a challenge to play the tones I needed because several reasons:
- sometimes I need different velocity (not always 127)
- some sounds evolve over several seconds, I think the longest so far is 9 secs for each tone
- For size constraints I needed to cut down on number of sampled keys for each sound and also again the length. Some sounds only needed about 1 sec of sample time
- incorporating all this into a midi files seemed to cumbersome...

I've been messing around with python before, so it made sense to look for a solution. And I manages to make a simple Python program to do this for me. You have to have Python installed as well as the package "mido". YOu change the parameters explained above in the "User settings" section. First you must run the program to ID your MIDI device and enter that into the main program.

I have no Idea if this is useful to anyone or if it makes any sense. I will help if I can.

Martin

ID PROGRAM:

Code: Select all

import mido
import time
import numpy as np

print(mido.get_output_names()) # To list the output ports
print(mido.get_input_names()) # To list the input ports
MAIN PROGRAM:

Code: Select all

#
#
#  Install mido: https://mido.readthedocs.io/en/latest/installing.html
#  Notes and frequencies: https://www.inspiredacoustics.com/en/MIDI_note_numbers_and_center_frequencies
#  Source and contact: https://www.norduserforum.com/nord-user-samples-nsmp-samples-f14/python-midi-tone-generator-to-generate-samples-t22072.html
#


import mido
import time
import numpy as np

###############################################################################################################
###################
## USER SETTINGS ##
###################
current_note_velocity = 127      # Enter value from 0-127. 
step = 1                         # Half noters to step through for each new note 
start_note = 30                  # Start note 0-127 (middle C=60) (low c 61-keys = 36) (low c 88-keys 21)
end_note = 100                   # End note 0-127 (middle C=60) (high c 61-keys = 96) (high c 88-keys 108)
tone_length = 8                  # tone length in secs ex 1.2
silence_length = 2.5             # silence tbehtween tones in secs ex 0.8
###############################################################################################################


midi_device_in = '3- AudioBox USB 96 MIDI In 0'
midi_device_out = '3- AudioBox USB 96 MIDI Out 1'

#print(mido.get_output_names()) # To list the output ports
#print(mido.get_input_names()) # To list the input ports

print('Opening MIDI ports...')
print('In: ' + midi_device_in)
print('Out: ' + midi_device_out)
inport = mido.open_input(midi_device_in)
outport = mido.open_output(midi_device_out)

# Create a list of notes to play
notes_to_play = np.arange(start_note, end_note, step).tolist()

# Print messages

print('Playing ' + str(len(notes_to_play)) + ' notes')
print('With velocity ' + str(current_note_velocity))

note_count = 0

# Play notes
for current_note in notes_to_play:
    msg = mido.Message('note_on', note=current_note, velocity=current_note_velocity)
    note_count = note_count + 1
    print('note ' + str(note_count) + ' of ' + str(len(notes_to_play)) + ' - ' + str(msg))
    outport.send(msg)
    time.sleep(tone_length)
    msg = mido.Message('note_off', note=current_note) 
    outport.send(msg)
    time.sleep(silence_length)
    
print('Done')
Last edited by Antilles on 21 Feb 2022, 14:05, edited 1 time in total.
These users thanked the author Antilles for the post (total 3):
Schorsch, WannitBBBad, Berretje
User avatar
Schorsch
Donator
Posts: 2242
Joined: 15 May 2018, 23:34
5
Your Nord Gear #1: Nord Stage 3
Your Nord Gear #2: Nord Stage 3
Location: Germany - NRW
Has thanked: 1236 times
Been thanked: 803 times

Re: Python MIDI tone generator to generate samples

Post by Schorsch »

Hi Martin,

thanks a lot!

Which tool do you use to actually record the sounds into individual wave files, and do you automate this as well?

Best regards, Schorsch
Regards Schorsch

Want to convert programs between NS2 and NS3?
Check this awesome website to visually view NS2/3 programs and re-create them on the other instrument!


Gear: NS3C, NS3 88, KeyLargo, Vent II ..
Antilles
Posts: 9
Joined: 17 Feb 2022, 11:56
2
Your Nord Gear #1: Nord Piano 5
Has thanked: 1 time
Been thanked: 4 times

Re: Python MIDI tone generator to generate samples

Post by Antilles »

Schorsch wrote:Hi Martin,

thanks a lot!

Which tool do you use to actually record the sounds into individual wave files, and do you automate this as well?

Best regards, Schorsch
I'm new to Nord, so I'm using the Sample editor v4, which can record straight into the program. It automatically detects the keys and start stop of all notes. So basically I press record and then run the python script. I think this is a new feature in version 4 as far as I can read.

Se attached screenshot

Martin
Attachments
Example on how the recording looks inside sample editor after I run the python script
Example on how the recording looks inside sample editor after I run the python script
2022-02-21 13_17_46-ESQ-1 Boomer XL - Nord Sample Editor.png (241.69 KiB) Viewed 2244 times
User avatar
Schorsch
Donator
Posts: 2242
Joined: 15 May 2018, 23:34
5
Your Nord Gear #1: Nord Stage 3
Your Nord Gear #2: Nord Stage 3
Location: Germany - NRW
Has thanked: 1236 times
Been thanked: 803 times

Re: Python MIDI tone generator to generate samples

Post by Schorsch »

Ah I see. I haven't sampled with sample editor by myself so far, I am using SampleRobot which does provide the combination of what your Python script does plus the recording into wav files (well, plus a lot of other features which are nice but not essential), but it's not freeware so your solution is quite interesting :thumbup:
Last edited by Schorsch on 21 Feb 2022, 14:24, edited 2 times in total.
Regards Schorsch

Want to convert programs between NS2 and NS3?
Check this awesome website to visually view NS2/3 programs and re-create them on the other instrument!


Gear: NS3C, NS3 88, KeyLargo, Vent II ..
User avatar
WannitBBBad
Patch Creator
Posts: 1814
Joined: 25 Jul 2011, 03:36
12
Your Nord Gear #1: Nord Stage 3
Has thanked: 1051 times
Been thanked: 1532 times

Re: Python MIDI tone generator to generate samples

Post by WannitBBBad »

Thanks Martin! I often save a "master" WAV file with all notes and long durations saved similar to your screenshot and then make smaller NSMP files from it. Where you might have to compromise today in number of notes used and their duration to save valuable synth sample storage space, a few years from now you can go back to your master WAV file and do more with it as sample memory is expanded. Take care.
Nord Stage 3 | SC Prophet T8 | Korg X50... In the past: Nord Stage EX, 2, 2EX | SC Prophet 5, 10 | MiniMoog | Hammond B3 & 122 Leslie | Yamaha DX7IIFD, EX5, CP60 | Hohner D6 | Fender Rhodes | Roland S-50, D-50, XP-50...
Antilles
Posts: 9
Joined: 17 Feb 2022, 11:56
2
Your Nord Gear #1: Nord Piano 5
Has thanked: 1 time
Been thanked: 4 times

Re: Python MIDI tone generator to generate samples

Post by Antilles »

WannitBBBad wrote:Thanks Martin! I often save a "master" WAV file with all notes and long durations saved similar to your screenshot and then make smaller NSMP files from it. Where you might have to compromise today in number of notes used and their duration to save valuable synth sample storage space, a few years from now you can go back to your master WAV file and do more with it as sample memory is expanded. Take care.
Good point, also I guess storing with different velocity could be good. AFAIK the Sample editor does not support multiple velocities (yet).
User avatar
Eriknie
Patch Creator
Posts: 146
Joined: 14 Jan 2014, 13:01
10
Your Nord Gear #1: Nord Piano 5
Your Nord Gear #2: Nord Stage 3
Location: The Netherlands
Has thanked: 29 times
Been thanked: 108 times
Contact:

Re: Python MIDI tone generator to generate samples

Post by Eriknie »

Nice program. I once made a similar tool in python to do this.
Alternatives are the auto sampler in logic/mainstage and using a simple DAW to generate the midi notes and recored the audio.

For sampling piano's you need automation and auto-sampler is great. For Nord you only have one velocity and need to sample every thirh of fourth note.
This can easily done with any DAW by adding a midi track and piano-roll editing. You can play with the interval, speed and length.

Even quicker is to set the velocity response of the synth where you capture from at a fixed level and just play every thirth (or other interval) while recording.
You van easily hear when the sound is repeating or finished. Works very quick and intuitive.

Once you have the resulting WAV, the sample editor will do al the other work (Like mapping and looping)
NP5-73, NS3C
QSheets: The fastest sheet display tool in the world that plays Audio and send Program Changes: https://QSheets.eriknie.synology.me
FixLoop: Add Loop Points of Wav Files into the Nord Sample Editor: https://github.com/erik-nie/FixLoop-NSE
Antilles
Posts: 9
Joined: 17 Feb 2022, 11:56
2
Your Nord Gear #1: Nord Piano 5
Has thanked: 1 time
Been thanked: 4 times

Re: Python MIDI tone generator to generate samples

Post by Antilles »

Schorsch wrote:Ah I see. I haven't sampled with sample editor by myself so far, I am using SampleRobot which does provide the combination of what your Python script does plus the recording into wav files (well, plus a lot of other features which are nice but not essential), but it's not freeware so your solution is quite interesting :thumbup:
Thanks, it's not really as solution unless you know how to execute a Python script, which is probably not for everyone. I hope someone could use it. The price for Sample Robot does not match my needs at all, since I probably don't need to sample more than a few instruments every year. Let's see so far I'm having fun, so that may change.
User avatar
WannitBBBad
Patch Creator
Posts: 1814
Joined: 25 Jul 2011, 03:36
12
Your Nord Gear #1: Nord Stage 3
Has thanked: 1051 times
Been thanked: 1532 times

Re: Python MIDI tone generator to generate samples

Post by WannitBBBad »

Antilles wrote:
WannitBBBad wrote:Thanks Martin! I often save a "master" WAV file with all notes and long durations saved similar to your screenshot and then make smaller NSMP files from it. Where you might have to compromise today in number of notes used and their duration to save valuable synth sample storage space, a few years from now you can go back to your master WAV file and do more with it as sample memory is expanded. Take care.
Good point, also I guess storing with different velocity could be good. AFAIK the Sample editor does not support multiple velocities (yet).
Yes, storing multiple velocities would be a good idea. You are fortunate to have the only keyboard at this time that supports the latest NSMP4 format, so you might be able to apply multiple samples of different velocity/character to the same note for the Round Robin capability used for "natural sounding repetitions" per the Nord website. To save storage space, I would suggest only adding multiple note samples to those you would like to have Round Robin on. For sharing any of your work on this Forum, it would be very helpful if you could provide your NSMP4 files and also versions in "NSMP" format that would benefit the widest range of current Nord owners. In the Nord Sample Editor 4 you can choose the output format, so you can make your files and save them in the NSMP4 format, and then save any you wish to share in NSMP format as well (the NSMP will only have the first sample used on each note). Thanks again, and welcome to the Forum BTW!
Last edited by WannitBBBad on 21 Feb 2022, 16:49, edited 2 times in total.
Nord Stage 3 | SC Prophet T8 | Korg X50... In the past: Nord Stage EX, 2, 2EX | SC Prophet 5, 10 | MiniMoog | Hammond B3 & 122 Leslie | Yamaha DX7IIFD, EX5, CP60 | Hohner D6 | Fender Rhodes | Roland S-50, D-50, XP-50...
Post Reply