Ramugen Components
The components can be downloaded here (129KB) and are also available via Torry's Delphi Pages
This is a brief tour of the main properties and methods for the components.
Demos for the TMidiArray component are available here(856KB)
The best demo for the TRamugen component is the source-code to the standard Ramugen Application here(352KB)
You can also see the source for the main preset editor form of the standard application online here and the interface form here
TRamugen
Quick example code to give you the flavour:
With Ramugen1 do
begin
Pitch.Min := 40;
Pitch.Max := 80;
Duration.Min := 800;
Duration.Max := 1200;
Amplitude.Min := 127;
Amplitude.Max := 127;
PlayNote(Pitch.Choose, Duration.Choose, Amplitude.Choose);
end;
Methods
Start / Stop - starts/stops the main engine. By default the settings are random within aesthetically neutral bounds (pitch 40 to 80, etc.)
PlayPhrase / Halt - starts/stops the Midi-Array built in to Ramugen
StartNote / StopNote - low-level Midi control of notes
PlayNote - as above but with duration, ie. the note gets turned off again by Ramugen
Assign/AssignTo/Create/Destroy - fully implemented in the usual way
Mu - randomises settings for all moods, presets, etc.
SaveToFile(FileName : string) - if blank, Ramugen handles it with a standard dialog box
SaveToStream(TargetStream : TStream) - memory or file stream.
LoadFromFile/LoadFromStream as above
Properties
Playing : Boolean runtime property - tells you whether the engine is engaged.
StorePlayBack : Boolean - tells Ramugen whether to keep any notes played in its internal memory array for replaying/processing.
ActivePresetFilled/ActiveMoodFilled/ActiveMindsetFilled : boolean - tells you whether the active preset/etc. has already been filled by the end-user.
ActivePreset/ActiveMindset/ActiveMood : Integer run-time - sets Ramugen to refer to the specified settings, ie. "ActivePreset := 3" means that preset #3 becomes active and can be referred to directly by Ramugen (including the Ramugen engine).
MidiChannel/MidiDevice/MidiVoice - for determining what sounds come out of the speakers.
Name/Tag - as normal for all components
Preset-access Properties
The following contain the parameters for the Ramugen engine.
Pitch.Choose - returns a pitch chosen within the hard limits specified with Min and Max.
Pitch.Weighted : boolean design-time - if set to false, pitch.choose just returns a value totally at random between Min and Max; if set to true, pitch.choose returns a value based on more subtle selection criteria. See Pitch.InputWeightings.
Pitch.Change.Probability - set how likely it is that on any particular note-selection, the pitch will be totally randomised (as opposed to meandering, etc.).
Pitch.Change.IsRequired : boolean run-time - tells you whether the pitch needs to be totally randomised, based on the above probability setting.
Pitch.Min/Max - hard limits to pitch selection - if Max is 30 and you assign 32 to it, it'll correct it down to 30. Setting Min to a higher value than Max results in Max being adjusted accordingly.
Pitch.SetRange(Min,Max) - as above but accepting much more flexible input (strings, edits, etc.), and where the range is invalid (min>max) it just swaps the two values round.
Pitch.MoveDown/MoveUp - when the pitch isn't totally randomised, it'll move from where it is. These two properties are weightings. The calculation of which direction the pitch will move is done by the engine. You can provide any two arbitrary integer values.
Pitch.Description/Title - customisation of the following dialog box:
Pitch.InputWeightings - opens a standard dialog box so that you can enter arbitrary integer values corresponding to a weighted selection system. It works like this:
Let's say you enter C : 5, C# : 0, D : 1, D# : 1, E : 5 - C# definitely won't be picked next time you call Pitch.Choose, but D or D# might be, though it's five times more likely than that to be a C or an E.
Pitch.HardMax/HardMin - a further safeguard protecting the hard limits from change by the end-user of your application. You might provide EditBoxes for the user to specify their hard limits (Min and Max), but clearly you don't want them to set pitch.max to 387.
ChordIntervals.* as with Pitch.* above; used to generate chords based around specific intervals rather than notes, eg. Major and Minor thirds only, with a 5:3 ratio of probability.
MoveInterval.* as above; used to determine the melodic shape of movements where pitch isn't randomised, eg. no wider than a fifth and no tritones.
TransposeFactor.* as above; used to adjust pitch output by raw transposition. Useful if you've got pitch set to only select Cs, Es and Gs, since by setting TransposeFactor to 4th or 5th with 2:1 ratio of probability, you enable emulation of "tonal" three-chord harmony. (ie. Ramugen picks pitches C, E or G, but may also transpose them to F A or C, or G B or D, depending on TransposeFactor.Weightings and TransposeFactor.Change.Probability
Duration.* as above but no weighting system. Also includes Duration.Unitsize, which forces Ramugen to pick values conforming to a particular 'resolution', eg. Unitsize 100, Min 100, Max 1000 only yields values 100,200,300,400,etc. not 137,159,191,etc.
Amplitude.* as Duration above.
NumNotes.* as above; used to determine how many notes will constitute the next event. If it's set to just 1 then it won't be a chord; if it's 2 then it'll be an interval and if more than that, a traditional 'chord' (maximum 6 notes). If you want to implement a greater degree of complexity, you can override the Pitch engine (and set NumNotes.HardMax to allow the values). It's also possible to associate a TMidiArray or TRamugen/RamugenPreset with the main Ramugen component using their OnNoteStart(etc) events.
BackTrack.Probability / BackTrack.IsRequired works like Pitch.Change.Probability/IsRequired; used by the engine to decide whether the current pitch needs to revert to its previous value instead of moving somewhere else.
ChordLocal.* as above; if ChordLocal.IsRequired, the Ramugen engine uses intervals instead of random pitches to provide notes for chords.
MindsetChange/Moodchange/PresetChange.* as above - used to determine how likely it is that these things will be changed by the engine once engaged using Start.
Rest/ChangeLandmark/ActivateLandmark/MoveHand.* as above; Rest is a silent note; ChangeLandmark means that Ramugen takes the current pitch and remembers it, then if ActivateLandmark.IsRequired in the future, that pitch becomes the new pitch; MoveHand makes the centre of Ramugen's focus the current note. It's used for melodic meandering. eg. If Ramugen moves from a C to an E, it could be that the 'hand' remains at C so that the next note is picked from the vicinity of C; on the other hand the 'hand' could move to E so that the next note is picked from that vicinity instead.
BrainInterval : the time between decision-points for changing preset/mood/mindset. Default is once per second (1000ms). Obviously slowing it down is equivalent to lowering the probabilities for change of all three settings.
Devolvees : dvPresets/dvMoods/dvMindsets(Boolean) - if set to true, these are controlled by Ramugen once the engine's engaged. If set to false, they remain static.
Memory : TMidiArray - see separate object guide lower down page.
Events
OnEngineStart - when you tell it to Start
OnEngineStop - when you tell it to Stop
OnMemoryPhraseStart - when you tell it PlayPhrase
OnMemoryPhraseStop - when the phrase ends or you tell it Halt
OnNoteStart - when an individual note starts
OnNoteStop - when it ends
PEO_01-11 : partial engine override - change part (or all) of the way Ramugen picks notes...
To use the PEO events, remember that the desired outcome is to set CurrentPitch, CurrentDuration, CurrentAmplitude. The source code to the default engine is here. For indeterminate style composition, the default engine handles the common scenarios.
TEO-01/02 : total engine override - TEO_01_PlayNote represents the Ramugen engine as a whole; TEO_02_Moods handles the changing of presets/moods/mindsets by Ramugen, and is on a separate timer.
TRamugenPreset
As above, but IsFilled property is the equivalent of Ramugen.PresetFilled.
This component is used when you're not wanting a full ramugen engine with multiple presets/moods/mindsets, just control over the parameters (pitch,etc.).
Has its own Mu method.
TMidiArray
Quick example code to give you the flavour:
With MidiArray1 do
begin
AddNote(80, 1000, 127); //pitch,duration,amplitude
AddNote(82, 1000, 107);
PlayPhrase;
Reverse;
PlayPhrase; //won't wait for the other phrase to finish : see demos
end;
Methods
PlayPhrase - play the current midi array's midi-phrase; all timer handling done by the component. Can be used polyphonically but if you want more than one voice/channel, use more than one array.
Halt - stops all playing for this array, ie. any phrase(s) being played currently.
AddNote - add a note to the array; accepts just pitch, pitch&duration or pitch/duration/amplitude. Also accepts descriptive terms for pitch such as 'F#',6 meaning F#6.
Clear - as expected.
Assign/AssignTo/Create/Destroy - as standard. Assign can be from an array or a compatible object (TRamugen or TMidiArray or descendants)
SaveToFile/LoadFromFile - saves the array to a file. Please note that this does NOT format the array into the standard MIDI file format; it simply saves the array's contents for future use by TMidiArray/TRamugen components. (Note that all properties/methods/events of TMidiArray are available to TRamugen.Memory property)
OpenMidiDevice : opens a MIDI device for use by the array.
ShareMidiDeviceOf(handler : TObject) - use the MIDI device already opened by another compatible object (TMidiArray/TRamugen) : see demo
Append - load another array/MidiArray/Ramugen and add it to the end of the current array's contents.
PlayNote/StartNote/StopNote - as for TRamugen
Reverse - reverses the order of the notes in the array
Invert - performs a tonal inversion : C G A (rising) becomes C F Eb (falling)
MutatePitch/Duration/Amplitude(Probability : single; RangeUp,RangeDown : integer = 1) - makes small changes to the values of the array based on a probability setting (ie. between 0 and 1) and a specified range of maximum change. The default is 1 up, 1 down.
MakeRandomToneRow - fills the array with a 12-note row. Useful for serial composition. It's the equivalent of the following code:
for t := 1 to 12 do addnote(t);
shuffle(1);
Shuffle(probability : single, pitch,duration,amplitude,independent : boolean) - shuffles the members of the array according to the probability value (1 = shuffle every element; 0 = shuffle none). The boolean flags determine which attributes are shuffled, and the last flag determines whether members are regarded as single items or whether pitch,duration and amplitude exist independently of each other.
Stretch : scale the durations of the array
Transpose : transpose up/down
RotateLeft/Right : performs a circular rotation on the array such that the first member becomes the last or vice versa.
RandomisePitch/duration/amplitude : fills the array with random values within set limits. This is equivalent to an unweighted Pitch.Choose in TRamugen.
Properties
Channel/Voice : as expected, these change the sounds coming out of the speaker.
Name/Tag : as standard.
Repeating : boolean - if true, when a phrase ends, it loops back again.
RepeatCount : integer - used by the repeat controller above.
Pitch/Duration/Amplitude : array properties - direct access to the elements of the array.
PhraseLength : truncates or expands the array if set; if read, returns the length of the array's midi-phrase.
Octave : returns the octave-part of a pitch value, ie. Octave(60) = 5
Pitch-class : returns the pitch-class of a pitch value, ie. PitchClass(60) = 'C'; useful for linking two or more midiarrays together (see demo)
Events
OnStartNote/OnStartPhrase/etc. as for TRamugen
Online source code :
Main Ramugen class definitions and implementation
Worker Classes including TMidiArray
MinMax Class - handles chance operations for musical attributes such as pitch or duration
The components can be downloaded here (129KB) and are also available via Torry's Delphi Pages
The readme file is here